Class ComboBoxCellEditor
- java.lang.Object
-
- org.eclipse.nebula.widgets.nattable.edit.editor.AbstractCellEditor
-
- org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor
-
- All Implemented Interfaces:
ICellEditor
- Direct Known Subclasses:
FilterRowComboBoxCellEditor
public class ComboBoxCellEditor extends AbstractCellEditor
ICellEditor
implementation to provide combo box editing behaviour. Uses theNatCombo
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!
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.nebula.widgets.nattable.edit.editor.AbstractCellEditor
AbstractCellEditor.InlineFocusListener, AbstractCellEditor.InlineTraverseListener
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
freeEdit
Flag that indicates whether this ComboBoxCellEditor supports free editing in the text control of the NatCombo or not.protected org.eclipse.swt.graphics.Image
iconImage
The image to use as overlay to theText
Control if the dropdown is visible.protected int
maxVisibleItems
The maximum number of items the drop down will show before introducing a scroll bar.protected boolean
multiselect
Flag that indicates whether this ComboBoxCellEditor supports multiple selection or not.protected String
multiselectTextPrefix
String that is used to prefix the generated String representation showed in the text control if multiselect is supported.protected String
multiselectTextSuffix
String that is used to suffix the generated String representation showed in the text control if multiselect is supported.protected String
multiselectValueSeparator
String that is used to separate values in the String representation showed in the text control if multiselect is supported.protected boolean
showDropdownFilter
Flag that indicates whether a text box is displayed to filter the drop down optionsprotected boolean
useCheckbox
Flag that indicates whether this ComboBoxCellEditor shows checkboxes for items in the dropdown or not.-
Fields inherited from class org.eclipse.nebula.widgets.nattable.edit.editor.AbstractCellEditor
cellStyle, configRegistry, conversionEditErrorHandler, dataValidator, displayConverter, editMode, focusListener, labelStack, layerCell, parent, traverseListener, validationEditErrorHandler
-
-
Constructor Summary
Constructors Constructor Description ComboBoxCellEditor(Object... canonicalValues)
Create a new single selectionComboBoxCellEditor
based on the given list of items, showing the default number of items in the dropdown of the combo.ComboBoxCellEditor(List<?> canonicalValues)
Create a new single selectionComboBoxCellEditor
based on the given list of items, showing the default number of items in the dropdown of the combo.ComboBoxCellEditor(List<?> canonicalValues, int maxVisibleItems)
Create a new single selectionComboBoxCellEditor
based on the given list of items.ComboBoxCellEditor(IComboBoxDataProvider dataProvider)
Create a new single selectionComboBoxCellEditor
based on the givenIComboBoxDataProvider
, showing the default number of items in the dropdown of the combo.ComboBoxCellEditor(IComboBoxDataProvider dataProvider, int maxVisibleItems)
Create a new single selectionComboBoxCellEditor
based on the givenIComboBoxDataProvider
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.eclipse.swt.widgets.Control
activateCell(org.eclipse.swt.widgets.Composite parent, Object originalCanonicalValue)
This method will be called byAbstractCellEditor.activateCell(Composite, Object, EditModeEnum, ICellEditHandler, ILayerCell, IConfigRegistry)
after initializing the activation values and before adding the default listeners.protected void
addNatComboListener(NatCombo combo)
Registers special listeners to theNatCombo
regarding theEditModeEnum
, that are needed to commit/close or change the visibility state of theNatCombo
dependent on UI interactions.void
close()
Close/dispose the containedControl
NatCombo
createEditorControl(org.eclipse.swt.widgets.Composite parent)
Creates the editor control that is wrapped by this ICellEditor.Object
getCanonicalValue()
This implementation overrides the default implementation because we can work on the list of canonical items in the combo directly.NatCombo
getEditorControl()
Object
getEditorValue()
Returns the current value in this editor prior to conversion.org.eclipse.swt.graphics.Image
getIconImage()
boolean
isFocusOnText()
boolean
isFreeEdit()
boolean
isMultiselect()
boolean
isShowDropdownFilter()
boolean
isUseCheckbox()
void
select(int index)
Selects the item at the given zero-relative index in the receiver's list.void
select(int[] indices)
Selects the items at the given zero-relative indices in the receiver.void
setCanonicalValue(Object canonicalValue)
This implementation overrides the default implementation because of the special handling for comboboxes.void
setEditorValue(Object value)
Sets the given value to editor control.void
setFocusOnText(boolean focusOnText)
void
setFreeEdit(boolean freeEdit)
void
setIconImage(org.eclipse.swt.graphics.Image iconImage)
void
setMultiselect(boolean multiselect)
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.void
setMultiselectValueSeparator(String multiselectValueSeparator)
void
setShowDropdownFilter(boolean showDropdownFilter)
void
setUseCheckbox(boolean useCheckbox)
-
Methods inherited from class org.eclipse.nebula.widgets.nattable.edit.editor.AbstractCellEditor
activateAtAnyPosition, activateCell, activateOnTraversal, addEditorControlListeners, calculateControlBounds, commit, commit, commit, getCanonicalValue, getColumnIndex, getColumnPosition, getRowIndex, getRowPosition, handleConversion, isClosed, openAdjacentEditor, openInline, openMultiEditDialog, removeEditorControlListeners, setDataValidator, supportMultiEdit, validateCanonicalValue, validateCanonicalValue
-
-
-
-
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 isnull
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 isnull
the default String "]" is used.
-
iconImage
protected org.eclipse.swt.graphics.Image iconImage
The image to use as overlay to theText
Control if the dropdown is visible. It will indicate that the control is an open combo to the user. If this value isnull
the default image specified in NatCombo will be used.
-
-
Constructor Detail
-
ComboBoxCellEditor
public ComboBoxCellEditor(List<?> canonicalValues)
Create a new single selectionComboBoxCellEditor
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 theIDisplayConverter
for display purposes
-
ComboBoxCellEditor
public ComboBoxCellEditor(Object... canonicalValues)
Create a new single selectionComboBoxCellEditor
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 theIDisplayConverter
for display purposes- Since:
- 1.5
-
ComboBoxCellEditor
public ComboBoxCellEditor(List<?> canonicalValues, int maxVisibleItems)
Create a new single selectionComboBoxCellEditor
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 theIDisplayConverter
for display purposesmaxVisibleItems
- The maximum number of items the drop down will show before introducing a scroll bar.
-
ComboBoxCellEditor
public ComboBoxCellEditor(IComboBoxDataProvider dataProvider)
Create a new single selectionComboBoxCellEditor
based on the givenIComboBoxDataProvider
, showing the default number of items in the dropdown of the combo.- Parameters:
dataProvider
- TheIComboBoxDataProvider
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 selectionComboBoxCellEditor
based on the givenIComboBoxDataProvider
.- Parameters:
dataProvider
- TheIComboBoxDataProvider
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 byAbstractCellEditor.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 classAbstractCellEditor
- 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 interfaceICellEditor
- Overrides:
getCanonicalValue
in classAbstractCellEditor
- 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 interfaceICellEditor
- Overrides:
setCanonicalValue
in classAbstractCellEditor
- Parameters:
canonicalValue
- The canonical value to be set to the wrapped editor control.
-
close
public void close()
Description copied from interface:ICellEditor
Close/dispose the containedControl
- Specified by:
close
in interfaceICellEditor
- Overrides:
close
in classAbstractCellEditor
-
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 benull
- Returns:
- The created editor control that is wrapped by this ICellEditor.
-
addNatComboListener
protected void addNatComboListener(NatCombo combo)
Registers special listeners to theNatCombo
regarding theEditModeEnum
, that are needed to commit/close or change the visibility state of theNatCombo
dependent on UI interactions.- Parameters:
combo
- TheNatCombo
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 isnull
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 theText
Control if the dropdown is visible. It will indicate that the control is an open combo to the user. If this value isnull
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 isfalse
.- 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
-
-