propertyManager
Class EditableComboProperty
java.lang.Object
propertyManager.ReadableProperty
propertyManager.EditableProperty
propertyManager.EditableComboProperty
- All Implemented Interfaces:
- java.io.Serializable
- Direct Known Subclasses:
- EditableBooleanProperty
public class EditableComboProperty
- extends EditableProperty
- Version:
- 1.0
The EditableComboProperty works with the PropertyManager and the
Properties View to present a drop down box to the user in the
properties view.
Example:
// create a new property
EditableComboProperty myColors = new EditableComboProperty("ColorID", "Select a Color");
// add name/value pairs to the combo property
myColors.addComboItem("Red", Color.RED);
myColors.addComboItem("Blue", Color.BLUE);
myColors.addComboItem("Green", Color.GREEN);
myColors.setDefaultValue(Color.BLUE);
// add it to your property manager object
propertyManager.addProperty(myColors);
...
// when you want to know what the currently selected color is
// retrieve it with the following code
Color selected = (Color) myColors.getValue();
// Or, if you do not have a reference to the myColors property, but
// you have a reference to the propertyManager, use the ID
EditableProperty myColors = propertyManager.getEditableProperty("ColorID");
Color selected = myColors.getValue();
- Author:
- Dan Phifer
- See Also:
- Serialized Form
|
Method Summary |
void |
addComboItem(java.lang.String text,
java.lang.Object value)
|
java.lang.String[] |
getComboItemNames()
|
org.eclipse.ui.views.properties.PropertyDescriptor |
getCustomPropertyDescriptor()
This method can be overridden by suclasses. |
java.lang.Object |
getDefaultValue()
|
private int |
getIndexOf(java.lang.Object v)
|
java.lang.String |
getText()
|
java.lang.Object |
getValue()
|
boolean |
hasDynamicPropertyDescriptor()
|
boolean |
hasText(java.lang.String text)
|
boolean |
hasValue(java.lang.Object value)
|
void |
removeAllComboItems()
Removes all items from the combo list and sets the value and defaultValue
to null |
void |
removeComboItem(java.lang.Object text,
java.lang.Object value)
Removes the specified item from the combo list |
void |
setDefaultValue(java.lang.Object value)
Sets the default value of the combo box. |
void |
setIndex(int i)
Sets the value of the property to the value corresponding to the ith
comboItem added |
void |
setValue(java.lang.Object value)
Sets the value of the drop down to the given value by changing the index
of the drop down |
void |
setValueByName(java.lang.String name)
Sets the value of the drop down box to the value associated with the
given name |
private java.lang.String |
translateToName(java.lang.Object value)
|
private java.lang.Object |
translateToValue(java.lang.Object value)
|
| Methods inherited from class propertyManager.ReadableProperty |
addPropertyChangeListener, getID, getName, getPropertyDescriptor, getSubPropertyManager, getUnderlyingDefaultValue, getUnderlyingValue, hasDefaultValue, hasSubProperties, hasValue, notifyPropertyChangeListeners, removePropertyChangeListener, setCategory, setLabelProvider, setSubPropertyManager, setUnderlyingDefaultValue |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
itemTexts
private java.util.ArrayList itemTexts
itemValues
private java.util.ArrayList itemValues
EditableComboProperty
public EditableComboProperty(java.lang.String id,
java.lang.String name)
addComboItem
public void addComboItem(java.lang.String text,
java.lang.Object value)
- Parameters:
name - The name to be shown in the drop down listvalue - The value to be returned when the user selects the given name
Note: avoids duplicates
removeAllComboItems
public void removeAllComboItems()
- Removes all items from the combo list and sets the value and defaultValue
to null
removeComboItem
public void removeComboItem(java.lang.Object text,
java.lang.Object value)
- Removes the specified item from the combo list
- Parameters:
text - the text of the combo item to be removedvalue - the value of the combo item to be removed
setDefaultValue
public void setDefaultValue(java.lang.Object value)
- Sets the default value of the combo box. addComboItem must be called
before setting the default value, sine the list of possible values for
the value parameter is constructed through calls to addComboItem
- Overrides:
setDefaultValue in class ReadableProperty
- Parameters:
value - a value supplied to the addComboItem function
getDefaultValue
public java.lang.Object getDefaultValue()
- Overrides:
getDefaultValue in class ReadableProperty
- Returns:
- By default, the default underlying value is returned.
getCustomPropertyDescriptor
public org.eclipse.ui.views.properties.PropertyDescriptor getCustomPropertyDescriptor()
- Description copied from class:
ReadableProperty
- This method can be overridden by suclasses. The default implementation
returns a read-only PropertyDescriptor.
- Overrides:
getCustomPropertyDescriptor in class EditableProperty
- Returns:
- the property descriptor to be used for this property
hasDynamicPropertyDescriptor
public boolean hasDynamicPropertyDescriptor()
- Overrides:
hasDynamicPropertyDescriptor in class ReadableProperty
- Returns:
- true if the property descriptor can change. Mainly, this is for
combo property object, so that the items in the list can be
dynamic. Other types of descriptors do not contain information
that is data dependent
hasText
public boolean hasText(java.lang.String text)
- Parameters:
text - the String whose existence needs to be checked among the text
items
- Returns:
- true if the given text is contained in the combo items list
hasValue
public boolean hasValue(java.lang.Object value)
- Parameters:
value - the Object whose existence needs to be checked among the value
items
- Returns:
- true if the given value is contained in the combo items list
getComboItemNames
public java.lang.String[] getComboItemNames()
- Returns:
- The list of names to be disaplyed in the combo box
setValue
public void setValue(java.lang.Object value)
- Sets the value of the drop down to the given value by changing the index
of the drop down
- Overrides:
setValue in class EditableProperty
- Parameters:
value -
setValueByName
public void setValueByName(java.lang.String name)
- Sets the value of the drop down box to the value associated with the
given name
comboProperty.addComboItem("myName", myValue);
...
comboProperty.setValueByName("myName");
comboProperty.getValue() will yield myValue
- Parameters:
name - The name of the combo item to be selected
setIndex
public void setIndex(int i)
- Sets the value of the property to the value corresponding to the ith
comboItem added
comboProperty.addComboItem("Item 1", object1);
comboProperty.addComboItem("Item 2", object2);
...
comboProperty.setIndex(1);
comboProperty.getValue() will yield object2
- Parameters:
i - The position (0-based) of the combo item to be selected.
getValue
public java.lang.Object getValue()
- Overrides:
getValue in class ReadableProperty
- Returns:
- the value of the selected option
getText
public java.lang.String getText()
- Returns:
- The name of the selected option
translateToValue
private java.lang.Object translateToValue(java.lang.Object value)
- Parameters:
value - The value used by the properties view (Integer index)
- Returns:
- the comboValue represented by the value
translateToName
private java.lang.String translateToName(java.lang.Object value)
- Parameters:
value - The value used by the properties view (Integer index)
- Returns:
- the comboName represented by the value
getIndexOf
private int getIndexOf(java.lang.Object v)
- Returns:
- the index of the selected value