public class NatCombo
extends org.eclipse.swt.widgets.Composite
This control supports the ability for multi select in the dropdown of the combo which is not available for the SWT Combo control. This feature was added with Nebula NatTable 1.0.0
The following style bits are supported by this control.
(if a border should be added to the Text control),
(default for Text control, if this is missing, the Text
control can be edited),
(if the items in the combo should be showed with checkboxes),
(if multi selection is allowed)| Modifier and Type | Class and Description |
|---|---|
class |
NatCombo.FocusListenerWrapper
FocusListener that is used to ensure that the Text control and the
dropdown table control are sharing the same focus.
|
| Modifier and Type | Field and Description |
|---|---|
protected IStyle |
cellStyle
The IStyle that is used for rendering the Text and the combo control.
|
static String |
DEFAULT_MULTI_SELECT_PREFIX
Default String that is used to prefix the generated String representation
showed in the text control if multiselect is supported.
|
static String |
DEFAULT_MULTI_SELECT_SUFFIX
String that is used to suffix the generated String representation showed
in the text control if multiselect is supported.
|
static String |
DEFAULT_MULTI_SELECT_VALUE_SEPARATOR
Default String that is used to separate values in the String
representation showed in the text control if multiselect is supported.
|
static int |
DEFAULT_NUM_OF_VISIBLE_ITEMS
The default number of visible items on open the combo.
|
protected org.eclipse.swt.widgets.Shell |
dropdownShell
The Shell containing the dropdown of this NatCombo
|
protected org.eclipse.swt.widgets.Table |
dropdownTable
The Table control used for the combo component of this NatCombo
|
protected org.eclipse.jface.viewers.TableViewer |
dropdownTableViewer
The Table control used for the combo component of this NatCombo
|
protected org.eclipse.swt.widgets.Text |
filterBox
The text control allowing filtering of options
|
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 that is shown at the right edge of the text control if the
NatCombo is opened.
|
protected List<String> |
itemList
The items that are showed within the combo transformed to a
java.util.List.
|
protected int |
maxVisibleItems
The maximum number of visible items of the combo.
|
protected boolean |
multiselect
Flag that indicates whether this NatCombo supports multiselect 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 Map<String,Boolean> |
selectionStateMap
Map used to hold the selection state of items in the drop.
|
protected boolean |
showDropdownFilter
Flag that indicated whether this NatCombo supports filtering of the
values in the dropdown control
|
protected int |
style
The style bits that where set on creation time.
|
protected org.eclipse.swt.widgets.Text |
text
The text control of this NatCombo, allowing to enter values directly.
|
protected boolean |
useCheckbox
Flag that indicates whether checkboxes should be shown for the items in
the dropdown.
|
| Constructor and Description |
|---|
NatCombo(org.eclipse.swt.widgets.Composite parent,
IStyle cellStyle,
int style)
Creates a new NatCombo using the given IStyle for rendering, showing the
default number of items at once in the dropdown.
|
NatCombo(org.eclipse.swt.widgets.Composite parent,
IStyle cellStyle,
int maxVisibleItems,
int style)
Creates a new NatCombo using the given IStyle for rendering, showing the
given amount of items at once in the dropdown.
|
NatCombo(org.eclipse.swt.widgets.Composite parent,
IStyle cellStyle,
int maxVisibleItems,
int style,
boolean showDropdownFilter)
Creates a new NatCombo using the given IStyle for rendering, showing the
given amount of items at once in the dropdown.
|
NatCombo(org.eclipse.swt.widgets.Composite parent,
IStyle cellStyle,
int maxVisibleItems,
int style,
org.eclipse.swt.graphics.Image iconImage)
Creates a new NatCombo using the given IStyle for rendering, showing the
given amount of items at once in the dropdown.
|
NatCombo(org.eclipse.swt.widgets.Composite parent,
IStyle cellStyle,
int maxVisibleItems,
int style,
org.eclipse.swt.graphics.Image iconImage,
boolean showDropdownFilter)
Creates a new NatCombo using the given IStyle for rendering, showing the
given amount of items at once in the dropdown.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addFocusListener(org.eclipse.swt.events.FocusListener listener) |
void |
addKeyListener(org.eclipse.swt.events.KeyListener listener) |
void |
addMouseListener(org.eclipse.swt.events.MouseListener listener) |
void |
addSelectionListener(org.eclipse.swt.events.SelectionListener listener) |
void |
addShellListener(org.eclipse.swt.events.ShellListener listener) |
void |
addTextControlListener(org.eclipse.swt.events.ControlListener listener) |
void |
addTraverseListener(org.eclipse.swt.events.TraverseListener listener) |
protected void |
applyDropdownListener() |
protected void |
calculateBounds()
Calculates the size and location of the Shell that represents the
dropdown control of this NatCombo.
|
protected void |
calculateColumnWidth()
Calculates and applies the column width to ensure that the column has the
same width as the table itself, so selection is possible for the whole
row.
|
protected void |
createDropdownControl(int style)
Create the dropdown control of this NatCombo, adding styles,
look&feel and needed listeners for the control only.
|
protected void |
createTextControl(int style)
Creates the Text control of this NatCombo, adding styles, look&feel
and needed listeners for the control only.
|
boolean |
forceFocus() |
protected org.eclipse.swt.widgets.Table |
getDropdownTable() |
String[] |
getSelection()
Returns an array of
Strings that are currently selected in
the receiver. |
int |
getSelectionCount()
Returns the number of selected items contained in the receiver.
|
int |
getSelectionIndex()
Returns the zero-relative index of the item which is currently selected
in the receiver, or -1 if no item is selected.
|
int[] |
getSelectionIndices()
Returns the zero-relative indices of the items which are currently
selected in the receiver.
|
protected String[] |
getTextAsArray()
Will transform the text for the Text control of this NatCombo to an array
of Strings.
|
protected String[] |
getTransformedSelection()
Transforms the selection in the Table control dropdown into a String[].
|
protected String |
getTransformedText(String[] values)
Transforms the given array of Strings to a text representation that can
be added to the text control of this combo.
|
protected String |
getTransformedTextForSelection()
Transforms the selection of the dropdown to a text representation that
can be added to the text control of this combo.
|
protected int |
getVisibleItemCount()
Calculates the number of items that should be showed in the dropdown at
once.
|
void |
hideDropdownControl()
Hide the dropdown of this NatCombo.
|
boolean |
isFocusControl() |
void |
notifyListeners(int eventType,
org.eclipse.swt.widgets.Event event) |
void |
removeFocusListener(org.eclipse.swt.events.FocusListener listener) |
void |
removeKeyListener(org.eclipse.swt.events.KeyListener listener) |
void |
removeMouseListener(org.eclipse.swt.events.MouseListener listener) |
void |
removeSelectionListener(org.eclipse.swt.events.SelectionListener listener) |
void |
removeShellListener(org.eclipse.swt.events.ShellListener listener) |
void |
removeTextControlListener(org.eclipse.swt.events.ControlListener listener) |
void |
removeTraverseListener(org.eclipse.swt.events.TraverseListener listener) |
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.
|
protected void |
setDropdownSelection(String[] selection)
Transforms the given String array whose contents represents selected
items to a selection that can be handled by the underlying Table control
in the dropdown.
|
void |
setItems(String[] items)
Sets the given items to be the items shown in the dropdown of this
NatCombo.
|
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 |
setSelection(String[] items)
Selects the items at the given zero-relative indices in the receiver.
|
void |
showDropdownControl()
Shows the dropdown of this NatCombo.
|
void |
showDropdownControl(boolean focusOnText)
Shows the dropdown of this NatCombo.
|
protected void |
updateTextControl(boolean hideDropdown)
This method will be called if an item of the dropdown control is selected
via mouse click or pressing enter.
|
changed, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabListcomputeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBaraddControlListener, addDragDetectListener, addGestureListener, addHelpListener, addMenuDetectListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, computeSize, computeSize, dragDetect, dragDetect, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getRegion, getShell, getSize, getTextDirection, getToolTipText, getTouchEnabled, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeGestureListener, removeHelpListener, removeMenuDetectListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, requestLayout, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setFont, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setRegion, setSize, setSize, setTextDirection, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, updateaddDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isAutoDirection, isDisposed, isListening, removeDisposeListener, removeListener, removeListener, reskin, setData, setData, toStringpublic static final String DEFAULT_MULTI_SELECT_VALUE_SEPARATOR
public static final String DEFAULT_MULTI_SELECT_PREFIX
public static final String DEFAULT_MULTI_SELECT_SUFFIX
public static final int DEFAULT_NUM_OF_VISIBLE_ITEMS
protected final IStyle cellStyle
protected int maxVisibleItems
protected List<String> itemList
protected Map<String,Boolean> selectionStateMap
protected org.eclipse.swt.widgets.Text filterBox
protected org.eclipse.swt.widgets.Text text
protected org.eclipse.swt.widgets.Shell dropdownShell
protected org.eclipse.swt.widgets.Table dropdownTable
protected org.eclipse.jface.viewers.TableViewer dropdownTableViewer
protected org.eclipse.swt.graphics.Image iconImage
protected final int style
protected boolean showDropdownFilter
protected boolean freeEdit
protected boolean multiselect
protected boolean useCheckbox
protected String multiselectValueSeparator
protected String multiselectTextPrefix
protected String multiselectTextSuffix
public NatCombo(org.eclipse.swt.widgets.Composite parent,
IStyle cellStyle,
int style)
parent - A widget that will be the parent of this NatCombocellStyle - Style configuration containing horizontal alignment, font,
foreground and background color information.style - The style for the Text Control to construct. Uses this style
adding internal styles via ConfigRegistry.public NatCombo(org.eclipse.swt.widgets.Composite parent,
IStyle cellStyle,
int maxVisibleItems,
int style)
parent - A widget that will be the parent of this NatCombocellStyle - Style configuration containing horizontal alignment, font,
foreground and background color information.maxVisibleItems - the max number of items the drop down will show before
introducing a scroll bar.style - The style for the Text Control to construct. Uses this style
adding internal styles via ConfigRegistry.public NatCombo(org.eclipse.swt.widgets.Composite parent,
IStyle cellStyle,
int maxVisibleItems,
int style,
boolean showDropdownFilter)
parent - A widget that will be the parent of this NatCombocellStyle - Style configuration containing horizontal alignment, font,
foreground and background color information.maxVisibleItems - the max number of items the drop down will show before
introducing a scroll bar.style - The style for the Text Control to construct. Uses this style
adding internal styles via ConfigRegistry.showDropdownFilter - Flag indicating whether the dropdown filter is displayedpublic NatCombo(org.eclipse.swt.widgets.Composite parent,
IStyle cellStyle,
int maxVisibleItems,
int style,
org.eclipse.swt.graphics.Image iconImage)
parent - A widget that will be the parent of this NatCombocellStyle - Style configuration containing horizontal alignment, font,
foreground and background color information.maxVisibleItems - the max number of items the drop down will show before
introducing a scroll bar.style - The style for the Text Control to construct. Uses this
style adding internal styles via ConfigRegistry.iconImage - The image to use as overlay to the Text Control if the
dropdown is visible. Using this image will indicate that the
control is an open combo to the user.public NatCombo(org.eclipse.swt.widgets.Composite parent,
IStyle cellStyle,
int maxVisibleItems,
int style,
org.eclipse.swt.graphics.Image iconImage,
boolean showDropdownFilter)
parent - A widget that will be the parent of this NatCombocellStyle - Style configuration containing horizontal alignment, font,
foreground and background color information.maxVisibleItems - the max number of items the drop down will show before
introducing a scroll bar.style - The style for the Text Control to construct. Uses this
style adding internal styles via ConfigRegistry.iconImage - The image to use as overlay to the Text Control if the
dropdown is visible. Using this image will indicate that the
control is an open combo to the user.showDropdownFilter - Flag indicating whether the dropdown filter is displayedpublic void setItems(String[] items)
items - The array of items to set.protected void createTextControl(int style)
style - The style for the Text Control to construct. Uses this style
adding internal styles via ConfigRegistry.protected void createDropdownControl(int style)
style - The style for the Table Control to construct. Uses this style
adding internal styles via ConfigRegistry.protected void updateTextControl(boolean hideDropdown)
hideDropdown - true if the dropdown should be hidden after
updating the text controlpublic void showDropdownControl()
public void showDropdownControl(boolean focusOnText)
focusOnText - true if the focus should be set to the text
control instead of the dropdown after opening the dropdown.protected org.eclipse.swt.widgets.Table getDropdownTable()
Table control that is used in the dropdown. Will be
created if it does not exist yet.public void hideDropdownControl()
protected int getVisibleItemCount()
protected void calculateBounds()
protected void calculateColumnWidth()
public int getSelectionIndex()
Note that this only returns useful results if this NatCombo supports single selection or only one item is selected.
public int[] getSelectionIndices()
Note: This is not the actual structure used by the receiver to maintain its selection, so modifying the array will not affect the receiver.
public int getSelectionCount()
public String[] getSelection()
Strings that are currently selected in
the receiver. The order of the items is unspecified. An empty array
indicates that no items are selected.
Note: This is not the actual structure used by the receiver to maintain its selection, so modifying the array will not affect the receiver.
public void setSelection(String[] items)
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.
The text control of this NatCombo will also be updated with the new selected values.
items - the items to selectpublic void select(int index)
index - the index of the item to selectpublic void select(int[] indices)
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.
indices - the array of indices for the items to selectprotected void applyDropdownListener()
public void addKeyListener(org.eclipse.swt.events.KeyListener listener)
addKeyListener in class org.eclipse.swt.widgets.Controlpublic void removeKeyListener(org.eclipse.swt.events.KeyListener listener)
removeKeyListener in class org.eclipse.swt.widgets.Controlpublic void addTraverseListener(org.eclipse.swt.events.TraverseListener listener)
addTraverseListener in class org.eclipse.swt.widgets.Controlpublic void removeTraverseListener(org.eclipse.swt.events.TraverseListener listener)
removeTraverseListener in class org.eclipse.swt.widgets.Controlpublic void addMouseListener(org.eclipse.swt.events.MouseListener listener)
addMouseListener in class org.eclipse.swt.widgets.Controlpublic void removeMouseListener(org.eclipse.swt.events.MouseListener listener)
removeMouseListener in class org.eclipse.swt.widgets.Controlpublic void notifyListeners(int eventType,
org.eclipse.swt.widgets.Event event)
notifyListeners in class org.eclipse.swt.widgets.Widgetpublic void addSelectionListener(org.eclipse.swt.events.SelectionListener listener)
public void removeSelectionListener(org.eclipse.swt.events.SelectionListener listener)
public void addShellListener(org.eclipse.swt.events.ShellListener listener)
public void removeShellListener(org.eclipse.swt.events.ShellListener listener)
public void addTextControlListener(org.eclipse.swt.events.ControlListener listener)
public void removeTextControlListener(org.eclipse.swt.events.ControlListener listener)
public boolean isFocusControl()
isFocusControl in class org.eclipse.swt.widgets.Controlpublic boolean forceFocus()
forceFocus in class org.eclipse.swt.widgets.Controlpublic void addFocusListener(org.eclipse.swt.events.FocusListener listener)
addFocusListener in class org.eclipse.swt.widgets.Controlpublic void removeFocusListener(org.eclipse.swt.events.FocusListener listener)
removeFocusListener in class org.eclipse.swt.widgets.Controlprotected String[] getTransformedSelection()
protected void setDropdownSelection(String[] selection)
selection - The Strings that represent the selected itemsprotected String[] getTextAsArray()
Note that by default the multiselect String is specified to show with enclosing [] brackets and values separated by ", ". If you need to change this you need to set the corresponding values in this NatCombo.
protected String getTransformedTextForSelection()
Note that by default the multiselect String is specified to show with enclosing [] brackets and values separated by ", ". If you need to change this you need to set the corresponding values in this NatCombo.
protected String getTransformedText(String[] values)
If this NatCombo is only configured to support single selection, than only the first value in the array will be processed. Otherwise the result will be processed by concatenating the values.
Note that by default the multiselect String is specified to show with enclosing [] brackets and values separated by ", ". If you need to change this you need to set the corresponding values in this NatCombo.
values - The values to build the text representation from.public void setMultiselectValueSeparator(String multiselectValueSeparator)
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.DEFAULT_MULTI_SELECT_VALUE_SEPARATORpublic void setMultiselectTextBracket(String multiselectTextPrefix, String multiselectTextSuffix)
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.DEFAULT_MULTI_SELECT_PREFIX,
DEFAULT_MULTI_SELECT_SUFFIXCopyright © 2019. All rights reserved.