|
Eclipse eRCP Release 1.1 |
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.swt.widgets.Widget
org.eclipse.swt.widgets.Control
org.eclipse.swt.widgets.Scrollable
org.eclipse.swt.widgets.Composite
org.eclipse.swt.widgets.Tree
Instances of this class provide a selectable user interface object that displays a hierarchy of items and issues notification when an item in the hierarchy is selected.
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 Summary | |
---|---|
Tree(Composite parent,
int style)
Constructs a new instance of this class given its parent and a style value describing its behavior and appearance. |
Method Summary | |
---|---|
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. |
void |
deselectAll()
Deselects all selected items 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. |
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. |
TreeItem |
getTopItem()
Returns the item which is currently at the top of the receiver. |
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 |
selectAll()
Selects all of the items in the receiver. |
void |
setItemCount(int count)
Sets the number of root-level items contained in the receiver. |
void |
setSelection(TreeItem[] items)
Sets the receiver's selection to be the given array of items. |
void |
setTopItem(TreeItem item)
Sets the item which is currently at the top of the receiver. |
void |
showItem(TreeItem item)
Shows the item. |
void |
showSelection()
Shows the selection. |
Methods inherited from class org.eclipse.swt.widgets.Composite |
---|
checkSubclass, getBackgroundMode, getChildren, getLayout, getTabList, layout, layout, setBackgroundMode, setLayout, setTabList |
Methods inherited from class org.eclipse.swt.widgets.Scrollable |
---|
computeTrim, getClientArea, getHorizontalBar, getVerticalBar |
Methods inherited from class org.eclipse.swt.widgets.Widget |
---|
addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, setData, setData, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
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 construct
IllegalArgumentException
- SWTException
- SWT.SINGLE
,
SWT.MULTI
,
SWT.CHECK
,
SWT#VIRTUAL
,
Widget.checkSubclass()
,
Widget.getStyle()
Method Detail |
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 selection
IllegalArgumentException
- SWTException
- SelectionListener
,
removeSelectionListener(org.eclipse.swt.events.SelectionListener)
,
SelectionEvent
public void addTreeListener(TreeListener listener)
TreeListener
interface.
listener
- the listener which should be notified
IllegalArgumentException
- SWTException
- TreeListener
,
removeTreeListener(org.eclipse.swt.events.TreeListener)
public void deselectAll()
SWTException
- public TreeItem getItem(Point point)
point
- the point used to locate the item
IllegalArgumentException
- 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 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 TreeItem getTopItem()
SWTException
- public void removeAll()
SWTException
- public void removeSelectionListener(SelectionListener listener)
listener
- the listener which should no longer be notified
IllegalArgumentException
- SWTException
- SelectionListener
,
addSelectionListener(org.eclipse.swt.events.SelectionListener)
public void removeTreeListener(TreeListener listener)
listener
- the listener which should no longer be notified
IllegalArgumentException
- SWTException
- TreeListener
,
addTreeListener(org.eclipse.swt.events.TreeListener)
public void selectAll()
If the receiver is single-select, do nothing.
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 items
IllegalArgumentException
- SWTException
- deselectAll()
public void setTopItem(TreeItem item)
item
- the item to be shown
IllegalArgumentException
- SWTException
- getTopItem()
public void showItem(TreeItem item)
item
- the item to be shown
IllegalArgumentException
- SWTException
- showSelection()
public void showSelection()
SWTException
- showItem(TreeItem)
public void setItemCount(int count)
count
- the number of items
SWTException
-
|
Eclipse eRCP Release 1.1 |
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |