Class MultiChoice<T>
java.lang.Object
org.eclipse.swt.widgets.Widget
org.eclipse.swt.widgets.Control
org.eclipse.swt.widgets.Scrollable
org.eclipse.swt.widgets.Composite
org.eclipse.nebula.widgets.opal.multichoice.MultiChoice<T>
- Type Parameters:
T- Class of objects represented by this widget
- All Implemented Interfaces:
org.eclipse.swt.graphics.Drawable
public class MultiChoice<T>
extends org.eclipse.swt.widgets.Composite
The MultiChoice class represents a selectable user interface object that
combines a read-only text-field and a set of checkboxes.
Note that although this class is a subclass of Composite, it
does not make sense to add children to it, or set a layout on it.
- Styles:
- NONE
- Events:
- Selection
-
Field Summary
-
Constructor Summary
Constructors Constructor Description MultiChoice(org.eclipse.swt.widgets.Composite parent, int style)Constructs a new instance of this class given its parent.MultiChoice(org.eclipse.swt.widgets.Composite parent, int style, java.util.List<T> elements)Constructs a new instance of this class given its parent. -
Method Summary
Modifier and Type Method Description voidadd(T value)Adds the argument to the end of the receiver's list.voidadd(T value, int index)Adds the argument to the receiver's list at the given zero-relative index.voidaddAll(java.util.List<T> values)Adds the argument to the end of the receiver's list.voidaddAll(T[] values)Adds the argument to the end of the receiver's list.org.eclipse.swt.graphics.PointcomputeSize(int wHint, int hHint, boolean changed)voiddeselect(T value)Deselects the item in the receiver's list.voiddeselectAll()Deselects all items in the receiver's list.voiddeselectAt(int index)Deselects the item at the given zero-relative index in the receiver's list.org.eclipse.swt.widgets.ButtongetArrowButton()org.eclipse.swt.graphics.ColorgetBackground()booleangetEditable()Returns the editable state.org.eclipse.swt.graphics.FontgetFont()org.eclipse.swt.graphics.ColorgetForeground()TgetItem(int index)Returns the item at the given, zero-relative index in the receiver's list.intgetItemCount()Returns the number of items contained in the receiver's list.java.util.List<T>getItems()Returns the list of items in the receiver's list.(package private) TgetLastModified()intgetNumberOfColumns()(package private) org.eclipse.swt.widgets.ShellgetPopup()java.util.Set<T>getSelected()int[]getSelectedIndex()Returns the zero-relative indices of the items which are currently selected in the receiver.java.util.List<T>getSelection()Returns an array ofObjects that are currently selected in the receiver.org.eclipse.swt.events.SelectionListenergetSelectionListener()java.lang.StringgetSeparator()java.lang.StringgetText()org.eclipse.swt.widgets.TextgetTextControl()booleanisShowSelectUnselectAll()voidrefresh()Refresh the widget (after the add of a new element for example)voidremove(T object)Searches the receiver's list starting at the first item until an item is found that is equal to the argument, and removes that item from the list.voidremoveAll()Remove all items of the receivervoidremoveAt(int index)Removes the item from the receiver's list at the given zero-relative index.voidselect(T value)Selects an item the receiver's list.voidselectAll()Selects all selected items in the receiver's list.voidselectAt(int index)Selects the item at the given zero-relative index in the receiver's list.voidsetBackground(org.eclipse.swt.graphics.Color background)voidsetEditable(boolean editable)Sets the editable state.voidsetEnabled(boolean enabled)voidsetFont(org.eclipse.swt.graphics.Font font)voidsetForeground(org.eclipse.swt.graphics.Color foreground)voidsetLabelProvider(MultiChoiceLabelProvider labelProvider)voidsetNumberOfColumns(int numberOfColumns)voidsetSelected(java.util.Set<T> selection)voidsetSelectedIndex(int[] index)Selects items in the receiver.voidsetSelection(java.util.Set<T> selection)Sets the selection of the receiver.voidsetSelectionListener(MultiChoiceSelectionListener<T> selectionListener)voidsetSeparator(java.lang.String separator)voidsetShowSelectUnselectAll(boolean showSelectUnselectAll)voidsetText(java.lang.String textValue)Fill the text box.voidsetToolTipText(java.lang.String txt)voidupdateSelection()Update the selectionprotected voidvalidateEntry()Methods inherited from class org.eclipse.swt.widgets.Composite
changed, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList, toStringMethods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBarMethods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getRegion, getShell, getSize, getTextDirection, getToolTipText, getTouchEnabled, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, removeTraverseListener, requestLayout, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setRegion, setSize, setSize, setTextDirection, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, updateMethods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isAutoDirection, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, setData
-
Constructor Details
-
MultiChoice
public MultiChoice(org.eclipse.swt.widgets.Composite parent, int style)Constructs a new instance of this class given its parent.- Parameters:
parent- a widget which will be the parent of the new instance (cannot be null)style- not used- Throws:
java.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the parent is null
org.eclipse.swt.SWTException-- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
-
MultiChoice
public MultiChoice(org.eclipse.swt.widgets.Composite parent, int style, java.util.List<T> elements)Constructs a new instance of this class given its parent.- Parameters:
parent- a widget which will be the parent of the new instance (cannot be null)style- not usedelements- list of elements displayed by this widget- Throws:
java.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the parent is null
org.eclipse.swt.SWTException-- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
-
-
Method Details
-
validateEntry
protected void validateEntry() -
add
Adds the argument to the end of the receiver's list.- Parameters:
values- new item- Throws:
java.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the string is null
org.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
add
Adds the argument to the receiver's list at the given zero-relative index.- Parameters:
values- new itemindex- the index for the item- Throws:
java.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the string is null
- ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
org.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
addAll
Adds the argument to the end of the receiver's list.- Parameters:
values- new items- Throws:
java.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the string is null
org.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
addAll
Adds the argument to the end of the receiver's list.- Parameters:
values- new items- Throws:
java.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the string is null
org.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getEditable
public boolean getEditable()Returns the editable state.- Returns:
- whether or not the receiver is editable
- Throws:
org.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getItem
Returns the item at the given, zero-relative index in the receiver's list. Throws an exception if the index is out of range.- Parameters:
index- the index of the item to return- Returns:
- the item at the given index
- Throws:
java.lang.NullPointerException- if there is no item in the receiverjava.lang.IllegalArgumentException-- ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
org.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getItemCount
public int getItemCount()Returns the number of items contained in the receiver's list.- Returns:
- the number of items
- Throws:
org.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getItems
Returns the list of items in the receiver's list.Note: This is not the actual structure used by the receiver to maintain its list of items, so modifying the array will not affect the receiver.
- Returns:
- the items in the receiver's list
- Throws:
org.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
removeAt
public void removeAt(int index)Removes the item from the receiver's list at the given zero-relative index.- Parameters:
index- the index for the item- Throws:
java.lang.NullPointerException- if there is no item in the receiverjava.lang.IllegalArgumentException-- ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
org.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
remove
Searches the receiver's list starting at the first item until an item is found that is equal to the argument, and removes that item from the list.- Parameters:
object- the item to remove- Throws:
java.lang.NullPointerException- if there is no item in the receiverjava.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the object is null
org.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
removeAll
public void removeAll()Remove all items of the receiver- Throws:
org.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setLabelProvider
- Parameters:
labelProvider- the Label Provider to set
-
setSelection
Sets the selection of the receiver. If the item was already selected, it remains selected.- Parameters:
selection- the new selection- Throws:
java.lang.NullPointerException- if there is no item in the receiverjava.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the selection is null
org.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
selectAll
public void selectAll()Selects all selected items in the receiver's list.- Throws:
java.lang.NullPointerException- if there is no item in the receiverorg.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
selectAt
public void selectAt(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.- Parameters:
index- the index of the item to select- Throws:
java.lang.NullPointerException- if there is no item in the receiverjava.lang.IllegalArgumentException-- ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
org.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
select
Selects an item the receiver's list. If the item was already selected, it remains selected.- Parameters:
index- the index of the item to select- Throws:
java.lang.NullPointerException- if there is no item in the receiverjava.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the selection is null
org.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setSelectedIndex
public void setSelectedIndex(int[] index)Selects items in the receiver. If the items were already selected, they remain selected.- Parameters:
index- the indexes of the items to select- Throws:
java.lang.NullPointerException- if there is no item in the receiverjava.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the selection is null
- ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
org.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getSelectedIndex
public int[] getSelectedIndex()Returns the zero-relative indices of the items which are currently selected in the receiver. The order of the indices is unspecified. The array is empty if 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.
- Returns:
- the array of indices of the selected items
- Throws:
java.lang.NullPointerException- if there is no item in the receiverorg.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getSelection
Returns an array ofObjects 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.
- Returns:
- an array representing the selection
- Throws:
java.lang.NullPointerException- if there is no item in the receiverorg.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
deselectAt
public void deselectAt(int index)Deselects the item at the given zero-relative index in the receiver's list. If the item at the index was already deselected, it remains deselected. Indices that are out of range are ignored.- Parameters:
index- the index of the item to deselect- Throws:
java.lang.NullPointerException- if there is no item in the receiverjava.lang.IllegalArgumentException-- ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
org.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
deselect
Deselects the item in the receiver's list. If the item at the index was already deselected, it remains deselected.- Parameters:
value- the item to deselect- Throws:
java.lang.NullPointerException- if there is no item in the receiverjava.lang.IllegalArgumentException-- ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
org.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
deselectAll
public void deselectAll()Deselects all items in the receiver's list.- Parameters:
value- the item to deselect- Throws:
java.lang.NullPointerException- if there is no item in the receiverorg.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getNumberOfColumns
public int getNumberOfColumns()- Returns:
- the number of columns
-
setNumberOfColumns
public void setNumberOfColumns(int numberOfColumns)- Parameters:
numberOfColumns- the number of columns
-
getSeparator
public java.lang.String getSeparator()- Returns:
- the separator used in the text field. Default value is ","
-
setSeparator
public void setSeparator(java.lang.String separator)- Parameters:
separator- the new value of the separator
-
getForeground
public org.eclipse.swt.graphics.Color getForeground()- Overrides:
getForegroundin classorg.eclipse.swt.widgets.Control- See Also:
Control.getForeground()
-
setForeground
public void setForeground(org.eclipse.swt.graphics.Color foreground)- Overrides:
setForegroundin classorg.eclipse.swt.widgets.Control- See Also:
Control.setForeground(org.eclipse.swt.graphics.Color)
-
getBackground
public org.eclipse.swt.graphics.Color getBackground()- Overrides:
getBackgroundin classorg.eclipse.swt.widgets.Control- See Also:
Control.getBackground()
-
setBackground
public void setBackground(org.eclipse.swt.graphics.Color background)- Overrides:
setBackgroundin classorg.eclipse.swt.widgets.Control- See Also:
Control.setBackground(org.eclipse.swt.graphics.Color)
-
getFont
public org.eclipse.swt.graphics.Font getFont()- Overrides:
getFontin classorg.eclipse.swt.widgets.Control- See Also:
Control.getFont()
-
setFont
public void setFont(org.eclipse.swt.graphics.Font font)- Overrides:
setFontin classorg.eclipse.swt.widgets.Control- See Also:
Control.setFont(org.eclipse.swt.graphics.Font)
-
refresh
public void refresh()Refresh the widget (after the add of a new element for example) -
computeSize
public org.eclipse.swt.graphics.Point computeSize(int wHint, int hHint, boolean changed)- Overrides:
computeSizein classorg.eclipse.swt.widgets.Control- See Also:
Control.computeSize(int, int, boolean)
-
setEnabled
public void setEnabled(boolean enabled)- Overrides:
setEnabledin classorg.eclipse.swt.widgets.Control- See Also:
Control.setEnabled(boolean)
-
setEditable
public void setEditable(boolean editable)Sets the editable state.- Parameters:
editable- the new editable state- Throws:
org.eclipse.swt.SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setToolTipText
public void setToolTipText(java.lang.String txt)- Overrides:
setToolTipTextin classorg.eclipse.swt.widgets.Control- See Also:
Control.setToolTipText(java.lang.String)
-
getSelectionListener
public org.eclipse.swt.events.SelectionListener getSelectionListener()- Returns:
- the selection listener
-
setSelectionListener
- Parameters:
selectionListener- the new selection listener
-
updateSelection
public void updateSelection()Update the selection -
getLastModified
T getLastModified()- Returns:
- the last modified item
-
getPopup
org.eclipse.swt.widgets.Shell getPopup()- Returns:
- the popup
-
setText
public void setText(java.lang.String textValue)Fill the text box. Please notice that the setted element MAY not be in the items list.
For instance, your widget contains a list of european countries. If you use setText("USA"), the text will display "USA", butgetSelection()will return and empty text. To retrieve "USA", you have to use the method getText();- Parameters:
textValue- new text value
-
getText
public java.lang.String getText()- Returns:
- the display value as text
-
isShowSelectUnselectAll
public boolean isShowSelectUnselectAll()- Returns:
trueif the hyperlinks "Select all" and "Deselect all" are displayted
-
setShowSelectUnselectAll
public void setShowSelectUnselectAll(boolean showSelectUnselectAll)- Parameters:
showSelectUnselectAll- set to "true" to display the hyperlinks "Select all" and "Deselect all"
-
setSelected
- Parameters:
selection- elements to select
-
getSelected
- Returns:
- selected elements
-
getTextControl
public org.eclipse.swt.widgets.Text getTextControl()- Returns:
- text control
-
getArrowButton
public org.eclipse.swt.widgets.Button getArrowButton()- Returns:
- the arrow button
-