Class SelectItemAction

All Implemented Interfaces:
ActionListener, PropertyChangeListener, Serializable, Cloneable, Comparable, EventListener, Action
Direct Known Subclasses:
SetFontFaceAction, SetFontSizeAction

@OpenApiAll public class SelectItemAction extends ActionsCategory implements PropertyChangeListener
Action for selecting item from the list. List can contain any objects which have correct toString() method. When this action is represented as toolbar GUI component is a combo box. When this action is represented as menu GUI component is a sub menu. By default combo box and sub menu items displays only strings from list elements, but it can be changed by overriding createAction(Object, String) method which can create another type of actions used to display list items.

Selected item can be got using getCurrent() method. When selection is changed action fires property change event with name getValueName().

See Also:
  • Field Details

    • ADDITIONAL_PROPERTY_MAX_WIDTH

      public static final String ADDITIONAL_PROPERTY_MAX_WIDTH
      A name of additional action property for specifying max width of component. Toolbar creator may use that setting if needed.
      See Also:
  • Constructor Details

    • SelectItemAction

      public SelectItemAction(String id, String name, @CheckForNull KeyStroke stroke, @CheckForNull String group, @CheckForNull List<?> items, String valueName)
      Creates action and fills it with action for each element from list.
      Parameters:
      id - id of action
      name - action name
      stroke - key stroke for action.
      group - action group.
      items - list of selections.
      valueName - name of fired property when value is changed.
      See Also:
    • SelectItemAction

      public SelectItemAction(String id, String name, int stroke, @CheckForNull String group, @CheckForNull List<?> items, String valueName)
      Creates action and fills it with action for each element from list.
      Parameters:
      id - id of action
      name - action name
      stroke - key stroke for action.
      group - action group.
      items - list selections.
      valueName - name of fired property when value is changed.
      See Also:
  • Method Details

    • setItems

      public void setItems(@CheckForNull List<?> items)
      Sets List value. For each item from items new action will be created using createAction method.
      Parameters:
      items - items of objects from which actions will be created.
    • getItems

      public List<?> getItems()
    • setList

      @Deprecated public void setList(List newList)
      Deprecated.
      use #setItems(java.util.List)
    • createAction

      protected SelectionStateItem createAction(Object obj, String valueName)
      Method creates action which represents given object, and fires PropertyChangeEvent with name valueName when it is executed.
      Parameters:
      obj - object from which action will be created.
      valueName - property name which should be fired when created action is executed.
      See Also:
    • propertyChange

      public void propertyChange(PropertyChangeEvent e)
      Listens for child action. Puts value got from the event with getPropertyName() using setCurrent( method ) method. If children actions is state actions updates theirs state.
      Specified by:
      propertyChange in interface PropertyChangeListener
    • updateState

      public void updateState()
      Updates state for actions from actions in list.
      Overrides:
      updateState in class NMAction
      See Also:
    • clone

      public SelectItemAction clone()
      Description copied from class: ActionsCategory
      Clones the category. During clone does not fire any property change events. Does deep clone.
      Overrides:
      clone in class ActionsCategory
      Returns:
      deep clone of category.
    • getValue

      public Object getValue()
      Method returns current selection.
      Returns:
      currently selected object.
    • isChangeable

      public boolean isChangeable()
      Returns true if new action item can be added.
      Returns:
      true if this action is changeable.
    • setChangeable

      public void setChangeable(boolean val)
      Sets changeable property.
      Parameters:
      val - new value.
    • setValue

      public void setValue(Object value)
      Sets new value of this list action.
    • getValueName

      public String getValueName()
      Returns property name which will be used to fire property change and to put value.
      Returns:
      property name.
    • accept

      public void accept(ActionsVisitor visitor)
      If given visitor is MainActionsVisitor, visit this action in different way.
      Overrides:
      accept in class ActionsCategory
      Parameters:
      visitor - the given visitor.
    • isShowActionName

      public boolean isShowActionName()
    • setShowActionName

      public void setShowActionName(boolean showActionName)
    • isDisplayAsComboBox

      public boolean isDisplayAsComboBox()
    • setDisplayAsComboBox

      public void setDisplayAsComboBox(boolean displayAsComboBox)