Class AbstractTreeViewer
- java.lang.Object
-
- org.eclipse.jface.viewers.Viewer
-
- org.eclipse.jface.viewers.ContentViewer
-
- org.eclipse.jface.viewers.StructuredViewer
-
- org.eclipse.jface.viewers.ColumnViewer
-
- org.eclipse.jface.viewers.AbstractTreeViewer
-
- All Implemented Interfaces:
IInputProvider,IInputSelectionProvider,IPostSelectionProvider,ISelectionProvider
- Direct Known Subclasses:
TreeViewer
public abstract class AbstractTreeViewer extends ColumnViewer
Abstract base implementation for tree-structure-oriented viewers (trees and table trees).Nodes in the tree can be in either an expanded or a collapsed state, depending on whether the children on a node are visible. This class introduces public methods for controlling the expanding and collapsing of nodes.
As of 3.2, AbstractTreeViewer 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 abstract tree viewers must implement one of the interfaces
ITreeContentProvideror (as of 3.2, to support multiple equal elements)ITreePathContentProvider.This class is not intended to be subclassed outside of the JFace viewers framework.
- See Also:
TreeViewer
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.jface.viewers.StructuredViewer
StructuredViewer.ColorAndFontCollector, StructuredViewer.ColorAndFontCollectorWithProviders
-
-
Field Summary
Fields Modifier and Type Field Description static intALL_LEVELSConstant indicating that all levels of the tree should be expanded or collapsed.-
Fields inherited from class org.eclipse.jface.viewers.Viewer
WIDGET_DATA_KEY
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractTreeViewer()Creates an abstract tree viewer.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidadd(Object parentElementOrTreePath, Object childElement)Adds the given child element to this viewer as a child of the given parent element.voidadd(Object parentElementOrTreePath, Object... childElements)Adds the given child elements to this viewer as children of the given parent element.protected voidaddSelectionListener(Control control, SelectionListener listener)Deprecated.voidaddTreeListener(ITreeViewerListener listener)Adds a listener for expand and collapse events in this viewer.protected abstract voidaddTreeListener(Control control, TreeListener listener)Adds the given SWT tree listener to the given SWT control.protected voidassertContentProviderType(IContentProvider provider)Assert that the content provider is of one of the supported types.protected voidassociate(Object element, Item item)Associates the given element with the given widget.protected voidbuildLabel(ViewerLabel updateLabel, Object elementOrPath)This implementation of buildLabel handles tree paths as well as elements.voidcollapseAll()Collapses all nodes of the viewer's tree, starting with the root.voidcollapseToLevel(Object elementOrTreePath, int level)Collapses the subtree rooted at the given element or tree path to the given level.protected voidcreateChildren(Widget widget)Creates all children for the given widget.protected voidcreateTreeItem(Widget parent, Object element, int index)Creates a single item for the given parent and synchronizes it with the given element.protected ColumnViewerEditorcreateViewerEditor()This implementation ofcreateViewerEditor()returns null to ensure API backwards compatibility.protected voiddisassociate(Item item)TheAbstractTreeViewerimplementation of this method also recurses over children of the corresponding element.protected WidgetdoFindInputItem(Object element)Returns the widget in this viewer's control which represents the given element if it is the viewer's input.protected WidgetdoFindItem(Object element)Returns the widget in this viewer's control which represent the given element.protected intdoGetColumnCount()Returns the number of columns of this viewer.protected voiddoUpdateItem(Item item, Object element)Copies the attributes of the given element into the given SWT item.protected voiddoUpdateItem(Widget widget, Object element, boolean fullMap)Copies the attributes of the given element into the given SWT item.voidexpandAll()Expands all nodes of the viewer's tree, starting with the root.voidexpandAll(boolean disableRedraw)Expands all nodes of the viewer's tree, starting with the root.voidexpandToLevel(int level)Expands the root of the viewer's tree to the given level.voidexpandToLevel(int level, boolean disableRedraw)Expands the root of the viewer's tree to the given level.voidexpandToLevel(Object elementOrTreePath, int level)Expands all ancestors of the given element or tree path so that the given element becomes visible in this viewer's tree control, and then expands the subtree rooted at the given element to the given level.voidexpandToLevel(Object elementOrTreePath, int level, boolean disableRedraw)Expands all ancestors of the given element or tree path so that the given element becomes visible in this viewer's tree control, and then expands the subtree rooted at the given element to the given level.protected voidfireTreeCollapsed(TreeExpansionEvent event)Fires a tree collapsed event.protected voidfireTreeExpanded(TreeExpansionEvent event)Fires a tree expanded event.intgetAutoExpandLevel()Returns the auto-expand level.protected ItemgetChild(Widget widget, int index)Get the child for the widget at index.protected abstract Item[]getChildren(Widget widget)Returns the SWT child items for the given SWT widget.Item[]getChildren(Widget widget, Object[] elementChildren)Deprecated.This method was inadvertently released as API but is not intended to be called by clients.protected WidgetgetColumnViewerOwner(int columnIndex)Returns the column widget at the given column index.protected abstract booleangetExpanded(Item item)Returns whether the given SWT item is expanded or collapsed.Object[]getExpandedElements()Returns a list of elements corresponding to expanded nodes in this viewer's tree, including currently hidden ones that are marked as expanded but are under a collapsed ancestor.booleangetExpandedState(Object elementOrTreePath)Returns whether the node corresponding to the given element or tree path is expanded or collapsed.TreePath[]getExpandedTreePaths()Returns a list of tree paths corresponding to expanded nodes in this viewer's tree, including currently hidden ones that are marked as expanded but are under a collapsed ancestor.protected ItemgetItemAt(Point point)This implementation ofgetItemAt(Point)returns null to ensure API backwards compatibility.protected abstract intgetItemCount(Control control)Returns the number of child items of the given SWT control.protected abstract intgetItemCount(Item item)Returns the number of child items of the given SWT item.protected abstract Item[]getItems(Item item)Returns the child items of the given SWT item.protected ItemgetNextItem(Item item, boolean includeChildren)Returns the item after the given item in the tree, ornullif there is no next item.protected ObjectgetParentElement(Object elementOrTreePath)This method takes a tree path or an element.protected abstract ItemgetParentItem(Item item)Returns the parent item of the given item in the tree, ornullif there is no parent item.protected ItemgetPreviousItem(Item item)Returns the item before the given item in the tree, ornullif there is no previous item.protected Object[]getRawChildren(Object parentElementOrTreePath)Returns the children of the given parent without sorting and filtering them.ISelectiongetSelection()TheAbstractTreeViewerimplementation of this method returns the result as anITreeSelection.protected abstract Item[]getSelection(Control control)Returns all selected items for the given SWT control.protected ListgetSelectionFromWidget()Retrieves the selection, as aList, from the underlying widget.protected Object[]getSortedChildren(Object parentElementOrTreePath)Returns the sorted and filtered set of children of the given element.ITreeSelectiongetStructuredSelection()Returns theITreeSelectionof this viewer.protected TreePathgetTreePathFromItem(Item item)Returns the tree path for the given item.protected ViewerRowgetViewerRowFromItem(Widget item)Returns aViewerRowassociated with the given row widget.Object[]getVisibleExpandedElements()Gets the expanded elements that are visible to the user.protected voidhandleDoubleSelect(SelectionEvent event)Handles a double-click select event from the widget.protected voidhandleTreeCollapse(TreeEvent event)Handles a tree collapse event from the SWT widget.protected voidhandleTreeExpand(TreeEvent event)Handles a tree expand event from the SWT widget.protected voidhookControl(Control control)Adds event listener hooks to the given control.protected intindexForElement(Widget parent, Object element)Returns the index where the item should be inserted.protected voidinputChanged(Object input, Object oldInput)Internal hook method called when the input to this viewer is initially set or subsequently changed.voidinsert(Object parentElementOrTreePath, Object element, int position)Inserts the given element as a new child element of the given parent element at the given position.protected voidinternalAdd(Widget widget, Object parentElementOrTreePath, Object[] childElements)Adds the given child elements to this viewer as children of the given parent element.protected voidinternalCollapseToLevel(Widget widget, int level)Recursively collapses the subtree rooted at the given widget to the given level.protected WidgetinternalExpand(Object elementOrPath, boolean expand)Tries to create a path of tree items for the given element or tree path.protected voidinternalExpandToLevel(Widget widget, int level)Recursively expands the subtree rooted at the given widget to the given level.protected Widget[]internalFindItems(Object parentElementOrTreePath)Find the items for the given element of tree pathprotected WidgetinternalGetWidgetToSelect(Object elementOrTreePath)Returns the widget to be selected for the given element or tree path.protected voidinternalInitializeTree(Control tree)Initializes the tree with root items, expanding to the appropriate level if necessary.protected booleaninternalIsInputOrEmptyPath(Object elementOrTreePath)Returns true if the given object is either the input or an empty tree path.protected voidinternalRefresh(Object element)Refreshes this viewer starting at the given element.protected voidinternalRefresh(Object element, boolean updateLabels)Refreshes this viewer starting at the given element.protected voidinternalRefresh(Widget widget, Object element, boolean doStruct, boolean updateLabels)Refreshes the tree starting at the given widget.protected voidinternalRemove(Object[] elementsOrPaths)Removes the given elements from this viewer.protected voidinternalRemove(Object parent, Object[] elements)Removes the given elements from this viewer, whenever those elements appear as children of the given parent.booleanisExpandable(Object elementOrTreePath)Return whether the tree node representing the given element or path can be expanded.protected booleanisSameSelection(List<Item> items, Item[] current)Returnstrueif the given list and array of items refer to the same model elements.protected voidlabelProviderChanged()Notifies that the label provider has changed.protected abstract ItemnewItem(Widget parent, int style, int index)Creates a new item.voidremove(Object elementsOrTreePaths)Removes the given element from the viewer.voidremove(Object... elementsOrTreePaths)Removes the given elements from this viewer.voidremove(Object parent, Object... elements)Removes the given elements from this viewer whenever they appear as children of the given parent element.protected abstract voidremoveAll(Control control)Removes all items from the given control.voidremoveTreeListener(ITreeViewerListener listener)Removes a listener for expand and collapse events in this viewer.voidreveal(Object elementOrTreePath)This implementation of reveal() reveals the given element or tree path.ItemscrollDown(int x, int y)Scrolls the viewer's control down by one item from the given display-relative coordinates.ItemscrollUp(int x, int y)Scrolls the viewer's control up by one item from the given display-relative coordinates.voidsetAutoExpandLevel(int level)Sets the auto-expand level to be used when the input of the viewer is set usingStructuredViewer.setInput(Object).voidsetContentProvider(IContentProvider provider)Sets the content provider used by thisAbstractTreeViewer.protected abstract voidsetExpanded(Item item, boolean expand)Sets the expand state of the given item.voidsetExpandedElements(Object... elements)Sets which nodes are expanded in this viewer's tree.voidsetExpandedState(Object elementOrTreePath, boolean expanded)Sets whether the node corresponding to the given element or tree path is expanded or collapsed.voidsetExpandedTreePaths(TreePath... treePaths)Sets which nodes are expanded in this viewer's tree.voidsetExpandPreCheckFilters(boolean checkFilters)InstructsisExpandable(Object)to consult filters to more accurately determine if an item can be expanded.protected abstract voidsetSelection(List<Item> items)Sets the selection to the given list of items.protected voidsetSelectionToWidget(List v, boolean reveal)This implementation of setSelectionToWidget accepts a list of elements or a list of tree paths.protected voidsetSelectionToWidget(ISelection selection, boolean reveal)Converts the selection to aListand callssetSelectionToWidget(List, boolean).protected abstract voidshowItem(Item item)Shows the given item.protected voidupdateChildren(Widget widget, Object parent, Object[] elementChildren)Deprecated.this is no longer called by the frameworkprotected voidupdatePlus(Item item, Object element)Updates the "+"/"-" icon of the tree node from the given element.-
Methods inherited from class org.eclipse.jface.viewers.ColumnViewer
applyEditorValue, cancelEditing, checkBusy, editElement, getCell, getCellEditors, getCellModifier, getColumnProperties, getColumnViewerEditor, getItem, getLabelProvider, getViewerRow, handleDispose, hookEditingSupport, isBusy, isCellEditorActive, refresh, refresh, setBusy, setCellEditors, setCellModifier, setColumnProperties, setColumnViewerEditor, setLabelProvider, triggerEditorActivationEvent, update
-
Methods inherited from class org.eclipse.jface.viewers.StructuredViewer
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, mapElement, needsRefilter, preservingSelection, refresh, refresh, refreshItem, removeDoubleClickListener, removeFilter, removeOpenListener, removePostSelectionChangedListener, resetFilters, setComparator, setComparer, setFilters, setInput, setSelection, setSorter, setUseHashlookup, testFindItem, testFindItems, unmapAllElements, unmapElement, unmapElement, update, updateItem, updateSelection, usingElementMap
-
Methods inherited from class org.eclipse.jface.viewers.ContentViewer
getContentProvider, getInput, getLabelProvider
-
Methods inherited from class org.eclipse.jface.viewers.Viewer
addHelpListener, addSelectionChangedListener, fireHelpRequested, fireSelectionChanged, getControl, getData, handleHelpRequest, removeHelpListener, removeSelectionChangedListener, setData, setSelection
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.jface.viewers.ISelectionProvider
addSelectionChangedListener, removeSelectionChangedListener, setSelection
-
-
-
-
Method Detail
-
add
public void add(Object parentElementOrTreePath, Object... childElements)
Adds the given child elements to this viewer as children of the given parent element. If this viewer does not have a sorter, the elements are added at the end of the parent's list of children in the order given; otherwise, the elements are inserted at the appropriate positions.This method should be called (by the content provider) when elements have been added to the model, in order to cause the viewer to accurately reflect the model. This method only affects the viewer, not the model.
- Parameters:
parentElementOrTreePath- the parent elementchildElements- the child elements to add
-
internalFindItems
protected final Widget[] internalFindItems(Object parentElementOrTreePath)
Find the items for the given element of tree path- Parameters:
parentElementOrTreePath- the element or tree path- Returns:
- the items for that element
- Since:
- 3.3
-
internalAdd
protected void internalAdd(Widget widget, Object parentElementOrTreePath, Object[] childElements)
Adds the given child elements to this viewer as children of the given parent element.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.
- Parameters:
widget- the widget for the parent elementparentElementOrTreePath- the parent elementchildElements- the child elements to add- Since:
- 3.1
-
indexForElement
protected int indexForElement(Widget parent, Object element)
Returns the index where the item should be inserted.- Parameters:
parent- The parent widget the element will be inserted into.element- The element to insert.- Returns:
- the index of the element
-
getSortedChildren
protected Object[] getSortedChildren(Object parentElementOrTreePath)
Description copied from class:StructuredViewerReturns the sorted and filtered set of children of the given element. The resulting array must not be modified, as it may come directly from the model's internal state.- Overrides:
getSortedChildrenin classStructuredViewer- Parameters:
parentElementOrTreePath- the parent element- Returns:
- a sorted and filtered array of child elements
-
add
public void add(Object parentElementOrTreePath, Object childElement)
Adds the given child element to this viewer as a child of the given parent element. If this viewer does not have a sorter, the element is added at the end of the parent's list of children; otherwise, the element is inserted at the appropriate position.This method should be called (by the content provider) when a single element has been added to the model, in order to cause the viewer to accurately reflect the model. This method only affects the viewer, not the model. Note that there is another method for efficiently processing the simultaneous addition of multiple elements.
- Parameters:
parentElementOrTreePath- the parent element or pathchildElement- the child element
-
addSelectionListener
@Deprecated protected void addSelectionListener(Control control, SelectionListener listener)
Deprecated.Adds the given SWT selection listener to the given SWT control.- Parameters:
control- the SWT controllistener- the SWT selection listener
-
addTreeListener
public void addTreeListener(ITreeViewerListener listener)
Adds a listener for expand and collapse events in this viewer. Has no effect if an identical listener is already registered.- Parameters:
listener- a tree viewer listener
-
addTreeListener
protected abstract void addTreeListener(Control control, TreeListener listener)
Adds the given SWT tree listener to the given SWT control.- Parameters:
control- the SWT controllistener- the SWT tree listener
-
associate
protected void associate(Object element, Item item)
Description copied from class:StructuredViewerAssociates the given element with the given widget. Sets the given item's data to be the element, and maps the element to the item in the element map (if enabled).- Overrides:
associatein classStructuredViewer- Parameters:
element- the elementitem- the widget
-
collapseAll
public void collapseAll()
Collapses all nodes of the viewer's tree, starting with the root. This method is equivalent tocollapseToLevel(ALL_LEVELS).
-
collapseToLevel
public void collapseToLevel(Object elementOrTreePath, int level)
Collapses the subtree rooted at the given element or tree path to the given level.- Parameters:
elementOrTreePath- the element or tree pathlevel- non-negative level, orALL_LEVELSto collapse all levels of the tree
-
createChildren
protected void createChildren(Widget widget)
Creates all children for the given widget.The default implementation of this framework method assumes that
widget.getData()returns the element corresponding to the node. Note: the node is not visually expanded! You may have to callparent.setExpanded(true).- Parameters:
widget- the widget
-
createTreeItem
protected void createTreeItem(Widget parent, Object element, int index)
Creates a single item for the given parent and synchronizes it with the given element.- Parameters:
parent- the parent widgetelement- the elementindex- if non-negative, indicates the position to insert the item into its parent
-
disassociate
protected void disassociate(Item item)
TheAbstractTreeViewerimplementation of this method also recurses over children of the corresponding element.- Overrides:
disassociatein classStructuredViewer- Parameters:
item- the widget
-
doFindInputItem
protected Widget doFindInputItem(Object element)
Description copied from class:StructuredViewerReturns the widget in this viewer's control which represents the given element if it is the viewer's input.This method is internal to the framework; subclassers should not call this method.
- Specified by:
doFindInputItemin classStructuredViewer- Returns:
- the corresponding widget, or
nullif none
-
doFindItem
protected Widget doFindItem(Object element)
Description copied from class:StructuredViewerReturns the widget in this viewer's control which represent the given element. This method searches all the children of the input element.This method is internal to the framework; subclassers should not call this method.
- Specified by:
doFindItemin classStructuredViewer- Returns:
- the corresponding widget, or
nullif none
-
doUpdateItem
protected void doUpdateItem(Item item, Object element)
Copies the attributes of the given element into the given SWT item.- Parameters:
item- the SWT itemelement- the element
-
isSameSelection
protected boolean isSameSelection(List<Item> items, Item[] current)
Returnstrueif the given list and array of items refer to the same model elements. Order is unimportant.This method is not intended to be overridden by subclasses.
- Parameters:
items- the list of itemscurrent- the array of items- Returns:
trueif the refer to the same elements,falseotherwise- Since:
- 3.1 in TreeViewer, moved to AbstractTreeViewer in 3.3
-
doUpdateItem
protected void doUpdateItem(Widget widget, Object element, boolean fullMap)
Description copied from class:StructuredViewerCopies the attributes of the given element into the given SWT item. The element map is updated according to the value offullMap. IffullMapistruethen the current mapping from element to widgets is removed and the new mapping is added. If full map isfalsethen only the new map gets installed. Installing only the new map is necessary in cases where only the order of elements changes but not the set of elements.This method is internal to the framework; subclassers should not call this method.
- Specified by:
doUpdateItemin classStructuredViewerelement- elementfullMap-trueif mappings are added and removed, andfalseif only the new map gets installed
-
expandAll
public void expandAll()
Expands all nodes of the viewer's tree, starting with the root. This method is equivalent toexpandToLevel(ALL_LEVELS).
-
expandAll
public void expandAll(boolean disableRedraw)
Expands all nodes of the viewer's tree, starting with the root. This method is equivalent toexpandToLevel(ALL_LEVELS).- Parameters:
disableRedraw-truewhen drawing operations should be disabled during expansion.- Since:
- 3.14
-
expandToLevel
public void expandToLevel(int level)
Expands the root of the viewer's tree to the given level.- Parameters:
level- non-negative level, orALL_LEVELSto expand all levels of the tree
-
expandToLevel
public void expandToLevel(int level, boolean disableRedraw)Expands the root of the viewer's tree to the given level.- Parameters:
level- non-negative level, orALL_LEVELSto expand all levels of the treedisableRedraw-truewhen drawing operations should be disabled during expansion.- Since:
- 3.14
-
expandToLevel
public void expandToLevel(Object elementOrTreePath, int level)
Expands all ancestors of the given element or tree path so that the given element becomes visible in this viewer's tree control, and then expands the subtree rooted at the given element to the given level.- Parameters:
elementOrTreePath- the elementlevel- non-negative level, orALL_LEVELSto expand all levels of the tree
-
expandToLevel
public void expandToLevel(Object elementOrTreePath, int level, boolean disableRedraw)
Expands all ancestors of the given element or tree path so that the given element becomes visible in this viewer's tree control, and then expands the subtree rooted at the given element to the given level.- Parameters:
elementOrTreePath- the elementlevel- non-negative level, orALL_LEVELSto expand all levels of the treedisableRedraw-truewhen drawing operations should be disabled during expansion.- Since:
- 3.14
-
fireTreeCollapsed
protected void fireTreeCollapsed(TreeExpansionEvent event)
Fires a tree collapsed event. Only listeners registered at the time this method is called are notified.- Parameters:
event- the tree expansion event- See Also:
ITreeViewerListener.treeCollapsed(org.eclipse.jface.viewers.TreeExpansionEvent)
-
fireTreeExpanded
protected void fireTreeExpanded(TreeExpansionEvent event)
Fires a tree expanded event. Only listeners registered at the time this method is called are notified.- Parameters:
event- the tree expansion event- See Also:
ITreeViewerListener.treeExpanded(org.eclipse.jface.viewers.TreeExpansionEvent)
-
getAutoExpandLevel
public int getAutoExpandLevel()
Returns the auto-expand level.- Returns:
- non-negative level, or
ALL_LEVELSif all levels of the tree are expanded automatically - See Also:
setAutoExpandLevel(int)
-
getChildren
protected abstract Item[] getChildren(Widget widget)
Returns the SWT child items for the given SWT widget.- Parameters:
widget- the widget- Returns:
- the child items
-
getChild
protected Item getChild(Widget widget, int index)
Get the child for the widget at index. Note that the default implementation is not very efficient and should be overridden if this class is implemented.- Parameters:
widget- the widget to checkindex- the index of the widget- Returns:
- Item or
nullif widget is not a type that can contain items. - Throws:
ArrayIndexOutOfBoundsException- if the index is not valid.- Since:
- 3.1
-
getExpanded
protected abstract boolean getExpanded(Item item)
Returns whether the given SWT item is expanded or collapsed.- Parameters:
item- the item- Returns:
trueif the item is considered expanded andfalseif collapsed
-
getExpandedElements
public Object[] getExpandedElements()
Returns a list of elements corresponding to expanded nodes in this viewer's tree, including currently hidden ones that are marked as expanded but are under a collapsed ancestor.This method is typically used when preserving the interesting state of a viewer;
setExpandedElementsis used during the restore.- Returns:
- the array of expanded elements
- See Also:
setExpandedElements(java.lang.Object...)
-
getExpandedState
public boolean getExpandedState(Object elementOrTreePath)
Returns whether the node corresponding to the given element or tree path is expanded or collapsed.- Parameters:
elementOrTreePath- the element- Returns:
trueif the node is expanded, andfalseif collapsed
-
getItemCount
protected abstract int getItemCount(Control control)
Returns the number of child items of the given SWT control.- Parameters:
control- the control- Returns:
- the number of children
-
getItemCount
protected abstract int getItemCount(Item item)
Returns the number of child items of the given SWT item.- Parameters:
item- the item- Returns:
- the number of children
-
getItems
protected abstract Item[] getItems(Item item)
Returns the child items of the given SWT item.- Parameters:
item- the item- Returns:
- the child items
-
getNextItem
protected Item getNextItem(Item item, boolean includeChildren)
Returns the item after the given item in the tree, ornullif there is no next item.- Parameters:
item- the itemincludeChildren-trueif the children are considered in determining which item is next, andfalseif subtrees are ignored- Returns:
- the next item, or
nullif none
-
getParentItem
protected abstract Item getParentItem(Item item)
Returns the parent item of the given item in the tree, ornullif there is no parent item.- Parameters:
item- the item- Returns:
- the parent item, or
nullif none
-
getPreviousItem
protected Item getPreviousItem(Item item)
Returns the item before the given item in the tree, ornullif there is no previous item.- Parameters:
item- the item- Returns:
- the previous item, or
nullif none
-
getRawChildren
protected Object[] getRawChildren(Object parentElementOrTreePath)
Description copied from class:StructuredViewerReturns the children of the given parent without sorting and filtering them. The resulting array must not be modified, as it may come directly from the model's internal state.Returns an empty array if the given parent is
null.- Overrides:
getRawChildrenin classColumnViewer- Parameters:
parentElementOrTreePath- the parent element- Returns:
- the child elements
-
getSelection
protected abstract Item[] getSelection(Control control)
Returns all selected items for the given SWT control.- Parameters:
control- the control- Returns:
- the list of selected items
-
getSelectionFromWidget
protected List getSelectionFromWidget()
Description copied from class:StructuredViewerRetrieves the selection, as aList, from the underlying widget.- Specified by:
getSelectionFromWidgetin classStructuredViewer- Returns:
- the list of selected elements
-
handleDoubleSelect
protected void handleDoubleSelect(SelectionEvent event)
Description copied from class:StructuredViewerHandles a double-click select event from the widget.This method is internal to the framework; subclassers should not call this method.
- Overrides:
handleDoubleSelectin classStructuredViewer- Parameters:
event- the SWT selection event
-
handleTreeCollapse
protected void handleTreeCollapse(TreeEvent event)
Handles a tree collapse event from the SWT widget.- Parameters:
event- the SWT tree event
-
handleTreeExpand
protected void handleTreeExpand(TreeEvent event)
Handles a tree expand event from the SWT widget.- Parameters:
event- the SWT tree event
-
hookControl
protected void hookControl(Control control)
Description copied from class:ContentViewerAdds event listener hooks to the given control.All subclasses must call this method when their control is first established.
The
ContentViewerimplementation of this method hooks dispose events for the given control. Subclasses may override if they need to add other control hooks; however,super.hookControlmust be invoked.- Overrides:
hookControlin classColumnViewer- Parameters:
control- the control
-
inputChanged
protected void inputChanged(Object input, Object oldInput)
Description copied from class:ViewerInternal hook method called when the input to this viewer is initially set or subsequently changed.The default implementation does nothing. Subclassers may override this method to do something when a viewer's input is set. A typical use is populate the viewer.
- Overrides:
inputChangedin classViewer- Parameters:
input- the new input of this viewer, ornullif noneoldInput- the old input element ornullif there was previously no input
-
internalInitializeTree
protected void internalInitializeTree(Control tree)
Initializes the tree with root items, expanding to the appropriate level if necessary.- Parameters:
tree- the tree control- Since:
- 3.3
-
internalCollapseToLevel
protected void internalCollapseToLevel(Widget widget, int level)
Recursively collapses the subtree rooted at the given widget to the given level.Note that the default implementation of this method does not call
setRedraw.- Parameters:
widget- the widgetlevel- non-negative level, orALL_LEVELSto collapse all levels of the tree
-
internalExpand
protected Widget internalExpand(Object elementOrPath, boolean expand)
Tries to create a path of tree items for the given element or tree path. This method recursively walks up towards the root of the tree and in the case of an element (rather than a tree path) assumes thatgetParentreturns the correct parent of an element.- Parameters:
elementOrPath- the elementexpand-trueif all nodes on the path should be expanded, andfalseotherwise- Returns:
- Widget
-
getParentElement
protected Object getParentElement(Object elementOrTreePath)
This method takes a tree path or an element. If the argument is not a tree path, returns the parent of the given element ornullif the parent is not known. If the argument is a tree path with more than one segment, returns its parent tree path, otherwise returnsnull.- Parameters:
elementOrTreePath-- Returns:
- the parent element, or parent path, or
null - Since:
- 3.2
-
internalGetWidgetToSelect
protected Widget internalGetWidgetToSelect(Object elementOrTreePath)
Returns the widget to be selected for the given element or tree path.- Parameters:
elementOrTreePath- the element or tree path to select- Returns:
- the widget to be selected, or
nullif not found - Since:
- 3.1
-
internalExpandToLevel
protected void internalExpandToLevel(Widget widget, int level)
Recursively expands the subtree rooted at the given widget to the given level.Note that the default implementation of this method does not call
setRedraw.- Parameters:
widget- the widgetlevel- non-negative level, orALL_LEVELSto collapse all levels of the tree
-
internalRefresh
protected void internalRefresh(Object element)
Description copied from class:StructuredViewerRefreshes this viewer starting at the given element.- Specified by:
internalRefreshin classStructuredViewer- Parameters:
element- the element
-
internalRefresh
protected void internalRefresh(Object element, boolean updateLabels)
Description copied from class:StructuredViewerRefreshes this viewer starting at the given element. Labels are updated as described inrefresh(boolean updateLabels).The default implementation simply calls
internalRefresh(element), ignoringupdateLabels.If this method is overridden to do the actual refresh, then
internalRefresh(Object element)should simply callinternalRefresh(element, true).- Overrides:
internalRefreshin classStructuredViewer- Parameters:
element- the elementupdateLabels-trueto update labels for existing elements,falseto only update labels as needed, assuming that labels for existing elements are unchanged.
-
internalRefresh
protected void internalRefresh(Widget widget, Object element, boolean doStruct, boolean updateLabels)
Refreshes the tree starting at the given widget.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.
- Parameters:
widget- the widgetelement- the elementdoStruct-trueif structural changes are to be picked up, andfalseif only label provider changes are of interestupdateLabels-trueto update labels for existing elements,falseto only update labels as needed, assuming that labels for existing elements are unchanged.- Since:
- 3.1
-
internalRemove
protected void internalRemove(Object[] elementsOrPaths)
Removes the given elements from this viewer.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.
- Parameters:
elementsOrPaths- the elements or element paths to remove- Since:
- 3.1
-
internalRemove
protected void internalRemove(Object parent, Object[] elements)
Removes the given elements from this viewer, whenever those elements appear as children of the given parent.- Parameters:
parent- the parent elementelements- the elements to remove- Since:
- 3.1
-
isExpandable
public boolean isExpandable(Object elementOrTreePath)
Return whether the tree node representing the given element or path can be expanded. Clients should query expandability by path if the viewer's content provider is anITreePathContentProvider.The default implementation of this framework method calls
hasChildrenon this viewer's content provider. It may be overridden if necessary.- Parameters:
elementOrTreePath- the element or path- Returns:
trueif the tree node representing the given element can be expanded, orfalseif not- See Also:
setExpandPreCheckFilters(boolean)
-
labelProviderChanged
protected void labelProviderChanged()
Description copied from class:ContentViewerNotifies that the label provider has changed.The
ContentViewerimplementation of this method callsrefresh(). Subclasses may reimplement or extend.- Overrides:
labelProviderChangedin classContentViewer
-
newItem
protected abstract Item newItem(Widget parent, int style, int index)
Creates a new item.- Parameters:
parent- the parent widgetstyle- SWT style bitsindex- if non-negative, indicates the position to insert the item into its parent- Returns:
- the newly-created item
-
remove
public void remove(Object... elementsOrTreePaths)
Removes the given elements from this viewer. The selection is updated if required.This method should be called (by the content provider) when elements have been removed from the model, in order to cause the viewer to accurately reflect the model. This method only affects the viewer, not the model.
- Parameters:
elementsOrTreePaths- the elements to remove
-
remove
public void remove(Object parent, Object... elements)
Removes the given elements from this viewer whenever they appear as children of the given parent element. If the given elements also appear as children of some other parent, the other parent will remain unchanged. The selection is updated if required.This method should be called (by the content provider) when elements have been removed from the model, in order to cause the viewer to accurately reflect the model. This method only affects the viewer, not the model.
- Parameters:
parent- the parent of the elements to removeelements- the elements to remove- Since:
- 3.2
-
remove
public void remove(Object elementsOrTreePaths)
Removes the given element from the viewer. The selection is updated if necessary.This method should be called (by the content provider) when a single element has been removed from the model, in order to cause the viewer to accurately reflect the model. This method only affects the viewer, not the model. Note that there is another method for efficiently processing the simultaneous removal of multiple elements.
- Parameters:
elementsOrTreePaths- the element
-
removeAll
protected abstract void removeAll(Control control)
Removes all items from the given control.- Parameters:
control- the control
-
removeTreeListener
public void removeTreeListener(ITreeViewerListener listener)
Removes a listener for expand and collapse events in this viewer. Has no effect if an identical listener is not registered.- Parameters:
listener- a tree viewer listener
-
reveal
public void reveal(Object elementOrTreePath)
This implementation of reveal() reveals the given element or tree path.- Specified by:
revealin classStructuredViewer- Parameters:
elementOrTreePath- the element to reveal
-
scrollDown
public Item scrollDown(int x, int y)
Description copied from class:ViewerScrolls the viewer's control down by one item from the given display-relative coordinates. Returns the newly revealed Item, ornullif no scrolling occurred or if the viewer doesn't represent an item-based widget.- Overrides:
scrollDownin classViewer- Parameters:
x- horizontal coordinatey- vertical coordinate- Returns:
- the item scrolled down to
-
scrollUp
public Item scrollUp(int x, int y)
Description copied from class:ViewerScrolls the viewer's control up by one item from the given display-relative coordinates. Returns the newly revealed Item, ornullif no scrolling occurred or if the viewer doesn't represent an item-based widget.
-
setAutoExpandLevel
public void setAutoExpandLevel(int level)
Sets the auto-expand level to be used when the input of the viewer is set usingStructuredViewer.setInput(Object). The value 0 means that there is no auto-expand; 1 means that the invisible root element is expanded (since most concrete subclasses do not show the root element, there is usually no practical difference between using the values 0 and 1); 2 means that top-level elements are expanded, but not their children; 3 means that top-level elements are expanded, and their children, but not grandchildren; and so on.The value
ALL_LEVELSmeans that all subtrees should be expanded.Note that in previous releases, the Javadoc for this method had an off-by one error. See bug 177669 for details.
- Parameters:
level- non-negative level, orALL_LEVELSto expand all levels of the tree
-
setContentProvider
public void setContentProvider(IContentProvider provider)
Sets the content provider used by thisAbstractTreeViewer.Content providers for abstract tree viewers must implement either
ITreeContentProviderorITreePathContentProvider.- Overrides:
setContentProviderin classStructuredViewer- Parameters:
provider- the content provider- See Also:
ContentViewer.getContentProvider()
-
assertContentProviderType
protected void assertContentProviderType(IContentProvider provider)
Description copied from class:StructuredViewerAssert that the content provider is of one of the supported types.- Overrides:
assertContentProviderTypein classStructuredViewer
-
setExpanded
protected abstract void setExpanded(Item item, boolean expand)
Sets the expand state of the given item.- Parameters:
item- the itemexpand- the expand state of the item
-
setExpandedElements
public void setExpandedElements(Object... elements)
Sets which nodes are expanded in this viewer's tree. The given list contains the elements that are to be expanded; all other nodes are to be collapsed.This method is typically used when restoring the interesting state of a viewer captured by an earlier call to
getExpandedElements.- Parameters:
elements- the array of expanded elements- See Also:
getExpandedElements()
-
setExpandedTreePaths
public void setExpandedTreePaths(TreePath... treePaths)
Sets which nodes are expanded in this viewer's tree. The given list contains the tree paths that are to be expanded; all other nodes are to be collapsed.This method is typically used when restoring the interesting state of a viewer captured by an earlier call to
getExpandedTreePaths.- Parameters:
treePaths- the array of expanded tree paths- Since:
- 3.2
- See Also:
getExpandedTreePaths()
-
setExpandedState
public void setExpandedState(Object elementOrTreePath, boolean expanded)
Sets whether the node corresponding to the given element or tree path is expanded or collapsed.- Parameters:
elementOrTreePath- the elementexpanded-trueif the node is expanded, andfalseif collapsed
-
setSelection
protected abstract void setSelection(List<Item> items)
Sets the selection to the given list of items.- Parameters:
items- list of items (element type:org.eclipse.swt.widgets.Item)
-
setSelectionToWidget
protected void setSelectionToWidget(List v, boolean reveal)
This implementation of setSelectionToWidget accepts a list of elements or a list of tree paths.- Specified by:
setSelectionToWidgetin classStructuredViewer- Parameters:
v- list of selected elements (element type:Object) ornullif the selection is to be clearedreveal-trueif the selection is to be made visible, andfalseotherwise
-
showItem
protected abstract void showItem(Item item)
Shows the given item.- Parameters:
item- the item
-
updateChildren
@Deprecated protected void updateChildren(Widget widget, Object parent, Object[] elementChildren)
Deprecated.this is no longer called by the frameworkUpdates the tree items to correspond to the child elements of the given parent element. If null is passed for the children, this method obtains them (only if needed).- Parameters:
widget- the widgetparent- the parent elementelementChildren- the child elements, or null
-
getChildren
@Deprecated public Item[] getChildren(Widget widget, Object[] elementChildren)
Deprecated.This method was inadvertently released as API but is not intended to be called by clients.Not to be called by clients. Return the items to be refreshed as part of an update. elementChildren are the new elements.- Parameters:
widget-elementChildren-- Returns:
- Item[]
- Since:
- 3.4
-
updatePlus
protected void updatePlus(Item item, Object element)
Updates the "+"/"-" icon of the tree node from the given element. It callsisExpandableto determine whether an element is expandable.- Parameters:
item- the itemelement- the element
-
getVisibleExpandedElements
public Object[] getVisibleExpandedElements()
Gets the expanded elements that are visible to the user. An expanded element is only visible if the parent is expanded.- Returns:
- the visible expanded elements
- Since:
- 2.0
-
getTreePathFromItem
protected TreePath getTreePathFromItem(Item item)
Returns the tree path for the given item.- Parameters:
item-- Returns:
TreePath- Since:
- 3.2
-
getSelection
public ISelection getSelection()
TheAbstractTreeViewerimplementation of this method returns the result as anITreeSelection.Call
Subclasses do not typically override this method, but implementgetStructuredSelection()instead to get an instance ofITreeSelectiondirectly.getSelectionFromWidget(List)instead. If they override this method, they should return anITreeSelectionas well.- Specified by:
getSelectionin interfaceISelectionProvider- Overrides:
getSelectionin classStructuredViewer- Returns:
- ISelection
- Since:
- 3.2
-
getStructuredSelection
public ITreeSelection getStructuredSelection() throws ClassCastException
Returns theITreeSelectionof this viewer.Subclasses whose
getSelection()specifies to return a more specific type should also override this method and return that type.- Overrides:
getStructuredSelectionin classStructuredViewer- Returns:
- ITreeSelection
- Throws:
ClassCastException- if the selection of the viewer is not an instance of ITreeSelection- Since:
- 3.11
-
setSelectionToWidget
protected void setSelectionToWidget(ISelection selection, boolean reveal)
Description copied from class:StructuredViewerConverts the selection to aListand callssetSelectionToWidget(List, boolean). The selection is expected to be anIStructuredSelectionof elements. If not, the selection is cleared.Subclasses do not typically override this method, but implement
setSelectionToWidget(List, boolean)instead.- Overrides:
setSelectionToWidgetin classStructuredViewer- Parameters:
selection- an IStructuredSelection of elementsreveal-trueto reveal the first element in the selection, orfalseotherwise
-
getExpandedTreePaths
public TreePath[] getExpandedTreePaths()
Returns a list of tree paths corresponding to expanded nodes in this viewer's tree, including currently hidden ones that are marked as expanded but are under a collapsed ancestor.This method is typically used when preserving the interesting state of a viewer;
setExpandedElementsis used during the restore.- Returns:
- the array of expanded tree paths
- Since:
- 3.2
- See Also:
setExpandedElements(java.lang.Object...)
-
insert
public void insert(Object parentElementOrTreePath, Object element, int position)
Inserts the given element as a new child element of the given parent element at the given position. If this viewer has a sorter, the position is ignored and the element is inserted at the correct position in the sort order.This method should be called (by the content provider) when elements have been added to the model, in order to cause the viewer to accurately reflect the model. This method only affects the viewer, not the model.
- Parameters:
parentElementOrTreePath- the parent element, or the tree path to the parentelement- the elementposition- a 0-based position relative to the model, or -1 to indicate the last position- Since:
- 3.2
-
getColumnViewerOwner
protected Widget getColumnViewerOwner(int columnIndex)
Description copied from class:ColumnViewerReturns the column widget at the given column index.- Specified by:
getColumnViewerOwnerin classColumnViewer- Parameters:
columnIndex- the column index- Returns:
- Widget the column widget
-
getItemAt
protected Item getItemAt(Point point)
This implementation ofgetItemAt(Point)returns null to ensure API backwards compatibility. Subclasses should override.- Specified by:
getItemAtin classColumnViewer- Parameters:
point- the widget-relative coordinates- Returns:
- the
Itemat the coordinates ornullif there is no item at the given coordinates - Since:
- 3.3
-
createViewerEditor
protected ColumnViewerEditor createViewerEditor()
This implementation ofcreateViewerEditor()returns null to ensure API backwards compatibility. Subclasses should override.- Specified by:
createViewerEditorin classColumnViewer- Returns:
- the editor, or
nullif this viewer does not support editing cell contents. - Since:
- 3.3
-
doGetColumnCount
protected int doGetColumnCount()
Returns the number of columns of this viewer.Subclasses should overwrite this method, which has a default implementation (returning 0) for API backwards compatility reasons
- Specified by:
doGetColumnCountin classColumnViewer- Returns:
- the number of columns
- Since:
- 3.3
-
buildLabel
protected void buildLabel(ViewerLabel updateLabel, Object elementOrPath)
This implementation of buildLabel handles tree paths as well as elements.- Overrides:
buildLabelin classStructuredViewer- Parameters:
updateLabel- the ViewerLabel to collect the result inelementOrPath- the element or tree path for which a label should be built- See Also:
StructuredViewer.buildLabel(org.eclipse.jface.viewers.ViewerLabel, java.lang.Object)
-
internalIsInputOrEmptyPath
protected final boolean internalIsInputOrEmptyPath(Object elementOrTreePath)
Returns true if the given object is either the input or an empty tree path.- Parameters:
elementOrTreePath- an element which could either be the viewer's input, or a tree path- Returns:
trueif the given object is either the input or an empty tree path,falseotherwise.- Since:
- 3.3
-
getViewerRowFromItem
protected ViewerRow getViewerRowFromItem(Widget item)
Description copied from class:ColumnViewerReturns aViewerRowassociated 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.- Specified by:
getViewerRowFromItemin classColumnViewer- Parameters:
item- the row widget- Returns:
- ViewerRow a viewer row object
-
setExpandPreCheckFilters
public void setExpandPreCheckFilters(boolean checkFilters)
InstructsisExpandable(Object)to consult filters to more accurately determine if an item can be expanded.Setting this value to
truewill affect performance of the tree viewer.To improve performance, by default the tree viewer does not consult filters when determining if a tree node could be expanded.
- Parameters:
checkFilters-trueto instruct tree viewer to consult filters- Since:
- 3.8
- See Also:
isExpandable(Object)
-
-