Package ca.corbett.extras.properties
Class EnumProperty<T extends Enum<?>>
java.lang.Object
ca.corbett.extras.properties.AbstractProperty
ca.corbett.extras.properties.EnumProperty<T>
- Type Parameters:
T- Supply your custom enum type.
Represents a multi-choice property, very similar to a ComboProperty, except that the
options come from a supplied enum instead of a List of String values.
You must supply a default value for the field, and you can choose whether the
form field generated from this property uses the enum name() or the enum toString()
for the combo box values. It's important to note that even if you use the toString()
for the combo box values, when the property saves itself to a Properties object,
it will use the enum name() to identify the field value. This is handy in case
the toString() value changes over time or is localized to another language.
- Since:
- 2025-03-26
- Author:
- scorbo2
-
Field Summary
Fields inherited from class ca.corbett.extras.properties.AbstractProperty
categoryName, DEFAULT_CATEGORY, DEFAULT_PROPERTY_NAME, extraAttributes, fullyQualifiedName, helpText, isEnabled, isExposed, isInitiallyEditable, isInitiallyVisible, propertyLabel, propertyName, subCategoryName -
Constructor Summary
ConstructorsConstructorDescriptionEnumProperty(String name, String label, T defaultValue) Creates a new EnumProperty whose choices will be taken from the values of the supplied enum.EnumProperty(String name, String label, T defaultValue, boolean useNamesInsteadOfLabels) Creates a new EnumProperty whose choices will be taken from the values of the supplied enum, and lets you choose whether you want to use name() or toString() for the possible combo box values. -
Method Summary
Modifier and TypeMethodDescriptionprotected FormFieldDescendant classes must implement this method to generate a FormField associated with this property.intintintvoidloadFromFormField(FormField field) Populates this Property's value(s) from the given form field, assuming the field is of the correct type.voidloadFromProps(Properties props) Loads the value(s) for this property from the given Properties instance, overwriting any current value.voidsaveToProps(Properties props) Saves the current value(s) of this property to the given Properties instance.setSelectedIndex(int index) setSelectedItem(T item) Methods inherited from class ca.corbett.extras.properties.AbstractProperty
addAllExtraAttributes, addFormFieldChangeListener, clearExtraAttribute, clearExtraAttributes, equals, fireFormFieldChangedEvent, generateFormField, generateFormField, getCategoryName, getExtraAttribute, getFullyQualifiedName, getHelpText, getPropertyLabel, getPropertyName, getSubCategoryName, hashCode, isEnabled, isExposed, isInitiallyEditable, isInitiallyVisible, removeAllListeners, removeFormFieldChangeListener, setAllExtraAttributes, setEnabled, setExposed, setExtraAttribute, setHelpText, setInitiallyEditable, setInitiallyVisible, setPropertyLabel
-
Constructor Details
-
EnumProperty
Creates a new EnumProperty whose choices will be taken from the values of the supplied enum. Any combo box generated from this property will use the result of toString() on each enum, allowing you to present a user-friendly value in the combo box instead of using the name(). Use the other constructor if you actually want to use name() instead of toString() for the combo box values.- Parameters:
name- The fully qualified property name.label- The human-readable label for this property.defaultValue- A default value to use for initial selection.
-
EnumProperty
Creates a new EnumProperty whose choices will be taken from the values of the supplied enum, and lets you choose whether you want to use name() or toString() for the possible combo box values.- Parameters:
name- The fully qualified property name.label- The human-readable label for this property.defaultValue- A default value to use for initial selection.useNamesInsteadOfLabels- If true, name() will be used for combo box values instead of toString().
-
-
Method Details
-
setSelectedIndex
-
getSelectedIndex
public int getSelectedIndex() -
setSelectedItem
-
indexOf
-
indexOf
-
getSelectedItem
-
saveToProps
Description copied from class:AbstractPropertySaves the current value(s) of this property to the given Properties instance.- Specified by:
saveToPropsin classAbstractProperty- Parameters:
props- Any Properties instance which will receive the value(s) of this property.
-
loadFromProps
Description copied from class:AbstractPropertyLoads the value(s) for this property from the given Properties instance, overwriting any current value. The current value of this property will be used as a default value in the event that this property does not exist in the given Properties instance.- Specified by:
loadFromPropsin classAbstractProperty- Parameters:
props- Any Properties instance which contains value(s) for this property.
-
generateFormFieldImpl
Description copied from class:AbstractPropertyDescendant classes must implement this method to generate a FormField associated with this property. The generateFormField() method in this class will call this abstract method to create the FormField, which will then be augmented with our fully qualified name, read-only state, help text, and extra attributes.- Specified by:
generateFormFieldImplin classAbstractProperty- Returns:
- A FormField associated with this property.
-
loadFromFormField
Description copied from class:AbstractPropertyPopulates this Property's value(s) from the given form field, assuming the field is of the correct type.- Specified by:
loadFromFormFieldin classAbstractProperty- Parameters:
field- The FormField containing a value for this property.
-