Class ComboBoxCellEditor

  • All Implemented Interfaces:
    ICellEditor
    Direct Known Subclasses:
    FilterRowComboBoxCellEditor

    public class ComboBoxCellEditor
    extends AbstractCellEditor
    ICellEditor implementation to provide combo box editing behaviour. Uses the NatCombo as editor control which provides free editing in the text control part and multi selection in the dropdown part if configured.

    You can create a ComboBoxCellEditor either by setting the items to show statically by constructor, or by using an IComboBoxDataProvider. Last one is a way to dynamically populate the items showed in a combobox in NatTable. It is not possible to mix these two approaches!

    • Field Detail

      • maxVisibleItems

        protected int maxVisibleItems
        The maximum number of items the drop down will show before introducing a scroll bar.
      • showDropdownFilter

        protected boolean showDropdownFilter
        Flag that indicates whether a text box is displayed to filter the drop down options
        Since:
        1.4
      • freeEdit

        protected boolean freeEdit
        Flag that indicates whether this ComboBoxCellEditor supports free editing in the text control of the NatCombo or not. By default free editing is disabled.
      • multiselect

        protected boolean multiselect
        Flag that indicates whether this ComboBoxCellEditor supports multiple selection or not. By default multiple selection is disabled.
      • useCheckbox

        protected boolean useCheckbox
        Flag that indicates whether this ComboBoxCellEditor shows checkboxes for items in the dropdown or not.
      • multiselectValueSeparator

        protected String multiselectValueSeparator
        String that is used to separate values in the String representation showed in the text control if multiselect is supported. null to use the default String ", ".
      • multiselectTextPrefix

        protected String multiselectTextPrefix
        String that is used to prefix the generated String representation showed in the text control if multiselect is supported. Needed to visualize the multiselection to the user. If this value is null the default String "[" is used.
      • multiselectTextSuffix

        protected String multiselectTextSuffix
        String that is used to suffix the generated String representation showed in the text control if multiselect is supported. Needed to visualize the multiselection to the user. If this value is null the default String "]" is used.
      • iconImage

        protected org.eclipse.swt.graphics.Image iconImage
        The image to use as overlay to the Text Control if the dropdown is visible. It will indicate that the control is an open combo to the user. If this value is null the default image specified in NatCombo will be used.
    • Constructor Detail

      • ComboBoxCellEditor

        public ComboBoxCellEditor​(List<?> canonicalValues)
        Create a new single selection ComboBoxCellEditor based on the given list of items, showing the default number of items in the dropdown of the combo.
        Parameters:
        canonicalValues - Array of items to be shown in the drop down box. These will be converted using the IDisplayConverter for display purposes
      • ComboBoxCellEditor

        public ComboBoxCellEditor​(Object... canonicalValues)
        Create a new single selection ComboBoxCellEditor based on the given list of items, showing the default number of items in the dropdown of the combo.
        Parameters:
        canonicalValues - Array of items to be shown in the drop down box. These will be converted using the IDisplayConverter for display purposes
        Since:
        1.5
      • ComboBoxCellEditor

        public ComboBoxCellEditor​(List<?> canonicalValues,
                                  int maxVisibleItems)
        Create a new single selection ComboBoxCellEditor based on the given list of items.
        Parameters:
        canonicalValues - Array of items to be shown in the drop down box. These will be converted using the IDisplayConverter for display purposes
        maxVisibleItems - The maximum number of items the drop down will show before introducing a scroll bar.
      • ComboBoxCellEditor

        public ComboBoxCellEditor​(IComboBoxDataProvider dataProvider)
        Create a new single selection ComboBoxCellEditor based on the given IComboBoxDataProvider, showing the default number of items in the dropdown of the combo.
        Parameters:
        dataProvider - The IComboBoxDataProvider that is responsible for populating the items to the dropdown box. This is the way to use a ComboBoxCellEditor with dynamic content.
      • ComboBoxCellEditor

        public ComboBoxCellEditor​(IComboBoxDataProvider dataProvider,
                                  int maxVisibleItems)
        Create a new single selection ComboBoxCellEditor based on the given IComboBoxDataProvider.
        Parameters:
        dataProvider - The IComboBoxDataProvider that is responsible for populating the items to the dropdown box. This is the way to use a ComboBoxCellEditor with dynamic content.
        maxVisibleItems - The maximum number of items the drop down will show before introducing a scroll bar.
    • Method Detail

      • activateCell

        protected org.eclipse.swt.widgets.Control activateCell​(org.eclipse.swt.widgets.Composite parent,
                                                               Object originalCanonicalValue)
        Description copied from class: AbstractCellEditor
        This method will be called by AbstractCellEditor.activateCell(Composite, Object, EditModeEnum, ICellEditHandler, ILayerCell, IConfigRegistry) after initializing the activation values and before adding the default listeners. In this method the underlying editor control should be created and initialized, hiding default configuration from editor implementors.
        Specified by:
        activateCell in class AbstractCellEditor
        Parameters:
        parent - The parent Composite, needed for the creation of the editor control.
        originalCanonicalValue - The value that should be put to the activated editor control.
        Returns:
        The SWT Control to be used for capturing the new cell value.
      • getCanonicalValue

        public Object getCanonicalValue()
        This implementation overrides the default implementation because we can work on the list of canonical items in the combo directly. Only for multiselect in combination with free editing, we need to convert here ourself.
        Specified by:
        getCanonicalValue in interface ICellEditor
        Overrides:
        getCanonicalValue in class AbstractCellEditor
        Returns:
        The canonical value after converting the current value or the value itself if no IDisplayConverter is configured.
        See Also:
        IDisplayConverter
      • setCanonicalValue

        public void setCanonicalValue​(Object canonicalValue)
        This implementation overrides the default implementation because of the special handling for comboboxes. It can handle multi selection and needs to transfer the converted values into a String array so the values in the combobox can be selected.
        Specified by:
        setCanonicalValue in interface ICellEditor
        Overrides:
        setCanonicalValue in class AbstractCellEditor
        Parameters:
        canonicalValue - The canonical value to be set to the wrapped editor control.
      • getEditorValue

        public Object getEditorValue()
        Description copied from interface: ICellEditor
        Returns the current value in this editor prior to conversion. For a text editor that is used to edit integer values, this would mean it returns the text value instead of the converted integer value. This method is only intended to be used internally .
        Returns:
        The current value in this editor prior to conversion.
      • setEditorValue

        public void setEditorValue​(Object value)
        Description copied from interface: ICellEditor
        Sets the given value to editor control. This method is used to put the display values to the wrapped editor.
        Parameters:
        value - The display value to set to the wrapped editor control.
      • getEditorControl

        public NatCombo getEditorControl()
        Returns:
        The editor control that is wrapped by this ICellEditor.
      • createEditorControl

        public NatCombo createEditorControl​(org.eclipse.swt.widgets.Composite parent)
        Description copied from interface: ICellEditor
        Creates the editor control that is wrapped by this ICellEditor. Will use the style configurations in ConfigRegistry for styling the control.
        Parameters:
        parent - The Composite that will be the parent of the new editor control. Can not be null
        Returns:
        The created editor control that is wrapped by this ICellEditor.
      • addNatComboListener

        protected void addNatComboListener​(NatCombo combo)
        Registers special listeners to the NatCombo regarding the EditModeEnum, that are needed to commit/close or change the visibility state of the NatCombo dependent on UI interactions.
        Parameters:
        combo - The NatCombo to add the listeners to.
      • select

        public void select​(int index)
        Selects the item at the given zero-relative index in the receiver's list. If the item at the index was already selected, it remains selected. Indices that are out of range are ignored.
        Parameters:
        index - the index of the item to select
        See Also:
        List.select(int)
      • select

        public void select​(int[] indices)
        Selects the items at the given zero-relative indices in the receiver. The current selection is not cleared before the new items are selected.

        If the item at a given index is not selected, it is selected. If the item at a given index was already selected, it remains selected. Indices that are out of range and duplicate indices are ignored. If the receiver is single-select and multiple indices are specified, then all indices are ignored.

        Parameters:
        indices - the array of indices for the items to select
        See Also:
        List.select(int[])
      • setMultiselectValueSeparator

        public void setMultiselectValueSeparator​(String multiselectValueSeparator)
        Parameters:
        multiselectValueSeparator - String that should be used to separate values in the String representation showed in the text control if multiselect is supported. null to use the default value separator.
        See Also:
        NatCombo.DEFAULT_MULTI_SELECT_VALUE_SEPARATOR
      • setMultiselectTextBracket

        public void setMultiselectTextBracket​(String multiselectTextPrefix,
                                              String multiselectTextSuffix)
        Set the prefix and suffix that will parenthesize the text that is created out of the selected values if this NatCombo supports multiselection.
        Parameters:
        multiselectTextPrefix - String that should be used to prefix the generated String representation showed in the text control if multiselect is supported. null to use the default prefix.
        multiselectTextSuffix - String that should be used to suffix the generated String representation showed in the text control if multiselect is supported. null to use the default suffix.
        See Also:
        NatCombo.DEFAULT_MULTI_SELECT_PREFIX, NatCombo.DEFAULT_MULTI_SELECT_SUFFIX
      • getIconImage

        public org.eclipse.swt.graphics.Image getIconImage()
        Returns:
        The image that is used as overlay to the Text Control if the dropdown is visible. It will indicate that the control is an open combo to the user. If this value is null the default image specified in NatCombo will be used.
      • setIconImage

        public void setIconImage​(org.eclipse.swt.graphics.Image iconImage)
        Parameters:
        iconImage - The image to use as overlay to the Text Control if the dropdown is visible. It will indicate that the control is an open combo to the user. If this value is null the default image specified in NatCombo will be used.
      • isFreeEdit

        public boolean isFreeEdit()
        Returns:
        true if this ComboBoxCellEditor supports free editing in the text control of the NatCombo or not. By default free editing is disabled.
      • setFreeEdit

        public void setFreeEdit​(boolean freeEdit)
        Parameters:
        freeEdit - true to indicate that this ComboBoxCellEditor supports free editing in the text control of the NatCombo, false if not.
      • isMultiselect

        public boolean isMultiselect()
        Returns:
        true if this ComboBoxCellEditor supports multiple selection or not. By default multiple selection is disabled.
      • setMultiselect

        public void setMultiselect​(boolean multiselect)
        Parameters:
        multiselect - true to indicate that this ComboBoxCellEditor supports multiple selection, false if not.
      • isUseCheckbox

        public boolean isUseCheckbox()
        Returns:
        true if this ComboBoxCellEditor shows checkboxes for items in the dropdown. By default there are not checkboxes shown.
      • setUseCheckbox

        public void setUseCheckbox​(boolean useCheckbox)
        Parameters:
        useCheckbox - true if this ComboBoxCellEditor should show checkboxes for items in the dropdown, false if not.
      • isShowDropdownFilter

        public boolean isShowDropdownFilter()
        Returns:
        true if this ComboBoxCellEditor should show the text control for filtering items in the dropdown. By default the filter is not shown.
        Since:
        1.4
      • setShowDropdownFilter

        public void setShowDropdownFilter​(boolean showDropdownFilter)
        Parameters:
        showDropdownFilter - true if this ComboBoxCellEditor should show the text control for filtering items in the dropdown, false if not.
        Since:
        1.4
      • isFocusOnText

        public boolean isFocusOnText()
        Returns:
        true if the focus on the activated combobox is set to the text field, false if the dropdown gets the focus. Default is false.
        Since:
        1.6
      • setFocusOnText

        public void setFocusOnText​(boolean focusOnText)
        Parameters:
        focusOnText - true if the focus on the activated combobox should be set to the text field, false if the dropdown should get the focus.
        Since:
        1.6