public class Tree extends Composite
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 normally make sense to add Control
children to
it, or set a layout on it, unless implementing something like a cell
editor.
Note: Only one of the styles SINGLE and MULTI may be specified.
IMPORTANT: This class is not intended to be subclassed.
Constructor and Description |
---|
Tree(Composite parent,
int style)
Constructs a new instance of this class given its parent
and a style value describing its behavior and appearance.
|
Modifier and Type | Method and Description |
---|---|
void |
addSelectionListener(SelectionListener listener)
Adds the listener to the collection of listeners who will
be notified when the user changes the receiver's selection, by sending
it one of the messages defined in the
SelectionListener
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 the
TreeListener
interface. |
protected void |
checkSubclass()
Checks that this class can be subclassed.
|
void |
clear(int index,
boolean all)
Clears the item at the given zero-relative index in the receiver.
|
void |
clearAll(boolean all)
Clears all the items in the receiver.
|
void |
deselect(TreeItem item)
Deselects an item in the receiver.
|
void |
deselectAll()
Deselects all selected items in the receiver.
|
TreeColumn |
getColumn(int index)
Returns the column at the given, zero-relative index in the
receiver.
|
int |
getColumnCount()
Returns the number of columns contained in the receiver.
|
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.
|
TreeColumn[] |
getColumns()
Returns an array of
TreeColumn s which are the
columns in the receiver. |
int |
getGridLineWidth()
Returns the width in pixels of a grid line.
|
Color |
getHeaderBackground()
Returns the header background color.
|
Color |
getHeaderForeground()
Returns the header foreground color.
|
int |
getHeaderHeight()
Returns the height of the receiver's header
|
boolean |
getHeaderVisible()
Returns
true if the receiver's header is visible,
and false otherwise. |
TreeItem |
getItem(int index)
Returns the item at the given, zero-relative index in the
receiver.
|
TreeItem |
getItem(Point point)
Returns the item at the given point in the receiver
or null if no such item exists.
|
int |
getItemCount()
Returns the number of items contained in the receiver
that are direct item children of the receiver.
|
int |
getItemHeight()
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 |
getLinesVisible()
Returns
true if the receiver's lines are visible,
and false otherwise. |
TreeItem |
getParentItem()
Returns the receiver's parent item, which must be a
TreeItem or null when the receiver is a
root. |
TreeItem[] |
getSelection()
Returns an array of
TreeItem s that are currently
selected in the receiver. |
int |
getSelectionCount()
Returns the number of selected items contained in the receiver.
|
TreeColumn |
getSortColumn()
Returns the column which shows the sort indicator for
the receiver.
|
int |
getSortDirection()
Returns the direction of the sort indicator for the receiver.
|
TreeItem |
getTopItem()
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 |
indexOf(TreeItem item)
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 |
removeAll()
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 user changes the receiver's selection.
|
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 |
select(TreeItem item)
Selects an item in the receiver.
|
void |
selectAll()
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 |
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 |
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 show)
Marks the receiver's header as visible if the argument is
true ,
and marks it invisible otherwise. |
void |
setInsertMark(TreeItem item,
boolean before)
Display a mark indicating the point at which an item will be inserted.
|
void |
setItemCount(int count)
Sets the number of root-level items contained in the receiver.
|
void |
setLinesVisible(boolean show)
Marks the receiver's lines as visible if the argument is
true ,
and marks it invisible otherwise. |
void |
setRedraw(boolean redraw)
If the argument is
false , causes subsequent drawing
operations in the receiver to be ignored. |
void |
setSelection(TreeItem item)
Sets the receiver's selection to the given item.
|
void |
setSelection(TreeItem[] items)
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 |
showItem(TreeItem item)
Shows the item.
|
void |
showSelection()
Shows the selection.
|
changed, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar
addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, computeSize, dragDetect, dragDetect, forceFocus, 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, 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, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRegion, setSize, setSize, setTextDirection, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update
addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isAutoDirection, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, setData, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
isAutoScalable
public Tree(Composite parent, int style)
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. The class description
lists the style constants that are applicable to the class.
Style bits are also inherited from superclasses.
parent
- a composite control which will be the parent of the new instance (cannot be null)style
- the style of control to constructIllegalArgumentException
- SWTException
- SWT.SINGLE
,
SWT.MULTI
,
SWT.CHECK
,
SWT.FULL_SELECTION
,
SWT.VIRTUAL
,
SWT.NO_SCROLL
,
Widget.checkSubclass()
,
Widget.getStyle()
public void addSelectionListener(SelectionListener listener)
SelectionListener
interface.
When widgetSelected
is called, the item field of the event object is valid.
If the receiver has the SWT.CHECK
style and the check selection changes,
the event object detail field contains the value SWT.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.
listener
- the listener which should be notified when the user changes the receiver's selectionIllegalArgumentException
- SWTException
- SelectionListener
,
removeSelectionListener(org.eclipse.swt.events.SelectionListener)
,
SelectionEvent
public void addTreeListener(TreeListener listener)
TreeListener
interface.listener
- the listener which should be notifiedIllegalArgumentException
- SWTException
- TreeListener
,
removeTreeListener(org.eclipse.swt.events.TreeListener)
protected void checkSubclass()
Widget
The SWT class library is intended to be subclassed
only at specific, controlled points (most notably,
Composite
and Canvas
when
implementing new widgets). This method enforces this
rule unless it is overridden.
IMPORTANT: By providing an implementation of this method that allows a subclass of a class which does not normally allow subclassing to be created, the implementer agrees to be fully responsible for the fact that any such subclass will likely fail between SWT releases and will be strongly platform specific. No support is provided for user-written classes which are implemented in this fashion.
The ability to subclass outside of the allowed SWT classes is intended purely to enable those not on the SWT development team to implement patches in order to get around specific limitations in advance of when those limitations can be addressed by the team. Subclassing should not be attempted without an intimate and detailed understanding of the hierarchy.
checkSubclass
in class Composite
public void clear(int index, boolean all)
SWT.VIRTUAL
style,
these attributes are requested again as needed.index
- the index of the item to clearall
- true
if all child items of the indexed item should be
cleared recursively, and false
otherwiseIllegalArgumentException
- SWTException
- SWT.VIRTUAL
,
SWT.SetData
public void clearAll(boolean all)
SWT.VIRTUAL
style, these
attributes are requested again as needed.all
- true
if all child items should be cleared
recursively, and false
otherwiseSWTException
- SWT.VIRTUAL
,
SWT.SetData
public void deselect(TreeItem item)
item
- the item to be deselectedIllegalArgumentException
- SWTException
- public void deselectAll()
SWTException
- public int getGridLineWidth()
SWTException
- public Color getHeaderBackground()
SWTException
- public Color getHeaderForeground()
SWTException
- public int getHeaderHeight()
SWTException
- public boolean getHeaderVisible()
true
if the receiver's header is visible,
and false
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.
SWTException
- public TreeColumn getColumn(int index)
TreeColumn
s were created by the programmer,
this method will throw ERROR_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.index
- the index of the column to returnIllegalArgumentException
- SWTException
- getColumnOrder()
,
setColumnOrder(int[])
,
TreeColumn.getMoveable()
,
TreeColumn.setMoveable(boolean)
,
SWT.Move
public int getColumnCount()
TreeColumn
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.SWTException
- public int[] getColumnOrder()
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.
SWTException
- setColumnOrder(int[])
,
TreeColumn.getMoveable()
,
TreeColumn.setMoveable(boolean)
,
SWT.Move
public TreeColumn[] getColumns()
TreeColumn
s which are the
columns in the receiver. Columns are returned in the order
that they were created. If no TreeColumn
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.
SWTException
- getColumnOrder()
,
setColumnOrder(int[])
,
TreeColumn.getMoveable()
,
TreeColumn.setMoveable(boolean)
,
SWT.Move
public TreeItem getItem(int index)
index
- the index of the item to returnIllegalArgumentException
- SWTException
- public TreeItem getItem(Point point)
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.
point
- the point used to locate the itemIllegalArgumentException
- SWTException
- public int getItemCount()
SWTException
- public int getItemHeight()
SWTException
- public TreeItem[] getItems()
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.
SWTException
- public boolean getLinesVisible()
true
if the receiver's lines are visible,
and false
otherwise. Note that some platforms draw
grid lines while others may draw alternating row colors.
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.
SWTException
- public TreeItem getParentItem()
TreeItem
or null when the receiver is a
root.SWTException
- public TreeItem[] getSelection()
TreeItem
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.
SWTException
- public int getSelectionCount()
SWTException
- public TreeColumn getSortColumn()
SWTException
- setSortColumn(TreeColumn)
public int getSortDirection()
UP
, DOWN
or NONE
.SWTException
- setSortDirection(int)
public TreeItem getTopItem()
SWTException
- public int indexOf(TreeColumn column)
column
- the search columnIllegalArgumentException
- SWTException
- public int indexOf(TreeItem item)
item
- the search itemIllegalArgumentException
- SWTException
- public void removeAll()
SWTException
- public void removeSelectionListener(SelectionListener listener)
listener
- the listener which should no longer be notifiedIllegalArgumentException
- SWTException
- SelectionListener
,
addSelectionListener(org.eclipse.swt.events.SelectionListener)
public void removeTreeListener(TreeListener listener)
listener
- the listener which should no longer be notifiedIllegalArgumentException
- SWTException
- TreeListener
,
addTreeListener(org.eclipse.swt.events.TreeListener)
public void setInsertMark(TreeItem item, boolean before)
item
- the insert item. Null will clear the insertion mark.before
- true places the insert mark above 'item'. false places
the insert mark below 'item'.IllegalArgumentException
- SWTException
- public void setItemCount(int count)
count
- the number of itemsSWTException
- public void setLinesVisible(boolean show)
true
,
and marks it invisible otherwise. Note that some platforms draw
grid lines while others may draw alternating row colors.
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.
show
- the new visibility stateSWTException
- public void select(TreeItem item)
item
- the item to be selectedIllegalArgumentException
- SWTException
- public void selectAll()
If the receiver is single-select, do nothing.
SWTException
- public void setColumnOrder(int[] order)
order
- the new order to display the itemsSWTException
- IllegalArgumentException
- getColumnOrder()
,
TreeColumn.getMoveable()
,
TreeColumn.setMoveable(boolean)
,
SWT.Move
public void setFont(Font font)
Control
public void setHeaderBackground(Color color)
Note: This operation is a HINT and is not supported on all platforms. If the native header has a 3D look and feel (e.g. Windows 7), this method will cause the header to look FLAT irrespective of the state of the tree style.
color
- the new color (or null)IllegalArgumentException
- SWTException
- public void setHeaderForeground(Color color)
Note: This operation is a HINT and is not supported on all platforms. If the native header has a 3D look and feel (e.g. Windows 7), this method will cause the header to look FLAT irrespective of the state of the tree style.
color
- the new color (or null)IllegalArgumentException
- SWTException
- public void setHeaderVisible(boolean show)
true
,
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.
show
- the new visibility stateSWTException
- public void setRedraw(boolean redraw)
Control
false
, causes subsequent drawing
operations in the receiver to be ignored. No drawing of any kind
can occur in the receiver until the flag is set to true.
Graphics operations that occurred while the flag was
false
are lost. When the flag is set to true
,
the entire widget is marked as needing to be redrawn. Nested calls
to this method are stacked.
Note: This operation is a hint and may not be supported on some platforms or for some widgets.
setRedraw
in class Control
redraw
- the new redraw stateControl.redraw(int, int, int, int, boolean)
,
Control.update()
public void setSelection(TreeItem item)
If the item is not in the receiver, then it is ignored.
item
- the item to selectIllegalArgumentException
- SWTException
- public void setSelection(TreeItem[] items)
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.
items
- the array of itemsIllegalArgumentException
- SWTException
- deselectAll()
public void setSortColumn(TreeColumn column)
column
- the column used by the sort indicator or null
IllegalArgumentException
- SWTException
- public void setSortDirection(int direction)
UP
, DOWN
or NONE
.direction
- the direction of the sort indicatorSWTException
- public void setTopItem(TreeItem item)
item
- the item to be shownIllegalArgumentException
- SWTException
- getTopItem()
public void showColumn(TreeColumn column)
column
- the column to be shownIllegalArgumentException
- SWTException
- public void showItem(TreeItem item)
item
- the item to be shownIllegalArgumentException
- SWTException
- showSelection()
public void showSelection()
SWTException
- showItem(TreeItem)
Copyright (c) 2000, 2018 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.