public class TreeViewer extends AbstractTreeViewer
Tree
control.
This class is not intended to be subclassed outside the viewer framework. It is designed to be instantiated with a pre-existing SWT tree control and configured with a domain-specific content provider, label provider, element filter (optional), and element sorter (optional).
As of 3.2, TreeViewer supports multiple equal elements (each with a
different parent chain) in the tree. This support requires that clients
enable the element map by calling setUseHashLookup(true)
.
Content providers for tree viewers must implement either the
ITreeContentProvider
interface, (as of 3.2) the
ILazyTreeContentProvider
interface, or (as of 3.3) the
ILazyTreePathContentProvider
. If the content provider is an
ILazyTreeContentProvider
or an
ILazyTreePathContentProvider
, the underlying Tree must be
created using the SWT.VIRTUAL
style bit, the tree viewer will not
support sorting or filtering, and hash lookup must be enabled by calling
StructuredViewer.setUseHashlookup(boolean)
.
Users setting up an editable tree with more than 1 column have to pass the SWT.FULL_SELECTION style bit
StructuredViewer.ColorAndFontCollector, StructuredViewer.ColorAndFontCollectorWithProviders
ALL_LEVELS
WIDGET_DATA_KEY
Constructor and Description |
---|
TreeViewer(Composite parent)
Creates a tree viewer on a newly-created tree control under the given
parent.
|
TreeViewer(Composite parent,
int style)
Creates a tree viewer on a newly-created tree control under the given
parent.
|
TreeViewer(Tree tree)
Creates a tree viewer on the given tree control.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addTreeListener(Control c,
TreeListener listener)
Adds the given SWT tree listener to the given SWT control.
|
protected void |
assertContentProviderType(IContentProvider provider)
Assert that the content provider is of one of the
supported types.
|
protected ColumnViewerEditor |
createViewerEditor()
This implementation of
AbstractTreeViewer.createViewerEditor() returns null to ensure
API backwards compatibility. |
protected void |
disassociate(Item item)
The
AbstractTreeViewer implementation of this method also
recurses over children of the corresponding element. |
protected int |
doGetColumnCount()
Returns the number of columns of this viewer.
|
void |
editElement(Object element,
int column)
Starts editing the given element at the given column index.
|
protected Item |
getChild(Widget widget,
int index)
Get the child for the widget at index.
|
protected Item[] |
getChildren(Widget o)
Returns the SWT child items for the given SWT widget.
|
protected Widget |
getColumnViewerOwner(int columnIndex)
Returns the column widget at the given column index.
|
Control |
getControl()
Returns the primary control associated with this viewer.
|
protected boolean |
getExpanded(Item item)
Returns whether the given SWT item is expanded or collapsed.
|
protected Item |
getItemAt(Point p)
This implementation of
AbstractTreeViewer.getItemAt(Point) returns null to ensure
API backwards compatibility. |
protected int |
getItemCount(Control widget)
Returns the number of child items of the given SWT control.
|
protected int |
getItemCount(Item item)
Returns the number of child items of the given SWT item.
|
protected Item[] |
getItems(Item item)
Returns the child items of the given SWT item.
|
IBaseLabelProvider |
getLabelProvider()
The tree viewer implementation of this
Viewer framework
method ensures that the given label provider is an instance of either
ITableLabelProvider or ILabelProvider . |
protected Object |
getParentElement(Object element)
This method takes a tree path or an element.
|
protected Item |
getParentItem(Item item)
Returns the parent item of the given item in the tree, or
null if there is no parent item. |
protected Object[] |
getRawChildren(Object parent)
Returns the children of the given parent without sorting and filtering
them.
|
protected Item[] |
getSelection(Control widget)
Returns all selected items for the given SWT control.
|
Tree |
getTree()
Returns this tree viewer's tree control.
|
protected ViewerRow |
getViewerRowFromItem(Widget item)
Returns a
ViewerRow associated with the given row widget. |
protected void |
handleTreeCollapse(TreeEvent event)
Handles a tree collapse event from the SWT widget.
|
protected void |
handleTreeExpand(TreeEvent event)
Handles a tree expand event from the SWT widget.
|
protected void |
hookControl(Control control)
Adds event listener hooks to the given control.
|
protected void |
internalAdd(Widget widget,
Object parentElement,
Object[] childElements)
Adds the given child elements to this viewer as children of the given
parent element.
|
protected void |
internalInitializeTree(Control widget)
Initializes the tree with root items, expanding to the appropriate
level if necessary.
|
protected void |
internalRefreshStruct(Widget widget,
Object element,
boolean updateLabels)
Update the structure and recurse.
|
boolean |
isExpandable(Object element)
Return whether the tree node representing the given element or path can
be expanded.
|
protected void |
mapElement(Object element,
Widget item)
Adds the element item pair to the element map.
|
protected Item |
newItem(Widget parent,
int flags,
int ix)
Creates a new item.
|
void |
remove(Object parentOrTreePath,
int index)
Removes the element at the specified index of the parent.
|
protected void |
removeAll(Control widget)
Removes all items from the given control.
|
void |
replace(Object parentElementOrTreePath,
int index,
Object element)
For a TreeViewer with a tree with the VIRTUAL style bit set, replace the
given parent's child at index with the given element.
|
void |
setChildCount(Object elementOrTreePath,
int count)
For a TreeViewer with a tree with the VIRTUAL style bit set, set the
number of children of the given element or tree path.
|
void |
setContentProvider(IContentProvider provider)
The
AbstractTreeViewer implementation of this method
checks to ensure that the content provider is an
ITreeContentProvider . |
protected void |
setExpanded(Item node,
boolean expand)
Sets the expand state of the given item.
|
void |
setHasChildren(Object elementOrTreePath,
boolean hasChildren)
For a TreeViewer with a tree with the VIRTUAL style bit set, inform the
viewer about whether the given element or tree path has children.
|
void |
setSelection(ISelection selection,
boolean reveal)
Sets a new selection for this viewer and optionally makes it visible.
|
protected void |
setSelection(List items)
Sets the selection to the given list of items.
|
protected void |
showItem(Item item)
Shows the given item.
|
protected void |
updatePlus(Item item,
Object element)
Updates the "+"/"-" icon of the tree node from the given element.
|
add, add, addSelectionListener, addTreeListener, associate, buildLabel, collapseAll, collapseToLevel, createChildren, createTreeItem, doFindInputItem, doFindItem, doUpdateItem, doUpdateItem, expandAll, expandToLevel, expandToLevel, fireTreeCollapsed, fireTreeExpanded, getAutoExpandLevel, getChildren, getExpandedElements, getExpandedState, getExpandedTreePaths, getNextItem, getPreviousItem, getSelection, getSelectionFromWidget, getSortedChildren, getTreePathFromItem, getVisibleExpandedElements, handleDoubleSelect, indexForElement, inputChanged, insert, internalCollapseToLevel, internalExpand, internalExpandToLevel, internalFindItems, internalGetWidgetToSelect, internalIsInputOrEmptyPath, internalRefresh, internalRefresh, internalRefresh, internalRemove, internalRemove, isSameSelection, labelProviderChanged, remove, remove, remove, removeTreeListener, reveal, scrollDown, scrollUp, setAutoExpandLevel, setExpandedElements, setExpandedState, setExpandedTreePaths, setExpandPreCheckFilters, setSelectionToWidget, setSelectionToWidget, updateChildren
applyEditorValue, cancelEditing, checkBusy, getCell, getCellEditors, getCellModifier, getColumnProperties, getColumnViewerEditor, getItem, getLabelProvider, getViewerRow, handleDispose, hookEditingSupport, isBusy, isCellEditorActive, refresh, refresh, setBusy, setCellEditors, setCellModifier, setColumnProperties, setColumnViewerEditor, setLabelProvider, triggerEditorActivationEvent, update
addDoubleClickListener, addDragSupport, addDropSupport, addFilter, addOpenListener, addPostSelectionChangedListener, assertElementsNotNull, equals, filter, findItem, findItems, fireDoubleClick, fireOpen, firePostSelectionChanged, getColorAndFontCollector, getComparator, getComparer, getFilteredChildren, getFilters, getRoot, getSorter, handleInvalidSelection, handleLabelProviderChanged, handleOpen, handlePostSelect, handleSelect, hasFilters, internalUpdate, needsRefilter, preservingSelection, refresh, refresh, refreshItem, removeDoubleClickListener, removeFilter, removeOpenListener, removePostSelectionChangedListener, resetFilters, setComparator, setComparer, setFilters, setInput, setSorter, setUseHashlookup, testFindItem, testFindItems, unmapAllElements, unmapElement, unmapElement, update, updateItem, updateSelection, usingElementMap
getContentProvider, getInput
addHelpListener, addSelectionChangedListener, fireHelpRequested, fireSelectionChanged, getData, handleHelpRequest, removeHelpListener, removeSelectionChangedListener, setData, setSelection
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addSelectionChangedListener, removeSelectionChangedListener, setSelection
public TreeViewer(Composite parent)
MULTI, H_SCROLL, V_SCROLL,
and BORDER
. The
viewer has no input, no content provider, a default label provider, no
sorter, and no filters.parent
- the parent controlpublic TreeViewer(Composite parent, int style)
parent
- the parent controlstyle
- the SWT style bits used to create the tree.public TreeViewer(Tree tree)
tree
- the tree controlprotected void addTreeListener(Control c, TreeListener listener)
AbstractTreeViewer
addTreeListener
in class AbstractTreeViewer
c
- the SWT controllistener
- the SWT tree listenerprotected Widget getColumnViewerOwner(int columnIndex)
ColumnViewer
getColumnViewerOwner
in class AbstractTreeViewer
columnIndex
- the column indexprotected Item[] getChildren(Widget o)
AbstractTreeViewer
getChildren
in class AbstractTreeViewer
o
- the widgetpublic Control getControl()
Viewer
getControl
in class Viewer
protected boolean getExpanded(Item item)
AbstractTreeViewer
getExpanded
in class AbstractTreeViewer
item
- the itemtrue
if the item is considered expanded and
false
if collapsedprotected Item getItemAt(Point p)
AbstractTreeViewer
AbstractTreeViewer.getItemAt(Point)
returns null to ensure
API backwards compatibility. Subclasses should override.getItemAt
in class AbstractTreeViewer
p
- the widget-relative coordinatesItem
at the coordinates or null
if there
is no item at the given coordinatesprotected int getItemCount(Control widget)
AbstractTreeViewer
getItemCount
in class AbstractTreeViewer
widget
- the controlprotected int getItemCount(Item item)
AbstractTreeViewer
getItemCount
in class AbstractTreeViewer
item
- the itemprotected Item[] getItems(Item item)
AbstractTreeViewer
getItems
in class AbstractTreeViewer
item
- the itempublic IBaseLabelProvider getLabelProvider()
Viewer
framework
method ensures that the given label provider is an instance of either
ITableLabelProvider
or ILabelProvider
. If
it is an ITableLabelProvider
, then it provides a separate
label text and image for each column. If it is an
ILabelProvider
, then it provides only the label text and
image for the first column, and any remaining columns are blank.getLabelProvider
in class ContentViewer
protected Item getParentItem(Item item)
AbstractTreeViewer
null
if there is no parent item.getParentItem
in class AbstractTreeViewer
item
- the itemnull
if noneprotected Item[] getSelection(Control widget)
AbstractTreeViewer
getSelection
in class AbstractTreeViewer
widget
- the controlpublic Tree getTree()
protected void hookControl(Control control)
ContentViewer
All subclasses must call this method when their control is first established.
The ContentViewer
implementation of this method hooks
dispose events for the given control.
Subclasses may override if they need to add other control hooks;
however, super.hookControl
must be invoked.
hookControl
in class AbstractTreeViewer
control
- the controlprotected ColumnViewerEditor createViewerEditor()
AbstractTreeViewer
AbstractTreeViewer.createViewerEditor()
returns null to ensure
API backwards compatibility. Subclasses should override.createViewerEditor
in class AbstractTreeViewer
null
if this viewer does not support
editing cell contents.protected Item newItem(Widget parent, int flags, int ix)
AbstractTreeViewer
newItem
in class AbstractTreeViewer
parent
- the parent widgetflags
- SWT style bitsix
- if non-negative, indicates the position to insert the item
into its parentprotected void removeAll(Control widget)
AbstractTreeViewer
removeAll
in class AbstractTreeViewer
widget
- the controlprotected void setExpanded(Item node, boolean expand)
AbstractTreeViewer
setExpanded
in class AbstractTreeViewer
node
- the itemexpand
- the expand state of the itemprotected void setSelection(List items)
AbstractTreeViewer
setSelection
in class AbstractTreeViewer
items
- list of items (element type:
org.eclipse.swt.widgets.Item
)protected void showItem(Item item)
AbstractTreeViewer
showItem
in class AbstractTreeViewer
item
- the itemprotected Item getChild(Widget widget, int index)
AbstractTreeViewer
getChild
in class AbstractTreeViewer
widget
- the widget to checkindex
- the index of the widgetnull
if widget is not a type that can
contain items.protected void assertContentProviderType(IContentProvider provider)
StructuredViewer
assertContentProviderType
in class AbstractTreeViewer
protected Object[] getRawChildren(Object parent)
StructuredViewer
Returns an empty array if the given parent is null
.
getRawChildren
in class AbstractTreeViewer
parent
- the parent elementpublic void setChildCount(Object elementOrTreePath, int count)
elementOrTreePath
- the element, or tree pathcount
- public void replace(Object parentElementOrTreePath, int index, Object element)
This method should be called by implementers of ILazyTreeContentProvider to populate this viewer.
parentElementOrTreePath
- the parent of the element that should be updated, or the tree
path to that parentindex
- the index in the parent's childrenelement
- the new elementsetChildCount(Object, int)
,
ILazyTreeContentProvider
,
ILazyTreePathContentProvider
public boolean isExpandable(Object element)
AbstractTreeViewer
ITreePathContentProvider
.
The default implementation of this framework method calls
hasChildren
on this viewer's content provider. It may be
overridden if necessary.
isExpandable
in class AbstractTreeViewer
element
- the element or pathtrue
if the tree node representing the given
element can be expanded, or false
if notAbstractTreeViewer.setExpandPreCheckFilters(boolean)
protected Object getParentElement(Object element)
AbstractTreeViewer
null
if the parent is not known. If the argument is a tree path with more than
one segment, returns its parent tree path, otherwise returns
null
.getParentElement
in class AbstractTreeViewer
null
protected void internalAdd(Widget widget, Object parentElement, Object[] childElements)
AbstractTreeViewer
EXPERIMENTAL. Not to be used except by JDT. This method was added to support JDT's explorations into grouping by working sets. This method cannot be removed without breaking binary backwards compatibility, but should not be called by clients.
internalAdd
in class AbstractTreeViewer
widget
- the widget for the parent elementparentElement
- the parent elementchildElements
- the child elements to addprotected void internalRefreshStruct(Widget widget, Object element, boolean updateLabels)
AbstractTreeViewer
protected void mapElement(Object element, Widget item)
StructuredViewer
This method is internal to the framework; subclassers should not call this method.
mapElement
in class StructuredViewer
element
- the elementitem
- the corresponding widgetprotected ViewerRow getViewerRowFromItem(Widget item)
ColumnViewer
ViewerRow
associated with the given row widget.
Implementations may re-use the same instance for different row widgets;
callers can only use the viewer row locally and until the next call to
this method.getViewerRowFromItem
in class AbstractTreeViewer
item
- the row widgetprotected void internalInitializeTree(Control widget)
AbstractTreeViewer
internalInitializeTree
in class AbstractTreeViewer
widget
- the tree controlprotected void updatePlus(Item item, Object element)
AbstractTreeViewer
isExpandable
to determine whether an element is
expandable.updatePlus
in class AbstractTreeViewer
item
- the itemelement
- the elementpublic void remove(Object parentOrTreePath, int index)
parentOrTreePath
- the parent element, the input element, or a tree path to the parent elementindex
- child indexprotected void handleTreeExpand(TreeEvent event)
AbstractTreeViewer
handleTreeExpand
in class AbstractTreeViewer
event
- the SWT tree eventprotected void handleTreeCollapse(TreeEvent event)
AbstractTreeViewer
handleTreeCollapse
in class AbstractTreeViewer
event
- the SWT tree eventpublic void setContentProvider(IContentProvider provider)
AbstractTreeViewer
AbstractTreeViewer
implementation of this method
checks to ensure that the content provider is an
ITreeContentProvider
.setContentProvider
in class AbstractTreeViewer
provider
- the content providerContentViewer.getContentProvider()
public void setHasChildren(Object elementOrTreePath, boolean hasChildren)
elementOrTreePath
- the element, or tree pathhasChildren
- protected void disassociate(Item item)
AbstractTreeViewer
AbstractTreeViewer
implementation of this method also
recurses over children of the corresponding element.disassociate
in class AbstractTreeViewer
item
- the widgetprotected int doGetColumnCount()
AbstractTreeViewer
Subclasses should overwrite this method, which has a default implementation (returning 0) for API backwards compatility reasons
doGetColumnCount
in class AbstractTreeViewer
public void setSelection(ISelection selection, boolean reveal)
Currently the reveal
parameter is not honored because
Tree
does not provide an API to only select an item without
scrolling it into view
setSelection
in class StructuredViewer
selection
- the new selectionreveal
- true
if the selection is to be made visible,
and false
otherwisepublic void editElement(Object element, int column)
ColumnViewer
editElement
in class ColumnViewer
element
- the model elementcolumn
- the column index
Copyright (c) 2000, 2014 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.