org.eclipse.ercp.swt.mobile
Class SortedList

java.lang.Object
  extended by org.eclipse.swt.widgets.Widget
      extended by org.eclipse.swt.widgets.Control
          extended by org.eclipse.swt.widgets.Scrollable
              extended by org.eclipse.ercp.swt.mobile.SortedList
All Implemented Interfaces:
Drawable

public class SortedList
extends Scrollable

Instances of this class represent a selectable user interface object that displays a sorted list of text items. The items may be displayed in ascending or descending order. The sorting algorithm is platform and locale dependent.

If the FILTER style is specified during construction, an associated label is also displayed showing characters entered which are then used to filter the list to show fewer items. The selection state of items filtered out of the list is cleared.

IMPORTANT: This class is not intended to be subclassed.

Styles:
SINGLE, MULTI, UP, DOWN

Note: Only one of SINGLE and MULTI may be specified. Only one of UP and DOWN may be specified.

Mode Styles:
FILTER

Events:
Selection, DefaultSelection


Field Summary
static int FILTER
          constructor style specifying filter field should be displayed
 boolean hasFilter
           
 
Fields inherited from class org.eclipse.swt.widgets.Control
internal_parent
 
Fields inherited from class org.eclipse.swt.widgets.Widget
internal_handle, internal_style
 
Constructor Summary
SortedList(Composite parent, int style)
           
SortedList(Composite parent, int style, int modeStyle)
          Construct a new instance of this class given its parent, a style value describing its behavior and appearance, and a mode style describing additional behavior modes.
 
Method Summary
 void add(java.lang.String item)
          Adds the argument to the receiver's list of items.
 void addSelectionListener(SelectionListener listener)
          Adds the listener to the collection of listeners who will be notified when the receiver's selection changes, by sending it one of the messages defined in the SelectionListener interface.
 boolean allowTraverseByArrowKey(Event event)
           
 Point computeSize(int wHint, int hHint, boolean changed)
          Returns the prefered size of the receiver.
 void dispose()
          Disposes of the operating system resources associated with the receiver and all its descendents.
 boolean forceFocus()
          Forces the receiver to have the keyboard focus, causing all keyboard events to be delivered to it.
 Rectangle getBounds()
          Returns a rectangle describing the receiver's size and location relative to its parent (or its display if its parent is null), unless the receiver is a shell.
protected  Control getchild()
           
 java.lang.String getFocus()
          Returns the text of the item currently focused in the receiver, or null if no item has focus.
 Font getFont()
          Returns the font that the receiver will use to paint textual information.
 int getItemHeight()
          Returns the height (in pixels) of the area which would be used to display one of the items in the tree.
 Point getLocation()
          Returns a point describing the receiver's location relative to its parent (or its display if its parent is null), unless the receiver is a shell.
 java.lang.String[] getSelection()
          Returns an array of Strings of items that are currently selected in the receiver.
 int getSelectionCount()
          Returns the number of items currently selected.
 Point getSize()
          Returns a point describing the receiver's size.
 void internal_createHandle(int index)
           
 boolean isDisposed()
          Returns true if the widget has been disposed, and false otherwise.
 boolean isEnableTraverse()
           
 boolean isFocusControl()
          Returns true if the receiver has the user-interface focus, and false otherwise.
 void pack()
          Causes the receiver to be resized to its preferred size.
 void remove(java.lang.String item)
          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.
 void removeAll()
          Removes all of the items from the receiver.
 void removeSelectionListener(SelectionListener listener)
          Removes the listener from the collection of listeners who are notified when the receiver's selection changes.
 void select(java.lang.String item)
          Selects the first item that has text matching the given string.
 void setBounds(int x, int y, int width, int height)
          Sets the receiver's size and location to the rectangular area specified by the arguments.
 void setBounds(Rectangle rect)
          Sets the receiver's size and location to the rectangular area specified by the argument.
 boolean setFocus()
          Causes the receiver to have the keyboard focus, such that all keyboard events will be delivered to it.
 void setFont(Font font)
          Sets the font that the receiver will use to paint textual information to the font specified by the argument, or to the default font for that kind of control if the argument is null.
 void setItems(java.lang.String[] items)
          Sets the receiver's items to be the given array of items.
 void setLocation(int x, int y)
          Sets the receiver's location to the point specified by the arguments which are relative to the receiver's parent (or its display if its parent is null), unless the receiver is a shell.
 void setLocation(Point location)
          Sets the receiver's location to the point specified by the arguments which are relative to the receiver's parent (or its display if its parent is null), unless the receiver is a shell.
 void setSelection(java.lang.String[] items)
          Sets the receiver's selection to be the given array of items.
 void setSize(int width, int height)
          Sets the receiver's size to the point specified by the arguments.
 void setSize(Point size)
          Sets the receiver's size to the point specified by the argument.
 void showSelection()
          Scrolls the list as necessary to show the selected items.
protected  boolean traverse(Event event)
           
 
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getVerticalBar, internal_getNativeStyle
 
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addFocusListener, addKeyListener, addMouseListener, addMouseMoveListener, addPaintListener, addTraverseListener, computeSize, getBackground, getBorderWidth, getEnabled, getForeground, getLayoutData, getMenu, getParent, getShell, getToolTipText, getVisible, internal_copyArea, internal_dispose_GC, internal_getBounds, internal_getDefaultClipping, internal_new_GC, isEnabled, isReparentable, isVisible, moveAbove, moveBelow, pack, redraw, redraw, removeControlListener, removeFocusListener, removeKeyListener, removeMouseListener, removeMouseMoveListener, removePaintListener, removeTraverseListener, setBackground, setCapture, setEnabled, setForeground, setLayoutData, setMenu, setParent, setRedraw, setToolTipText, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverseByArrowKey, traverseGroup, update
 
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkSubclass, checkWidget, getData, getData, getDisplay, getStyle, internal_sendEvent, isListening, notifyListeners, removeDisposeListener, removeInternalFilter, removeListener, removeListener, sendEvent, setData, setData, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FILTER

public static final int FILTER
constructor style specifying filter field should be displayed

See Also:
Constant Field Values

hasFilter

public boolean hasFilter
Constructor Detail

SortedList

public SortedList(Composite parent,
                  int style)

SortedList

public SortedList(Composite parent,
                  int style,
                  int modeStyle)
Construct a new instance of this class given its parent, a style value describing its behavior and appearance, and a mode style describing additional behavior modes.

The style value is either one of the style constants defined in class SWT which is applicable to instances of this class, or must be built by bitwise OR 'ing together (that is, using the int "|" operator) two or more of those SWT style constants. Style bits are also inherited from superclasses. SWT.UP (the default) means the list is sorted in dictionary order from top to bottom (i.e. A, B, C, ...). SWT.DOWN means the list is sorted in reverse dictionary order from top to bottom (i.e. Z, Y, X, ...). The modeStyle may specify the class constant FILTER. This style adds a text entry field to the widget which does not receive focus, but will display characters entered while the list has focus. These characters are used to filter the list items so that fewer items are displayed in the list. The selection is cleared for any items not shown as a result of filtering.

Parameters:
parent - a composite control which will be the parent of the new instance (cannot be null)
style - the style of the control
modeStyle - the mode for the control
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the parent is null
SWTException -
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
See Also:
SWT.SINGLE, SWT.MULTI, SWT.UP, SWT.DOWN, FILTER
Method Detail

isDisposed

public boolean isDisposed()
Description copied from class: Widget
Returns true if the widget has been disposed, and false otherwise.

This method gets the dispose state for the widget. When a widget has been disposed, it is an error to invoke any other method using the widget.

Overrides:
isDisposed in class Widget
Returns:
true when the widget is disposed and false otherwise

dispose

public void dispose()
Description copied from class: Widget
Disposes of the operating system resources associated with the receiver and all its descendents. After this method has been invoked, the receiver and all descendents will answer true when sent the message isDisposed(). Any internal connections between the widgets in the tree will have been removed to facilitate garbage collection.

NOTE: This method is not called recursively on the descendents of the receiver. This means that, widget implementers can not detect when a widget is being disposed of by re-implementing this method, but should instead listen for the Dispose event.

Overrides:
dispose in class Control
See Also:
Widget.addDisposeListener(org.eclipse.swt.events.DisposeListener), Widget.removeDisposeListener(org.eclipse.swt.events.DisposeListener), Widget.checkWidget()

forceFocus

public boolean forceFocus()
Description copied from class: Control
Forces the receiver to have the keyboard focus, causing all keyboard events to be delivered to it.

Overrides:
forceFocus in class Control
Returns:
true if the control got focus, and false if it was unable to.
See Also:
Control.setFocus()

add

public void add(java.lang.String item)
Adds the argument to the receiver's list of items.

Parameters:
item - text to be added to the list
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the item is null
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
SWTError -
  • ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure
See Also:
setItems(String[]), remove(java.lang.String), removeAll()

addSelectionListener

public void addSelectionListener(SelectionListener listener)
Adds the listener to the collection of listeners who will be notified when the receiver's selection changes, by sending it one of the messages defined in the SelectionListener interface.

widgetSelected is called when the selection changes.
widgetDefaultSelected is typically called when selection is finalized.

Parameters:
listener - instance called when selection events occur
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
SWTError -
  • ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure
See Also:
ListBox.removeSelectionListener(org.eclipse.swt.events.SelectionListener), SelectionListener

computeSize

public Point computeSize(int wHint,
                         int hHint,
                         boolean changed)
Returns the prefered size of the receiver.

Description copied from class: Control

The preferred size of a control is the size that it would be best displayed at. The width hint and height hint arguments allow the caller to ask a control questions such as "Given a particular width, how high does the control need to be to show all of the contents?" To indicate that the caller does not wish to constrain a particular dimension, the constant SWT.DEFAULT is passed for the hint.

If the changed flag is true, it indicates that the receiver's contents have changed, therefore any caches that a layout manager containing the control may have been keeping need to be flushed. When the control is resized, the changed flag will be false, so layout manager caches can be retained.

Overrides: computeSize in class Control

Overrides:
computeSize in class Scrollable
Parameters:
wHint - the width hint (can be SWT.DEFAULT)
hHint - the height hint (can be SWT.DEFAULT)
changed - true if the control's contents have changed, and false otherwise
Returns:
the preferred size of the control
See Also:
Layout, Control.getBorderWidth(), Control.getBounds(), Control.getSize(), Control.pack(boolean), "computeTrim, getClientArea for controls that implement them"

getFocus

public java.lang.String getFocus()
Returns the text of the item currently focused in the receiver, or null if no item has focus.

Returns:
the text of the item with focus
Throws:
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent

getItemHeight

public int getItemHeight()
Returns the height (in pixels) of the area which would be used to display one of the items in the tree.

Returns:
height in pixels
Throws:
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
SWTError -
  • ERROR_CANNOT_GET_HEIGHT - if the operation fails because of an operating system failure

getSelection

public java.lang.String[] getSelection()
Returns an array of Strings of items that are currently selected in the receiver.

Returns:
array of selected items
Throws:
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
SWTError -
  • ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure
See Also:
getSelectionCount()

getSelectionCount

public int getSelectionCount()
Returns the number of items currently selected.

Returns:
count of selected items
Throws:
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
SWTError -
  • ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure
See Also:
getSelection()

remove

public void remove(java.lang.String item)
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:
item - text of item to remove
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the string is null
  • ERROR_INVALID_ARGUMENT - if the string is not found in the list
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
SWTError -
  • ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure
See Also:
add(String), removeAll()

removeAll

public void removeAll()
Removes all of the items from the receiver.

Throws:
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
java.lang.IllegalArgumentException -
  • ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure
See Also:
add(String), remove(String), setItems(String[])

removeSelectionListener

public void removeSelectionListener(SelectionListener listener)
Removes the listener from the collection of listeners who are notified when the receiver's selection changes.

Parameters:
listener - instance called when selection events occur
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
SWTError -
  • ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure
See Also:
addSelectionListener(org.eclipse.swt.events.SelectionListener), SelectionListener

select

public void select(java.lang.String item)
Selects the first item that has text matching the given string. If the argument is null, the selection is cleared.

Parameters:
item - text of item to select
Throws:
java.lang.IllegalArgumentException -
  • ERROR_INVALID_ARGUMENT - if the string is not found in the list
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent

setItems

public void setItems(java.lang.String[] items)
Sets the receiver's items to be the given array of items.

Parameters:
items - array of text strings to be shown in list
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the string array is null
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
SWTError -
  • ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure
See Also:
add(java.lang.String)

setSelection

public void setSelection(java.lang.String[] items)
Sets the receiver's selection to be the given array of items.

Parameters:
items - array of text strings to be selected in list
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the string array is null
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
See Also:
select(java.lang.String)

showSelection

public void showSelection()
Scrolls the list as necessary to show the selected items.

Throws:
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
See Also:
select(java.lang.String), setSelection(java.lang.String[])

internal_createHandle

public void internal_createHandle(int index)
Overrides:
internal_createHandle in class Widget

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
Description copied from class: Control
Sets the receiver's size and location to the rectangular area specified by the arguments. The x and y arguments are relative to the receiver's parent (or its display if its parent is null), unless the receiver is a shell. In this case, the x and y arguments are relative to the display.

Note: Attempting to set the width or height of the receiver to a negative number will cause that value to be set to zero instead.

Overrides:
setBounds in class Control
Parameters:
x - the new x coordinate for the receiver
y - the new y coordinate for the receiver
width - the new width for the receiver
height - the new height for the receiver

setBounds

public void setBounds(Rectangle rect)
Description copied from class: Control
Sets the receiver's size and location to the rectangular area specified by the argument. The x and y fields of the rectangle are relative to the receiver's parent (or its display if its parent is null).

Note: Attempting to set the width or height of the receiver to a negative number will cause that value to be set to zero instead.

Overrides:
setBounds in class Control
Parameters:
rect - the new bounds for the receiver

setLocation

public void setLocation(int x,
                        int y)
Description copied from class: Control
Sets the receiver's location to the point specified by the arguments which are relative to the receiver's parent (or its display if its parent is null), unless the receiver is a shell. In this case, the point is relative to the display.

Overrides:
setLocation in class Control
Parameters:
x - the new x coordinate for the receiver
y - the new y coordinate for the receiver

setLocation

public void setLocation(Point location)
Description copied from class: Control
Sets the receiver's location to the point specified by the arguments which are relative to the receiver's parent (or its display if its parent is null), unless the receiver is a shell. In this case, the point is relative to the display.

Overrides:
setLocation in class Control
Parameters:
location - the new location for the receiver

setSize

public void setSize(int width,
                    int height)
Description copied from class: Control
Sets the receiver's size to the point specified by the arguments.

Note: Attempting to set the width or height of the receiver to a negative number will cause that value to be set to zero instead.

Overrides:
setSize in class Control
Parameters:
width - the new width for the receiver
height - the new height for the receiver

pack

public void pack()
Description copied from class: Control
Causes the receiver to be resized to its preferred size. For a composite, this involves computing the preferred size from its layout, if there is one.

Overrides:
pack in class Control
See Also:
Control.computeSize(int, int, boolean)

setSize

public void setSize(Point size)
Description copied from class: Control
Sets the receiver's size to the point specified by the argument.

Note: Attempting to set the width or height of the receiver to a negative number will cause them to be set to zero instead.

Overrides:
setSize in class Control
Parameters:
size - the new size for the receiver

getBounds

public Rectangle getBounds()
Description copied from class: Control
Returns a rectangle describing the receiver's size and location relative to its parent (or its display if its parent is null), unless the receiver is a shell. In this case, the location is relative to the display.

Overrides:
getBounds in class Control
Returns:
the receiver's bounding rectangle

getLocation

public Point getLocation()
Description copied from class: Control
Returns a point describing the receiver's location relative to its parent (or its display if its parent is null), unless the receiver is a shell. In this case, the point is relative to the display.

Overrides:
getLocation in class Control
Returns:
the receiver's location

getSize

public Point getSize()
Description copied from class: Control
Returns a point describing the receiver's size. The x coordinate of the result is the width of the receiver. The y coordinate of the result is the height of the receiver.

Overrides:
getSize in class Control
Returns:
the receiver's size

setFocus

public boolean setFocus()
Description copied from class: Control
Causes the receiver to have the keyboard focus, such that all keyboard events will be delivered to it. Focus reassignment will respect applicable platform constraints.

Overrides:
setFocus in class Control
Returns:
true if the control got focus, and false if it was unable to.
See Also:
Control.forceFocus()

getchild

protected Control getchild()

setFont

public void setFont(Font font)
Description copied from class: Control
Sets the font that the receiver will use to paint textual information to the font specified by the argument, or to the default font for that kind of control if the argument is null.

Overrides:
setFont in class Control
Parameters:
font - the new font (or null)

getFont

public Font getFont()
Description copied from class: Control
Returns the font that the receiver will use to paint textual information.

Overrides:
getFont in class Control
Returns:
the receiver's font

isFocusControl

public boolean isFocusControl()
Description copied from class: Control
Returns true if the receiver has the user-interface focus, and false otherwise.

Overrides:
isFocusControl in class Control
Returns:
the receiver's focus state

isEnableTraverse

public boolean isEnableTraverse()
Overrides:
isEnableTraverse in class Control

allowTraverseByArrowKey

public boolean allowTraverseByArrowKey(Event event)
Overrides:
allowTraverseByArrowKey in class Control

traverse

protected boolean traverse(Event event)
Overrides:
traverse in class Control