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.

public class EnumProperty<T extends Enum<?>> extends AbstractProperty
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. The generated ComboField will be typed to the given enum type, so if you need to interact with the ComboField directly, you can do so in a type-safe manner. Enum values are displayed to the user using their toString() value, but they are persisted to properties using their name() value. This allows you to change the toString() value over time (for localization, for example) without breaking existing saved properties.
Since:
2025-03-26
Author:
scorbo2
  • Constructor Details

    • EnumProperty

      public EnumProperty(String name, String label, T defaultValue)
      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().
      Parameters:
      name - The fully qualified property name.
      label - The human-readable label for this property.
      defaultValue - A default value to use for initial selection.
  • Method Details

    • setSelectedItem

      public EnumProperty<T> setSelectedItem(T item)
    • getSelectedItem

      public T getSelectedItem()
    • saveToProps

      public void saveToProps(Properties props)
      Description copied from class: AbstractProperty
      Saves the current value(s) of this property to the given Properties instance.
      Specified by:
      saveToProps in class AbstractProperty
      Parameters:
      props - Any Properties instance which will receive the value(s) of this property.
    • loadFromProps

      public void loadFromProps(Properties props)
      Description copied from class: AbstractProperty
      Loads 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:
      loadFromProps in class AbstractProperty
      Parameters:
      props - Any Properties instance which contains value(s) for this property.
    • generateFormFieldImpl

      protected FormField generateFormFieldImpl()
      Description copied from class: AbstractProperty
      Descendant 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:
      generateFormFieldImpl in class AbstractProperty
      Returns:
      A FormField associated with this property.
    • loadFromFormField

      public void loadFromFormField(FormField field)
      Description copied from class: AbstractProperty
      Populates this Property's value(s) from the given form field, assuming the field is of the correct type.
      Specified by:
      loadFromFormField in class AbstractProperty
      Parameters:
      field - The FormField containing a value for this property.