|
Eclipse Rich Ajax Platform | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.swt.widgets.Widget org.eclipse.swt.widgets.Control org.eclipse.swt.widgets.Scrollable org.eclipse.swt.widgets.Composite org.eclipse.swt.widgets.Tree
public class 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 make sense to add Control
children to it, or set a
layout on it.
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 receiver's selection changes, 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 |
changed(Control[] changed)
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. |
|
Point |
computeSize(int wHint,
int hHint,
boolean changed)
Returns the preferred size of the receiver. |
|
void |
deselect(TreeItem item)
Deselects an item in the receiver. |
|
void |
deselectAll()
Deselects all selected items in the receiver. |
|
|
getAdapter(java.lang.Class<T> adapter)
Implementation of the Adaptable interface. |
|
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. |
|
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 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 |
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 |
setData(java.lang.String key,
java.lang.Object value)
Sets the application defined property of the receiver with the specified name to the given value. |
|
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 |
setHeaderVisible(boolean value)
Marks the receiver's header as visible if the argument is true
, 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 is true ,
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 |
showItem(TreeItem item)
Shows the item. |
|
void |
showSelection()
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.Widget |
---|
addDisposeListener, addListener, checkSubclass, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, reskin, 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
java.lang.IllegalArgumentException
- SWTException
- SWT.SINGLE
,
SWT.MULTI
,
SWT.CHECK
,
SWT.FULL_SELECTION
,
SWT.NO_SCROLL
,
Widget.checkSubclass()
,
Widget.getStyle()
Method Detail |
---|
public <T> T getAdapter(java.lang.Class<T> adapter)
Widget
Adaptable
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.
getAdapter
in interface Adaptable
getAdapter
in class Composite
adapter
- the lookup class
null
if
there is no adapter associated with the given class.public void setFont(Font font)
Control
setFont
in class Control
font
- the new font (or null)public void setItemCount(int count)
count
- the number of items
SWTException
- public int getItemCount()
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 getItem(int index)
index
- the index of the item to return
java.lang.IllegalArgumentException
- SWTException
- public int indexOf(TreeItem item)
item
- the search item
java.lang.IllegalArgumentException
- SWTException
- public TreeItem getParentItem()
TreeItem
or null when the receiver is a root.
SWTException
- public void removeAll()
SWTException
- public void showItem(TreeItem item)
item
- the item to be shown
java.lang.IllegalArgumentException
- SWTException
- showSelection()
public void setTopItem(TreeItem item)
item
- the item to be shown
java.lang.IllegalArgumentException
- SWTException
- getTopItem()
public TreeItem getTopItem()
SWTException
- public void showColumn(TreeColumn column)
column
- the column to be shown
java.lang.IllegalArgumentException
- SWTException
- public void showSelection()
SWTException
- showItem(TreeItem)
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 void setSelection(TreeItem selection)
If the item is not in the receiver, then it is ignored.
selection
- the item to select
java.lang.IllegalArgumentException
- SWTException
- public void setSelection(TreeItem[] selection)
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.
selection
- the array of items
java.lang.IllegalArgumentException
- SWTException
- deselectAll()
public void select(TreeItem item)
item
- the item to be selected
java.lang.IllegalArgumentException
- SWTException
- public void selectAll()
If the receiver is single-select, do nothing.
SWTException
- public void deselect(TreeItem item)
item
- the item to be deselected
java.lang.IllegalArgumentException
- SWTException
- public void deselectAll()
SWTException
- public void setLinesVisible(boolean value)
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.
value
- the new visibility state
SWTException
- public int getGridLineWidth()
SWTException
- public boolean getLinesVisible()
true
if the receiver's lines are 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 void clear(int index, boolean recursive)
SWT.VIRTUAL
style, these attributes
are requested again as needed.
index
- the index of the item to clearrecursive
- true
if all child items of the indexed item
should be cleared recursively, and false
otherwise
java.lang.IllegalArgumentException
- SWTException
- SWT.VIRTUAL
,
SWT.SetData
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 item
java.lang.IllegalArgumentException
- SWTException
- public int getItemHeight()
SWTException
- public void clearAll(boolean recursive)
SWT.VIRTUAL
style, these attributes are requested again as
needed.
recursive
- true
if all child items should be cleared
recursively, and false
otherwise
SWTException
- SWT.VIRTUAL
,
SWT.SetData
public void changed(Control[] changed)
Composite
changed
in class Composite
changed
- an array of controls that changed state and require a recalculation of sizepublic 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 getHeaderHeight()
SWTException
- public void setHeaderVisible(boolean value)
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.
value
- the new visibility state
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 int indexOf(TreeColumn column)
column
- the search column
java.lang.IllegalArgumentException
- 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 return
java.lang.IllegalArgumentException
- SWTException
- getColumnOrder()
,
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 void setColumnOrder(int[] order)
order
- the new order to display the items
SWTException
- java.lang.IllegalArgumentException
- getColumnOrder()
,
TreeColumn.getMoveable()
,
TreeColumn.setMoveable(boolean)
,
SWT.Move
public void setSortColumn(TreeColumn column)
column
- the column used by the sort indicator or null
java.lang.IllegalArgumentException
- SWTException
- public void setSortDirection(int direction)
UP
, DOWN
or NONE
.
direction
- the direction of the sort indicator
SWTException
- public TreeColumn getSortColumn()
SWTException
- setSortColumn(TreeColumn)
public int getSortDirection()
UP
, DOWN
or NONE
.
SWTException
- setSortDirection(int)
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 void addSelectionListener(SelectionListener listener)
SelectionListener
interface.
When widgetSelected
is called, the item field of the event
object is valid. If the receiver has SWT.CHECK
style set 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
java.lang.IllegalArgumentException
- SWTException
- SelectionListener
,
removeSelectionListener(org.eclipse.swt.events.SelectionListener)
,
SelectionEvent
public void removeSelectionListener(SelectionListener listener)
listener
- the listener which should no longer be notified
java.lang.IllegalArgumentException
- SWTException
- SelectionListener
,
addSelectionListener(org.eclipse.swt.events.SelectionListener)
public void addTreeListener(TreeListener listener)
TreeListener
interface.
listener
- the listener which should be notified
java.lang.IllegalArgumentException
- SWTException
- TreeListener
,
removeTreeListener(org.eclipse.swt.events.TreeListener)
public void removeTreeListener(TreeListener listener)
listener
- the listener which should no longer be notified
java.lang.IllegalArgumentException
- SWTException
- TreeListener
,
addTreeListener(org.eclipse.swt.events.TreeListener)
public void setData(java.lang.String key, java.lang.Object value)
Widget
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.
setData
in class Widget
key
- the name of the propertyvalue
- the new value for the propertyWidget.getData(String)
public Point computeSize(int wHint, int hHint, boolean changed)
Control
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 be false
, so layout
manager caches can be retained.
computeSize
in class Composite
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
Layout
,
Control.getBorderWidth()
,
Control.getBounds()
,
Control.getSize()
,
Control.pack(boolean)
,
"computeTrim, getClientArea for controls that implement them"
|
Eclipse Rich Ajax Platform | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright (c) EclipseSource and others 2002, 2012. All rights reserved.