Class FAbstractSelect

java.lang.Object
com.vaadin.featurepack.data.ui.FAbstractSelect
All Implemented Interfaces:
Buffered, BufferedValidatable, Container, Container.ItemSetChangeListener, Container.ItemSetChangeNotifier, Container.PropertySetChangeListener, Container.PropertySetChangeNotifier, Container.Viewer, Property<Object>, Property.Editor, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer, Field<Object>, Select, Validatable, Serializable

public class FAbstractSelect extends Object implements Select
See Also:
  • Field Details

    • items

      protected Container items
      Select options.
    • itemIdMapper

      protected com.vaadin.flow.data.provider.KeyMapper<Object> itemIdMapper
      Keymapper used to map key values.
  • Constructor Details

    • FAbstractSelect

      public FAbstractSelect(com.vaadin.flow.component.Component component)
    • FAbstractSelect

      public FAbstractSelect()
      Creates an empty Select. The caption is not used.
    • FAbstractSelect

      public FAbstractSelect(String caption)
      Creates an empty Select with caption.
    • FAbstractSelect

      public FAbstractSelect(String caption, Container dataSource)
      Creates a new select that is connected to a data-source.
      Parameters:
      caption - the Caption of the component.
      dataSource - the Container datasource to be selected from by this select.
    • FAbstractSelect

      public FAbstractSelect(String caption, Collection<?> options)
      Creates a new select that is filled from a collection of option values.
      Parameters:
      caption - the Caption of this field.
      options - the Collection containing the options.
  • Method Details

    • setComponentOverridesSetValue

      public void setComponentOverridesSetValue(boolean componentOverridesSetValue)
    • isComponentOverridesSetValue

      public boolean isComponentOverridesSetValue()
    • setNewItemHandler

      public void setNewItemHandler(FAbstractSelect.NewItemHandler newItemHandler)
      TODO refine doc Setter for new item handler that is called when user adds new item in newItemAllowed mode.
      Parameters:
      newItemHandler -
    • getNewItemHandler

      public FAbstractSelect.NewItemHandler getNewItemHandler()
      TODO refine doc
      Returns:
    • getVisibleItemIds

      public Collection<?> getVisibleItemIds()
      Gets the visible item ids. In Select, this returns list of all item ids, but can be overriden in subclasses if they paint only part of the items to the terminal or null if no items is visible.
    • getType

      public Class<?> getType()
      Returns the type of the property. getValue and setValue methods must be compatible with this type: one can safely cast getValue to given type and pass any variable assignable to this type as a parameter to setValue.
      Specified by:
      getType in interface Field<Object>
      Specified by:
      getType in interface Property<Object>
      Returns:
      the Type of the property.
    • getValue

      public Object getValue()
      Gets the selected item id or in multiselect mode a set of selected ids.
      Specified by:
      getValue in interface Property<Object>
      Specified by:
      getValue in interface Select
      Returns:
      the value stored in the Property
      See Also:
      • AbstractField.getValue()
    • setValue

      protected void setValue(Object newFieldValue, boolean repaintIsNotNeeded)
    • setValue

      public void setValue(Object newValue) throws Property.ReadOnlyException
      Sets the visible value of the property.

      The value of the select is the selected item id. If the select is in multiselect-mode, the value is a set of selected item keys. In multiselect mode all collections of id:s can be assigned.

      Specified by:
      setValue in interface Property<Object>
      Specified by:
      setValue in interface Select
      Parameters:
      newValue - the New selected item or collection of selected items.
      Throws:
      Property.ReadOnlyException - if the object is in read-only mode
      See Also:
      • AbstractField.setValue(java.lang.Object)
    • setValue

      protected void setValue(Object newFieldValue, boolean repaintIsNotNeeded, boolean ignoreReadOnly) throws Property.ReadOnlyException, ConversionException, Validator.InvalidValueException
      Sets the visible value of the property.

      The value of the select is the selected item id. If the select is in multiselect-mode, the value is a set of selected item keys. In multiselect mode all collections of id:s can be assigned.

      Parameters:
      repaintIsNotNeeded - True if caller is sure that repaint is not needed.
      ignoreReadOnly - True if read-only check should be omitted.
      newValue - the New selected item or collection of selected items.
      Throws:
      Property.ReadOnlyException
      ConversionException
      Validator.InvalidValueException
      Since:
      7.5.7
      See Also:
      • invalid reference
        AbstractField#setValue(java.lang.Object, java.lang.Boolean)
    • getItem

      public Item getItem(Object itemId)
      Gets the item from the container with given id. If the container does not contain the requested item, null is returned.
      Specified by:
      getItem in interface Container
      Specified by:
      getItem in interface Select
      Parameters:
      itemId - the item id.
      Returns:
      the item from the container.
    • getItemIds

      public Collection<?> getItemIds()
      Gets the item Id collection from the container.
      Specified by:
      getItemIds in interface Container
      Specified by:
      getItemIds in interface Select
      Returns:
      the Collection of item ids.
    • getContainerPropertyIds

      public Collection<?> getContainerPropertyIds()
      Gets the property Id collection from the container.
      Specified by:
      getContainerPropertyIds in interface Container
      Specified by:
      getContainerPropertyIds in interface Select
      Returns:
      the Collection of property ids.
    • getType

      public Class<?> getType(Object propertyId)
      Gets the property type.
      Specified by:
      getType in interface Container
      Specified by:
      getType in interface Select
      Parameters:
      propertyId - the Id identifying the property.
      Returns:
      data type of the Properties
      See Also:
    • size

      public int size()
      Gets the number of items in the container.
      Specified by:
      size in interface Container
      Specified by:
      size in interface Select
      Returns:
      the Number of items in the container.
      See Also:
    • containsId

      public boolean containsId(Object itemId)
      Tests, if the collection contains an item with given id.
      Specified by:
      containsId in interface Container
      Specified by:
      containsId in interface Select
      Parameters:
      itemId - the Id the of item to be tested.
      Returns:
      boolean indicating if the Container holds the specified Item
    • getContainerProperty

      public Property getContainerProperty(Object itemId, Object propertyId)
      Gets the Property identified by the given itemId and propertyId from the Container
      Specified by:
      getContainerProperty in interface Container
      Specified by:
      getContainerProperty in interface Select
      Parameters:
      itemId - ID of the visible Item which contains the Property
      propertyId - ID of the Property to retrieve
      Returns:
      Property with the given ID or null
      See Also:
    • addContainerProperty

      public boolean addContainerProperty(Object propertyId, Class<?> type, Object defaultValue) throws UnsupportedOperationException
      Adds the new property to all items. Adds a property with given id, type and default value to all items in the container. This functionality is optional. If the function is unsupported, it always returns false.
      Specified by:
      addContainerProperty in interface Container
      Specified by:
      addContainerProperty in interface Select
      Parameters:
      propertyId - ID of the Property
      type - Data type of the new Property
      defaultValue - The value all created Properties are initialized to
      Returns:
      True if the operation succeeded.
      Throws:
      UnsupportedOperationException - if the container does not support explicitly adding container properties
      See Also:
    • removeAllItems

      public boolean removeAllItems() throws UnsupportedOperationException
      Removes all items from the container. This functionality is optional. If the function is unsupported, it always returns false.
      Specified by:
      removeAllItems in interface Container
      Specified by:
      removeAllItems in interface Select
      Returns:
      True if the operation succeeded.
      Throws:
      UnsupportedOperationException - if the container does not support removing all items
      See Also:
    • addItem

      public Object addItem() throws UnsupportedOperationException
      Creates a new item into container with container managed id. The id of the created new item is returned. The item can be fetched with getItem() method. if the creation fails, null is returned.
      Specified by:
      addItem in interface Container
      Specified by:
      addItem in interface Select
      Returns:
      the Id of the created item or null in case of failure.
      Throws:
      UnsupportedOperationException - if adding an item without an explicit item ID is not supported by the container
      See Also:
    • addItem

      public Item addItem(Object itemId) throws UnsupportedOperationException
      Create a new item into container. The created new item is returned and ready for setting property values. if the creation fails, null is returned. In case the container already contains the item, null is returned. This functionality is optional. If the function is unsupported, it always returns null.
      Specified by:
      addItem in interface Container
      Specified by:
      addItem in interface Select
      Parameters:
      itemId - the Identification of the item to be created.
      Returns:
      the Created item with the given id, or null in case of failure.
      Throws:
      UnsupportedOperationException - if adding an item with an explicit item ID is not supported by the container
      See Also:
    • addItems

      public void addItems(Object... itemId) throws UnsupportedOperationException
      Adds given items with given item ids to container.
      Parameters:
      itemId - item identifiers to be added to underlying container
      Throws:
      UnsupportedOperationException - if the underlying container don't support adding items with identifiers
      Since:
      7.2
    • addItems

      public void addItems(Collection<?> itemIds) throws UnsupportedOperationException
      Adds given items with given item ids to container.
      Parameters:
      itemIds - item identifiers to be added to underlying container
      Throws:
      UnsupportedOperationException - if the underlying container don't support adding items with identifiers
      Since:
      7.2
    • removeItem

      public boolean removeItem(Object itemId) throws UnsupportedOperationException
      Description copied from interface: Container
      Removes the Item identified by ItemId from the Container.

      Containers that support filtering should also allow removing an item that is currently filtered out.

      This functionality is optional.

      Specified by:
      removeItem in interface Container
      Specified by:
      removeItem in interface Select
      Parameters:
      itemId - ID of the Item to remove
      Returns:
      true if the operation succeeded, false if not
      Throws:
      UnsupportedOperationException - if the container does not support removing individual items
    • sanitizeSelection

      public void sanitizeSelection()
      Checks that the current selection is valid, i.e. the selected item ids exist in the container. Updates the selection if one or several selected item ids are no longer available in the container.
    • removeContainerProperty

      public boolean removeContainerProperty(Object propertyId)
      Removes the property from all items. Removes a property with given id from all the items in the container. This functionality is optional. If the function is unsupported, it always returns false.
      Specified by:
      removeContainerProperty in interface Container
      Specified by:
      removeContainerProperty in interface Select
      Parameters:
      propertyId - ID of the Property to remove
      Returns:
      True if the operation succeeded.
      See Also:
    • setContainerDataSource

      public void setContainerDataSource(Container newDataSource)
      Sets the Container that serves as the data source of the viewer. As a side-effect the fields value (selection) is set to null due old selection not necessary exists in new Container.
      Specified by:
      setContainerDataSource in interface Container.Viewer
      Specified by:
      setContainerDataSource in interface Select
      Parameters:
      newDataSource - the new data source.
      See Also:
    • getContainerDataSource

      public Container getContainerDataSource()
      Gets the viewing data-source container.
      Specified by:
      getContainerDataSource in interface Container.Viewer
      Specified by:
      getContainerDataSource in interface Select
      Returns:
      data source Container
      See Also:
    • isMultiSelect

      public boolean isMultiSelect()
      Is the select in multiselect mode? In multiselect mode
      Specified by:
      isMultiSelect in interface Select
      Returns:
      the Value of property multiSelect.
    • setMultiSelect

      public void setMultiSelect(boolean multiSelect)
      Sets the multiselect mode. Setting multiselect mode false may lose selection information: if selected items set contains one or more selected items, only one of the selected items is kept as selected. Subclasses of AbstractSelect can choose not to support changing the multiselect mode, and may throw UnsupportedOperationException.
      Specified by:
      setMultiSelect in interface Select
      Parameters:
      multiSelect - the New value of property multiSelect.
    • isNewItemsAllowed

      public boolean isNewItemsAllowed()
      Does the select allow adding new options by the user. If true, the new options can be added to the Container. The text entered by the user is used as id. Note that data-source must allow adding new items.
      Specified by:
      isNewItemsAllowed in interface Select
      Returns:
      True if additions are allowed.
    • setNewItemsAllowed

      public void setNewItemsAllowed(boolean allowNewOptions)
      Enables or disables possibility to add new options by the user.
      Specified by:
      setNewItemsAllowed in interface Select
      Parameters:
      allowNewOptions - the New value of property allowNewOptions.
    • setItemCaption

      public void setItemCaption(Object itemId, String caption)
      Override the caption of an item. Setting caption explicitly overrides id, item and index captions.
      Parameters:
      itemId - the id of the item to be recaptioned.
      caption - the New caption.
    • getItemCaption

      public String getItemCaption(Object itemId)
      Gets the caption of an item. The caption is generated as specified by the item caption mode. See setItemCaptionMode() for more details.
      Specified by:
      getItemCaption in interface Select
      Parameters:
      itemId - the id of the item to be queried.
      Returns:
      the caption for specified item.
    • setItemIcon

      public void setItemIcon(Object itemId, Resource icon)
      Sets the icon for an item.
      Specified by:
      setItemIcon in interface Select
      Parameters:
      itemId - the id of the item to be assigned an icon.
      icon - the icon to use or null.
    • getItemIcon

      public Resource getItemIcon(Object itemId)
      Gets the item icon.
      Specified by:
      getItemIcon in interface Select
      Parameters:
      itemId - the id of the item to be assigned an icon.
      Returns:
      the icon for the item or null, if not specified.
    • setItemCaptionMode

      public void setItemCaptionMode(FAbstractSelect.ItemCaptionMode mode)
      Sets the item caption mode. See FAbstractSelect.ItemCaptionMode for a description of the modes.

      FAbstractSelect.ItemCaptionMode.EXPLICIT_DEFAULTS_ID is the default mode.

      Specified by:
      setItemCaptionMode in interface Select
      Parameters:
      mode - the One of the modes listed above.
    • getItemCaptionMode

      public FAbstractSelect.ItemCaptionMode getItemCaptionMode()
      Gets the item caption mode.

      The mode can be one of the following ones:

      • ITEM_CAPTION_MODE_EXPLICIT_DEFAULTS_ID : Items Id-objects toString is used as item caption. If caption is explicitly specified, it overrides the id-caption.
      • ITEM_CAPTION_MODE_ID : Items Id-objects toString is used as item caption.
      • ITEM_CAPTION_MODE_ITEM : Item-objects toString is used as item caption.
      • ITEM_CAPTION_MODE_INDEX : The index of the item is used as item caption. The index mode can only be used with the containers implementing Container.Indexed interface.
      • ITEM_CAPTION_MODE_EXPLICIT : The item captions must be explicitly specified.
      • ITEM_CAPTION_MODE_PROPERTY : The item captions are read from property, that must be specified with setItemCaptionPropertyId.
      The ITEM_CAPTION_MODE_EXPLICIT_DEFAULTS_ID is the default mode.

      Specified by:
      getItemCaptionMode in interface Select
      Returns:
      the One of the modes listed above.
    • setItemCaptionPropertyId

      public void setItemCaptionPropertyId(Object propertyId)
      Sets the item caption property.

      Setting the id to a existing property implicitly sets the item caption mode to ITEM_CAPTION_MODE_PROPERTY. If the object is in ITEM_CAPTION_MODE_PROPERTY mode, setting caption property id null resets the item caption mode to ITEM_CAPTION_EXPLICIT_DEFAULTS_ID.

      Note that the type of the property used for caption must be String

      Setting the property id to null disables this feature. The id is null by default

      .
      Specified by:
      setItemCaptionPropertyId in interface Select
      Parameters:
      propertyId - the id of the property.
    • getItemCaptionPropertyId

      public Object getItemCaptionPropertyId()
      Gets the item caption property.
      Specified by:
      getItemCaptionPropertyId in interface Select
      Returns:
      the Id of the property used as item caption source.
    • setItemIconPropertyId

      public void setItemIconPropertyId(Object propertyId) throws IllegalArgumentException
      Sets the item icon property.

      If the property id is set to a valid value, each item is given an icon got from the given property of the items. The type of the property must be assignable to Resource.

      Note : The icons set with setItemIcon function override the icons from the property.

      Setting the property id to null disables this feature. The id is null by default

      .
      Specified by:
      setItemIconPropertyId in interface Select
      Parameters:
      propertyId - the id of the property that specifies icons for items or null
      Throws:
      IllegalArgumentException - If the propertyId is not in the container or is not of a valid type
    • getItemIconPropertyId

      public Object getItemIconPropertyId()
      Gets the item icon property.

      If the property id is set to a valid value, each item is given an icon got from the given property of the items. The type of the property must be assignable to Icon.

      Note : The icons set with setItemIcon function override the icons from the property.

      Setting the property id to null disables this feature. The id is null by default

      .
      Specified by:
      getItemIconPropertyId in interface Select
      Returns:
      the Id of the property containing the item icons.
    • isSelected

      public boolean isSelected(Object itemId)
      Tests if an item is selected.

      In single select mode testing selection status of the item identified by getNullSelectionItemId() returns true if the value of the property is null.

      Parameters:
      itemId - the Id the of the item to be tested.
      See Also:
    • select

      public void select(Object itemId)
      Selects an item.

      In single select mode selecting item identified by getNullSelectionItemId() sets the value of the property to null.

      Specified by:
      select in interface Select
      Parameters:
      itemId - the identifier of Item to be selected.
      See Also:
    • unselect

      public void unselect(Object itemId)
      Unselects an item.
      Parameters:
      itemId - the identifier of the Item to be unselected.
      See Also:
    • containerPropertySetChange

      public void containerPropertySetChange(Container.PropertySetChangeEvent event)
      Notifies this listener that the Containers contents has changed.
      Specified by:
      containerPropertySetChange in interface Container.PropertySetChangeListener
      Specified by:
      containerPropertySetChange in interface Select
      Parameters:
      event - Change event.
      See Also:
    • addPropertySetChangeListener

      public void addPropertySetChangeListener(Container.PropertySetChangeListener listener)
      Adds a new Property set change listener for this Container.
      Specified by:
      addPropertySetChangeListener in interface Container.PropertySetChangeNotifier
      Specified by:
      addPropertySetChangeListener in interface Select
      Parameters:
      listener - The new Listener to be registered
      See Also:
      • invalid reference
        Container.PropertySetChangeNotifier#addListener(Container.PropertySetChangeListener)
    • removePropertySetChangeListener

      public void removePropertySetChangeListener(Container.PropertySetChangeListener listener)
      Removes a previously registered Property set change listener.
      Specified by:
      removePropertySetChangeListener in interface Container.PropertySetChangeNotifier
      Specified by:
      removePropertySetChangeListener in interface Select
      Parameters:
      listener - Listener to be removed
      See Also:
      • invalid reference
        Container.PropertySetChangeNotifier#removeListener(Container.PropertySetChangeListener)
    • addItemSetChangeListener

      public void addItemSetChangeListener(Container.ItemSetChangeListener listener)
      Adds an Item set change listener for the object.
      Specified by:
      addItemSetChangeListener in interface Container.ItemSetChangeNotifier
      Specified by:
      addItemSetChangeListener in interface Select
      Parameters:
      listener - listener to be added
      See Also:
      • invalid reference
        Container.ItemSetChangeNotifier#addListener(Container.ItemSetChangeListener)
    • removeItemSetChangeListener

      public void removeItemSetChangeListener(Container.ItemSetChangeListener listener)
      Removes the Item set change listener from the object.
      Specified by:
      removeItemSetChangeListener in interface Container.ItemSetChangeNotifier
      Specified by:
      removeItemSetChangeListener in interface Select
      Parameters:
      listener - listener to be removed
      See Also:
      • invalid reference
        Container.ItemSetChangeNotifier#removeListener(Container.ItemSetChangeListener)
    • getListeners

      public Collection<?> getListeners(Class<? extends com.vaadin.flow.component.ComponentEvent> eventType)
    • containerItemSetChange

      public void containerItemSetChange(Container.ItemSetChangeEvent event)
      Lets the listener know a Containers Item set has changed.
      Specified by:
      containerItemSetChange in interface Container.ItemSetChangeListener
      Specified by:
      containerItemSetChange in interface Select
      Parameters:
      event - change event text
      See Also:
    • firePropertySetChange

      protected void firePropertySetChange()
      Fires the property set change event.
    • fireItemSetChange

      protected void fireItemSetChange()
      Fires the item set change event.
    • isEmpty

      public boolean isEmpty()
      For multi-selectable fields, also an empty collection of values is considered to be an empty field.
      Specified by:
      isEmpty in interface Field<Object>
      Returns:
      true if the field is empty, false otherwise
    • setNullSelectionAllowed

      public void setNullSelectionAllowed(boolean nullSelectionAllowed)
      Allow or disallow empty selection by the user. If the select is in single-select mode, you can make an item represent the empty selection by calling setNullSelectionItemId(). This way you can for instance set an icon and caption for the null selection item.
      Specified by:
      setNullSelectionAllowed in interface Select
      Parameters:
      nullSelectionAllowed - whether or not to allow empty selection
      See Also:
    • isNullSelectionAllowed

      public boolean isNullSelectionAllowed()
      Checks if null empty selection is allowed by the user.
      Specified by:
      isNullSelectionAllowed in interface Select
      Returns:
      whether or not empty selection is allowed
      See Also:
    • getNullSelectionItemId

      public Object getNullSelectionItemId()
      Returns the item id that represents null value of this select in single select mode.

      Data interface does not support nulls as item ids. Selecting the item identified by this id is the same as selecting no items at all. This setting only affects the single select mode.

      Specified by:
      getNullSelectionItemId in interface Select
      Returns:
      the Object Null value item id.
      See Also:
    • setNullSelectionItemId

      public void setNullSelectionItemId(Object nullSelectionItemId)
      Sets the item id that represents null value of this select.

      Data interface does not support nulls as item ids. Selecting the item identified by this id is the same as selecting no items at all. This setting only affects the single select mode.

      Specified by:
      setNullSelectionItemId in interface Select
      Parameters:
      nullSelectionItemId - the nullSelectionItemId to set.
      See Also:
    • getCaptionChangeListener

      protected FAbstractSelect.CaptionChangeListener getCaptionChangeListener()