Class Tree
The item children that may be added to instances of this class must be of
type TreeItem
.
Style VIRTUAL
is used to create a Tree
whose
TreeItem
s are to be populated by the client on an on-demand
basis instead of up-front. This can provide significant performance
improvements for trees that are very large or for which TreeItem
population is expensive (for example, retrieving values from an external
source).
Here is an example of using a Tree
with style
VIRTUAL
:
final Tree tree = new Tree(parent, SWT.VIRTUAL | SWT.BORDER);
tree.setItemCount(20);
tree.addListener(SWT.SetData, new Listener() {
public void handleEvent(Event event) {
TreeItem item = (TreeItem)event.item;
TreeItem parentItem = item.getParentItem();
String text = null;
if (parentItem == null) {
text = "node " + tree.indexOf(item);
} else {
text = parentItem.getText() + " - " + parentItem.indexOf(item);
}
item.setText(text);
System.out.println(text);
item.setItemCount(10);
}
});
Note that although this class is a subclass of Composite
, it
does not make sense to add Control
children to it, or set a
layout on it.
- Styles:
- SINGLE, MULTI, CHECK, FULL_SELECTION, VIRTUAL, NO_SCROLL
- Events:
- Selection, DefaultSelection, Collapse, Expand, SetData
Note: Only one of the styles SINGLE and MULTI may be specified.
IMPORTANT: This class is not intended to be subclassed.
- Since:
- 1.0
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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 theSelectionListener
interface.void
addTreeListener
(TreeListener listener) Adds the listener to the collection of listeners who will be notified when an item in the receiver is expanded or collapsed by sending it one of the messages defined in theTreeListener
interface.void
Clears any data that has been cached by a Layout for all widgets that are in the parent hierarchy of the changed control up to and including the receiver.void
clear
(int index, boolean recursive) Clears the item at the given zero-relative index in the receiver.void
clearAll
(boolean recursive) Clears all the items in the receiver.computeSize
(int wHint, int hHint, boolean changed) Returns the preferred size of the receiver.void
Deselects an item in the receiver.void
Deselects all selected items in the receiver.<T> T
getAdapter
(Class<T> adapter) Implementation of theAdaptable
interface.getColumn
(int index) Returns the column at the given, zero-relative index in the receiver.int
Returns the number of columns contained in the receiver.int[]
Returns an array of zero-relative integers that map the creation order of the receiver's items to the order in which they are currently being displayed.Returns an array ofTreeColumn
s which are the columns in the receiver.int
Returns the width in pixels of a grid line.Returns the header background color.Returns the header foreground color.int
Returns the height of the receiver's headerboolean
Returnstrue
if the receiver's header is visible, andfalse
otherwise.getItem
(int index) Returns the item at the given, zero-relative index in the receiver.Returns the item at the given point in the receiver or null if no such item exists.int
Returns the number of items contained in the receiver that are direct item children of the receiver.int
Returns the height of the area which would be used to display one of the items in the tree.TreeItem[]
getItems()
Returns a (possibly empty) array of items contained in the receiver that are direct item children of the receiver.boolean
Returnstrue
if the receiver's lines are visible, andfalse
otherwise.Returns the receiver's parent item, which must be aTreeItem
or null when the receiver is a root.TreeItem[]
Returns an array ofTreeItem
s that are currently selected in the receiver.int
Returns the number of selected items contained in the receiver.Returns the column which shows the sort indicator for the receiver.int
Returns the direction of the sort indicator for the receiver.Returns the item which is currently at the top of the receiver.int
indexOf
(TreeColumn column) Searches the receiver's list starting at the first column (index 0) until a column is found that is equal to the argument, and returns the index of that column.int
Searches the receiver's list starting at the first item (index 0) until an item is found that is equal to the argument, and returns the index of that item.void
Removes all of the items from the receiver.void
removeSelectionListener
(SelectionListener listener) Removes the listener from the collection of listeners who will be notified when the receiver's selection changes.void
removeTreeListener
(TreeListener listener) Removes the listener from the collection of listeners who will be notified when items in the receiver are expanded or collapsed.void
Selects an item in the receiver.void
Selects all of the items in the receiver.void
setColumnOrder
(int[] order) Sets the order that the items in the receiver should be displayed in to the given argument which is described in terms of the zero-relative ordering of when the items were added.void
Sets the application defined property of the receiver with the specified name to the given value.void
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
setHeaderBackground
(Color color) Sets the header background color to the color specified by the argument, or to the default system color if the argument is null.void
setHeaderForeground
(Color color) Sets the header foreground color to the color specified by the argument, or to the default system color if the argument is null.void
setHeaderVisible
(boolean value) Marks the receiver's header as visible if the argument istrue
, and marks it invisible otherwise.void
setItemCount
(int count) Sets the number of root-level items contained in the receiver.void
setLinesVisible
(boolean value) Marks the receiver's lines as visible if the argument istrue
, and marks it invisible otherwise.void
setSelection
(TreeItem selection) Sets the receiver's selection to the given item.void
setSelection
(TreeItem[] selection) Sets the receiver's selection to be the given array of items.void
setSortColumn
(TreeColumn column) Sets the column used by the sort indicator for the receiver.void
setSortDirection
(int direction) Sets the direction of the sort indicator for the receiver.void
setTopItem
(TreeItem item) Sets the item which is currently at the top of the receiver.void
showColumn
(TreeColumn column) Shows the column.void
Shows the item.void
Shows the selection.Methods inherited from class org.eclipse.swt.widgets.Composite
getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getVerticalBar
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addTouchListener, addTraverseListener, computeSize, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getShell, getSize, getToolTipText, getTouchEnabled, getVisible, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeTouchListener, removeTraverseListener, requestLayout, setBackground, setBackgroundImage, setBounds, setBounds, setCursor, setEnabled, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setSize, setSize, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, update
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkSubclass, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, toString
-
Constructor Details
-
Tree
Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.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 theint
"|" operator) two or more of thoseSWT
style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.- Parameters:
parent
- a composite control which will be the parent of the new instance (cannot be null)style
- the style of control to construct- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the parent is null
SWTException
-- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
- ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
- See Also:
-
-
Method Details
-
getAdapter
Description copied from class:Widget
Implementation of theAdaptable
interface.IMPORTANT: This method is not part of the RWT public API. It is marked public only so that it can be shared within the packages provided by RWT. It should never be accessed from application code.
- Specified by:
getAdapter
in interfaceAdaptable
- Overrides:
getAdapter
in classComposite
- Parameters:
adapter
- the lookup class- Returns:
- an object that can be cast to the given class or
null
if there is no adapter associated with the given class.
-
setFont
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. -
setItemCount
public void setItemCount(int count) Sets the number of root-level items contained in the receiver.- Parameters:
count
- the number of 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 receiver
-
getItemCount
public int getItemCount()Returns the number of items contained in the receiver that are direct item children of the receiver. The number that is returned is the number of roots in the tree.- Returns:
- the number of 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 receiver
-
getItems
Returns a (possibly empty) array of items contained in the receiver that are direct item children of the receiver. These are the roots of the tree.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
- Throws:
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. 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:
IllegalArgumentException
-- ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
indexOf
Searches the receiver's list starting at the first item (index 0) until an item is found that is equal to the argument, and returns the index of that item. If no item is found, returns -1.- Parameters:
item
- the search item- Returns:
- the index of the item
- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the tool item is null
- ERROR_INVALID_ARGUMENT - if the tool item has been disposed
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getParentItem
Returns the receiver's parent item, which must be aTreeItem
or null when the receiver is a root.- Returns:
- the receiver's parent item
- Throws:
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()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 receiver
-
showItem
Shows the item. If the item is already showing in the receiver, this method simply returns. Otherwise, the items are scrolled and expanded until the item is visible.- Parameters:
item
- the item to be shown- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the item is null
- ERROR_INVALID_ARGUMENT - if the item has been disposed
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
setTopItem
Sets the item which is currently at the top of the receiver. This item can change when items are expanded, collapsed, scrolled or new items are added or removed.- Parameters:
item
- the item to be shown- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the item is null
- ERROR_INVALID_ARGUMENT - if the item has been disposed
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 1.4
- See Also:
-
getTopItem
Returns the item which is currently at the top of the receiver. This item can change when items are expanded, collapsed, scrolled or new items are added or removed.- Returns:
- the item at the top of 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 receiver
- Since:
- 1.4
-
showColumn
Shows the column. If the column is already showing in the receiver, this method simply returns. Otherwise, the columns are scrolled until the column is visible.- Parameters:
column
- the column to be shown- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the column is null
- ERROR_INVALID_ARGUMENT - if the column has been disposed
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 1.3
-
showSelection
public void showSelection()Shows the selection. If the selection is already showing in the receiver, this method simply returns. Otherwise, the items are scrolled until the selection is visible.- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
getSelection
Returns an array ofTreeItem
s 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:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getSelectionCount
public int getSelectionCount()Returns the number of selected items contained in the receiver.- Returns:
- the number 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 receiver
-
setSelection
Sets the receiver's selection to the given item. The current selection is cleared before the new item is selected.If the item is not in the receiver, then it is ignored.
- Parameters:
selection
- the item to select- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the item is null
- ERROR_INVALID_ARGUMENT - if the item has been disposed
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setSelection
Sets the receiver's selection to be the given array of items. The current selection is cleared before the new items are selected.Items that are not in the receiver are ignored. If the receiver is single-select and multiple items are specified, then all items are ignored.
- Parameters:
selection
- the array of items- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the array of items is null
- ERROR_INVALID_ARGUMENT - if one of the items has been disposed
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
select
Selects an item in the receiver. If the item was already selected, it remains selected.- Parameters:
item
- the item to be selected- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the item is null
- ERROR_INVALID_ARGUMENT - if the item has been disposed
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 1.3
-
selectAll
public void selectAll()Selects all of the items in the receiver.If the receiver is single-select, do nothing.
- Throws:
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 an item in the receiver. If the item was already deselected, it remains deselected.- Parameters:
item
- the item to be deselected- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the item is null
- ERROR_INVALID_ARGUMENT - if the item has been disposed
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 1.3
-
deselectAll
public void deselectAll()Deselects all selected items in 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 receiver
-
setLinesVisible
public void setLinesVisible(boolean value) Marks the receiver's lines as visible if the argument istrue
, and marks it invisible otherwise.If one of the receiver's ancestors is not visible or some other condition makes the receiver not visible, marking it visible may not actually cause it to be displayed.
- Parameters:
value
- the new visibility state- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getGridLineWidth
public int getGridLineWidth()Returns the width in pixels of a grid line.- Returns:
- the width of a grid line 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 receiver
- Since:
- 1.4
-
getLinesVisible
public boolean getLinesVisible()Returnstrue
if the receiver's lines are visible, andfalse
otherwise.If one of the receiver's ancestors is not visible or some other condition makes the receiver not visible, this method may still indicate that it is considered visible even though it may not actually be showing.
- Returns:
- the visibility state of the lines
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
clear
public void clear(int index, boolean recursive) Clears the item at the given zero-relative index in the receiver. The text, icon and other attributes of the item are set to the default value. If the tree was created with theSWT.VIRTUAL
style, these attributes are requested again as needed.- Parameters:
index
- the index of the item to clearrecursive
-true
if all child items of the indexed item should be cleared recursively, andfalse
otherwise- Throws:
IllegalArgumentException
-- ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
getItem
Returns the item at the given point in the receiver or null if no such item exists. The point is in the coordinate system of the receiver.The item that is returned represents an item that could be selected by the user. For example, if selection only occurs in items in the first column, then null is returned if the point is outside of the item. Note that the SWT.FULL_SELECTION style hint, which specifies the selection policy, determines the extent of the selection.
- Parameters:
point
- the point used to locate the item- Returns:
- the item at the given point, or null if the point is not in a selectable item
- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the point 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 receiver
-
getItemHeight
public int getItemHeight()Returns the height of the area which would be used to display one of the items in the tree.- Returns:
- the height of one item
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 1.3
-
clearAll
public void clearAll(boolean recursive) Clears all the items in the receiver. The text, icon and other attributes of the items are set to their default values. If the tree was created with theSWT.VIRTUAL
style, these attributes are requested again as needed.- Parameters:
recursive
-true
if all child items should be cleared recursively, andfalse
otherwise- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
changed
Description copied from class:Composite
Clears any data that has been cached by a Layout for all widgets that are in the parent hierarchy of the changed control up to and including the receiver. If an ancestor does not have a layout, it is skipped. -
getColumnCount
public int getColumnCount()Returns the number of columns contained in the receiver. If noTreeColumn
s were created by the programmer, this value is zero, despite the fact that visually, one column of items may be visible. This occurs when the programmer uses the tree like a list, adding items but never creating a column.- Returns:
- the number of columns
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getHeaderHeight
public int getHeaderHeight()Returns the height of the receiver's header- Returns:
- the height of the header or zero if the header is not visible
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setHeaderVisible
public void setHeaderVisible(boolean value) Marks the receiver's header as visible if the argument istrue
, and marks it invisible otherwise.If one of the receiver's ancestors is not visible or some other condition makes the receiver not visible, marking it visible may not actually cause it to be displayed.
- Parameters:
value
- the new visibility state- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getHeaderVisible
public boolean getHeaderVisible()Returnstrue
if the receiver's header is visible, andfalse
otherwise.If one of the receiver's ancestors is not visible or some other condition makes the receiver not visible, this method may still indicate that it is considered visible even though it may not actually be showing.
- Returns:
- the receiver's header's visibility state
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setHeaderBackground
Sets the header background color to the color specified by the argument, or to the default system color if the argument is null.- Parameters:
color
- the new color (or null)- Throws:
IllegalArgumentException
-- ERROR_INVALID_ARGUMENT - if the argument has been disposed
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 3.6
-
getHeaderBackground
Returns the header background color.- Returns:
- the receiver's header background color.
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 3.6
-
setHeaderForeground
Sets the header foreground color to the color specified by the argument, or to the default system color if the argument is null.- Parameters:
color
- the new color (or null)- Throws:
IllegalArgumentException
-- ERROR_INVALID_ARGUMENT - if the argument has been disposed
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 3.6
-
getHeaderForeground
Returns the header foreground color.- Returns:
- the receiver's header foreground color.
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 3.6
-
indexOf
Searches the receiver's list starting at the first column (index 0) until a column is found that is equal to the argument, and returns the index of that column. If no column is found, returns -1.- Parameters:
column
- the search column- Returns:
- the index of the column
- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the column 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 receiver
-
getColumn
Returns the column at the given, zero-relative index in the receiver. Throws an exception if the index is out of range. Columns are returned in the order that they were created. If noTreeColumn
s were created by the programmer, this method will throwERROR_INVALID_RANGE
despite the fact that a single column of data may be visible in the tree. This occurs when the programmer uses the tree like a list, adding items but never creating a column.- Parameters:
index
- the index of the column to return- Returns:
- the column at the given index
- Throws:
IllegalArgumentException
-- ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
getColumns
Returns an array ofTreeColumn
s which are the columns in the receiver. Columns are returned in the order that they were created. If noTreeColumn
s were created by the programmer, the array is empty, despite the fact that visually, one column of items may be visible. This occurs when the programmer uses the tree like a list, adding items but never creating a column.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
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
setColumnOrder
public void setColumnOrder(int[] order) Sets the order that the items in the receiver should be displayed in to the given argument which is described in terms of the zero-relative ordering of when the items were added.- Parameters:
order
- the new order to display the 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 receiver
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the item order is null
- ERROR_INVALID_ARGUMENT - if the item order is not the same length as the number of items
- See Also:
-
setSortColumn
Sets the column used by the sort indicator for the receiver. A null value will clear the sort indicator. The current sort column is cleared before the new column is set.- Parameters:
column
- the column used by the sort indicator ornull
- Throws:
IllegalArgumentException
-- ERROR_INVALID_ARGUMENT - if the column is disposed
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setSortDirection
public void setSortDirection(int direction) Sets the direction of the sort indicator for the receiver. The value can be one ofUP
,DOWN
orNONE
.- Parameters:
direction
- the direction of the sort indicator- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getSortColumn
Returns the column which shows the sort indicator for the receiver. The value may be null if no column shows the sort indicator.- Returns:
- the sort indicator
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
getSortDirection
public int getSortDirection()Returns the direction of the sort indicator for the receiver. The value will be one ofUP
,DOWN
orNONE
.- Returns:
- the sort direction
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
getColumnOrder
public int[] getColumnOrder()Returns an array of zero-relative integers that map the creation order of the receiver's items to the order in which they are currently being displayed.Specifically, the indices of the returned array represent the current visual order of the items, and the contents of the array represent the creation order of the items.
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 current visual order of the receiver's 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 receiver
- See Also:
-
addSelectionListener
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 theSelectionListener
interface.When
widgetSelected
is called, the item field of the event object is valid. If the receiver hasSWT.CHECK
style set and the check selection changes, the event object detail field contains the valueSWT.CHECK
.widgetDefaultSelected
is typically called when an item is double-clicked. The item field of the event object is valid for default selection, but the detail field is not used.- Parameters:
listener
- the listener which should be notified- Throws:
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 receiver
- See Also:
-
removeSelectionListener
Removes the listener from the collection of listeners who will be notified when the receiver's selection changes.- Parameters:
listener
- the listener which should no longer be notified- Throws:
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 receiver
- See Also:
-
addTreeListener
Adds the listener to the collection of listeners who will be notified when an item in the receiver is expanded or collapsed by sending it one of the messages defined in theTreeListener
interface.- Parameters:
listener
- the listener which should be notified- Throws:
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 receiver
- See Also:
-
removeTreeListener
Removes the listener from the collection of listeners who will be notified when items in the receiver are expanded or collapsed.- Parameters:
listener
- the listener which should no longer be notified- Throws:
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 receiver
- See Also:
-
setData
Description copied from class:Widget
Sets the application defined property of the receiver with the specified name to the given value.Applications may associate arbitrary objects with the receiver in this fashion. If the objects stored in the properties need to be notified when the widget is disposed of, it is the application's responsibility to hook the Dispose event on the widget and do so.
-
computeSize
Description copied from class:Control
Returns the preferred size of the receiver.The preferred size of a control is the size that it would best be 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 befalse
, so layout manager caches can be retained.- Overrides:
computeSize
in classComposite
- Parameters:
wHint
- the width hint (can beSWT.DEFAULT
)hHint
- the height hint (can beSWT.DEFAULT
)changed
-true
if the control's contents have changed, andfalse
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"
-