Class KeyedComboBoxModel<K,V>
java.lang.Object
org.pentaho.reporting.libraries.designtime.swing.KeyedComboBoxModel<K,V>
- All Implemented Interfaces:
ComboBoxModel,ListModel
The KeyedComboBox model allows to define an internal key (the data element) for every entry in the model.
This class is usefull in all cases, where the public text differs from the internal view on the data. A separation
between presentation data and processing data is a prequesite for localizing combobox entries. This model does not
allow selected elements, which are not in the list of valid elements.
- Author:
- Thomas Morgner
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new keyed combobox model.KeyedComboBoxModel(K[] keys, V[] values) Creates a new keyed combobox model for the given keys and values. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a new entry to the model.voidAdds a listener to the list that's notified each time a change to the data model occurs.voidclear()Removes all entries from the model.intfindElementIndex(V anItem) Tries to find the index of element with the given value.protected voidNotifies all registered list data listener of the given event.getElementAt(int index) Returns the value at the specified index.getKeyAt(int index) Returns the key from the given index.Returns the selected item.intReturns the selected data element or null if none is set.intgetSize()Returns the length of the list.voidremove(int index) voidremoveDataElement(K key) Removes an entry from the model.voidRemoves a listener from the list that's notified each time a change to the data model occurs.voidsetAllowOtherValue(boolean allowOtherValue) voidReplaces the data in this combobox model.final voidsetSelectedItem(Object anItem) Set the selected item.voidsetSelectedKey(K anItem) Defines the selected key.voidsetSelectedValue(V anItem) void
-
Constructor Details
-
KeyedComboBoxModel
public KeyedComboBoxModel()Creates a new keyed combobox model. -
KeyedComboBoxModel
Creates a new keyed combobox model for the given keys and values. Keys and values must have the same number of items.- Parameters:
keys- the keysvalues- the values
-
-
Method Details
-
setData
Replaces the data in this combobox model. The number of keys must be equals to the number of values.- Parameters:
keys- the keysvalues- the values
-
fireListDataEvent
Notifies all registered list data listener of the given event.- Parameters:
evt- the event.
-
getSelectedItem
Returns the selected item.- Specified by:
getSelectedItemin interfaceComboBoxModel<K>- Returns:
- The selected item or
nullif there is no selection
-
setSelectedKey
Defines the selected key. If the object is not in the list of values, no item gets selected.- Parameters:
anItem- the new selected item.
-
setSelectedItem
Set the selected item. The implementation of this method should notify all registeredListDataListeners that the contents have changed.- Specified by:
setSelectedItemin interfaceComboBoxModel<K>- Parameters:
anItem- the list object to select ornullto clear the selection
-
setSelectedValue
-
setAllowOtherValue
public void setAllowOtherValue(boolean allowOtherValue) -
addListDataListener
Adds a listener to the list that's notified each time a change to the data model occurs.- Specified by:
addListDataListenerin interfaceListModel<K>- Parameters:
l- theListDataListenerto be added
-
getElementAt
Returns the value at the specified index.- Specified by:
getElementAtin interfaceListModel<K>- Parameters:
index- the requested index- Returns:
- the value at
index
-
getKeyAt
Returns the key from the given index.- Parameters:
index- the index of the key.- Returns:
- the the key at the specified index.
-
getSelectedKey
Returns the selected data element or null if none is set.- Returns:
- the selected data element.
-
getSize
public int getSize()Returns the length of the list. -
removeListDataListener
Removes a listener from the list that's notified each time a change to the data model occurs.- Specified by:
removeListDataListenerin interfaceListModel<K>- Parameters:
l- theListDataListenerto be removed
-
findElementIndex
Tries to find the index of element with the given value. This method is called by the setSelectedItem method and returns the first occurence of the element.- Parameters:
anItem- the key for the element to be searched.- Returns:
- the index of the key, or -1 if not found.
-
removeDataElement
Removes an entry from the model.- Parameters:
key- the key
-
add
Adds a new entry to the model.- Parameters:
key- the keycbitem- the display value.
-
update
-
clear
public void clear()Removes all entries from the model. -
getSelectedItemIndex
public int getSelectedItemIndex() -
remove
public void remove(int index)
-