|
Eclipse Platform 2.0 |
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object
|
+--org.eclipse.jface.viewers.Viewer
|
+--org.eclipse.jface.viewers.ContentViewer
|
+--org.eclipse.jface.viewers.StructuredViewer
|
+--org.eclipse.jface.viewers.AbstractTreeViewer
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.
Content providers for abstract tree viewers must implement the ITreeContentProvider
interface.
TreeViewer,
TableTreeViewer| Field Summary | |
static int |
ALL_LEVELS
Constant 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 | |
protected |
AbstractTreeViewer()
Creates an abstract tree viewer. |
| Method Summary | |
void |
add(Object parentElement,
Object childElement)
Adds the given child element to this viewer as a child of the given parent element. |
void |
add(Object parentElement,
Object[] childElements)
Adds the given child elements to this viewer as children of the given parent element. |
protected void |
addSelectionListener(Control control,
SelectionListener listener)
Deprecated. |
protected abstract void |
addTreeListener(Control control,
TreeListener listener)
Adds the given SWT tree listener to the given SWT control. |
void |
addTreeListener(ITreeViewerListener listener)
Adds a listener for expand and collapse events in this viewer. |
void |
collapseAll()
Collapses all nodes of the viewer's tree, starting with the root. |
void |
collapseToLevel(Object element,
int level)
Collapses the subtree rooted at the given element to the given level. |
protected void |
createChildren(Widget widget)
Creates all children for the given widget. |
protected void |
createTreeItem(Widget parent,
Object element,
int index)
Creates a single item for the given parent and synchronizes it with the given element. |
protected void |
disassociate(Item item)
The AbstractTreeViewer implementation of this method
also recurses over children of the corresponding element. |
protected Widget |
doFindInputItem(Object element)
Returns the widget in this viewer's control which represents the given element if it is the viewer's input. |
protected Widget |
doFindItem(Object element)
Returns the widget in this viewer's control which represent the given element. |
protected abstract void |
doUpdateItem(Item item,
Object element)
Copies the attributes of the given element into the given SWT item. |
protected void |
doUpdateItem(Widget widget,
Object element,
boolean fullMap)
Copies the attributes of the given element into the given SWT item. |
void |
expandAll()
Expands all nodes of the viewer's tree, starting with the root. |
void |
expandToLevel(int level)
Expands the root of the viewer's tree to the given level. |
void |
expandToLevel(Object element,
int level)
Expands all ancestors of the given element 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 void |
fireTreeCollapsed(TreeExpansionEvent event)
Fires a tree collapsed event. |
protected void |
fireTreeExpanded(TreeExpansionEvent event)
Fires a tree expanded event. |
int |
getAutoExpandLevel()
Returns the auto-expand level. |
protected abstract Item[] |
getChildren(Widget widget)
Returns the SWT child items for the given SWT widget. |
protected abstract boolean |
getExpanded(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. |
boolean |
getExpandedState(Object element)
Returns whether the node corresponding to the given element is expanded or collapsed. |
protected abstract int |
getItemCount(Control control)
Returns the number of child items of the given SWT control. |
protected abstract int |
getItemCount(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 Item |
getNextItem(Item item,
boolean includeChildren)
Returns the item after the given item in the tree, or null if there is no next item. |
protected abstract Item |
getParentItem(Item item)
Returns the parent item of the given item in the tree, or null if there is parent item. |
protected Item |
getPreviousItem(Item item)
Returns the item before the given item in the tree, or null if there is no previous item. |
protected Object[] |
getRawChildren(Object parent)
Returns the children of the given parent without sorting and filtering them. |
protected abstract Item[] |
getSelection(Control control)
Returns all selected items for the given SWT control. |
protected List |
getSelectionFromWidget()
Retrieves the selection, as a List, from the underlying widget. |
Object[] |
getVisibleExpandedElements()
Get the expanded elements that are visible to the user. |
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 |
inputChanged(Object input,
Object oldInput)
Internal hook method called when the input to this viewer is initially set or subsequently changed. |
protected void |
internalCollapseToLevel(Widget widget,
int level)
Recursively collapses the subtree rooted at the given widget to the given level. |
protected Widget |
internalExpand(Object element,
boolean expand)
Tries to create a path of tree items for the given element. |
protected void |
internalExpandToLevel(Widget widget,
int level)
Recursively expands the subtree rooted at the given widget to the given level. |
void |
internalRefresh(Object element)
Refreshes this viewer starting at the given element. |
boolean |
isExpandable(Object element)
Return whether the tree node representing the given element can be expanded. |
protected void |
labelProviderChanged()
Notifies that the label provider has changed. |
protected abstract Item |
newItem(Widget parent,
int style,
int index)
Creates a new item. |
void |
remove(Object element)
Removes the given element from the viewer. |
void |
remove(Object[] elements)
Removes the given elements from this viewer. |
protected abstract void |
removeAll(Control control)
Removes all items from the given control. |
void |
removeTreeListener(ITreeViewerListener listener)
Removes a listener for expand and collapse events in this viewer. |
void |
reveal(Object element)
Ensures that the given element is visible, scrolling the viewer if necessary. |
Item |
scrollDown(int x,
int y)
Scrolls the viewer's control down by one item from the given display-relative coordinates. |
Item |
scrollUp(int x,
int y)
Scrolls the viewer's control up by one item from the given display-relative coordinates. |
void |
setAutoExpandLevel(int level)
Sets the auto-expand level. |
void |
setContentProvider(IContentProvider provider)
The AbstractTreeViewer implementation of this method
checks to ensure that the content provider is an ITreeContentProvider. |
protected abstract void |
setExpanded(Item item,
boolean expand)
Sets the expand state of the given item. |
void |
setExpandedElements(Object[] elements)
Sets which nodes are expanded in this viewer's tree. |
void |
setExpandedState(Object element,
boolean expanded)
Sets whether the node corresponding to the given element is expanded or collapsed. |
protected abstract void |
setSelection(List items)
Sets the selection to the given list of items. |
protected void |
setSelectionToWidget(List v,
boolean reveal)
Parlays the given list of selected elements into selections on this viewer's control. |
protected abstract void |
showItem(Item item)
Shows the given item. |
protected void |
updateChildren(Widget widget,
Object parent,
Object[] elementChildren)
Updates the tree items to correspond to the child elements of the given parent element. |
protected void |
updatePlus(Item item,
Object element)
Updates the "+"/"-" icon of the tree node from the given element. |
| Methods inherited from class org.eclipse.jface.viewers.ContentViewer |
getContentProvider, getInput, getLabelProvider, handleDispose, setLabelProvider |
| 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 |
| Field Detail |
public static final int ALL_LEVELS
expandToLevel(int),
collapseToLevel(java.lang.Object, int),
Constant Field Values| Constructor Detail |
protected AbstractTreeViewer()
| Method Detail |
public void add(Object parentElement,
Object[] childElements)
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.
parentElement - the parent elementchildElements - the child elements to add
public void add(Object parentElement,
Object childElement)
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.
parentElement - the parent elementchildElement - the child element
protected void addSelectionListener(Control control,
SelectionListener listener)
control - the SWT controllistener - the SWT selection listenerpublic void addTreeListener(ITreeViewerListener listener)
listener - a tree viewer listener
protected abstract void addTreeListener(Control control,
TreeListener listener)
control - the SWT controllistener - the SWT tree listenerpublic void collapseAll()
collapseToLevel(ALL_LEVELS).
public void collapseToLevel(Object element,
int level)
element - the elementlevel - non-negative level, or ALL_LEVELS to collapse
all levels of the treeprotected void createChildren(Widget 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
call parent.setExpanded(true).
widget - the widget
protected void createTreeItem(Widget parent,
Object element,
int index)
parent - the parent widgetelement - the elementindex - if non-negative, indicates the position to insert the item
into its parentprotected void disassociate(Item item)
AbstractTreeViewer implementation of this method
also recurses over children of the corresponding element.
disassociate in class StructuredVieweritem - the widgetprotected Widget doFindInputItem(Object element)
StructuredViewerThis method is internal to the framework; subclassers should not call this method.
doFindInputItem in class StructuredViewernull if noneprotected Widget doFindItem(Object element)
StructuredViewerThis method is internal to the framework; subclassers should not call this method.
doFindItem in class StructuredViewernull if none
protected abstract void doUpdateItem(Item item,
Object element)
item - the SWT itemelement - the element
protected void doUpdateItem(Widget widget,
Object element,
boolean fullMap)
StructuredViewerfullMap.
If fullMap is true then the current mapping
from element to widgets is removed and the new mapping is added.
If fullmap is false then 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.
doUpdateItem in class StructuredViewerwidget - element - the elementfullMap - true if mappings are added and removed,
and false if only the new map gets installedpublic void expandAll()
expandToLevel(ALL_LEVELS).
public void expandToLevel(int level)
level - non-negative level, or ALL_LEVELS to expand
all levels of the tree
public void expandToLevel(Object element,
int level)
element - the elementlevel - non-negative level, or ALL_LEVELS to expand
all levels of the treeprotected void fireTreeCollapsed(TreeExpansionEvent event)
event - the tree expansion eventITreeViewerListener.treeCollapsed(org.eclipse.jface.viewers.TreeExpansionEvent)protected void fireTreeExpanded(TreeExpansionEvent event)
event - the tree expansion eventITreeViewerListener.treeExpanded(org.eclipse.jface.viewers.TreeExpansionEvent)public int getAutoExpandLevel()
EXPAND_ALL if
all levels of the tree are expanded automaticallysetAutoExpandLevel(int)protected abstract Item[] getChildren(Widget widget)
widget - the widget
protected abstract boolean getExpanded(Item item)
item - the item
true if the item is considered expanded
and false if collapsedpublic Object[] getExpandedElements()
This method is typically used when preserving the interesting
state of a viewer; setExpandedElements is used during the restore.
setExpandedElements(java.lang.Object[])public boolean getExpandedState(Object element)
element - the element
true if the node is expanded, and false if collapsedprotected abstract int getItemCount(Control control)
control - the control
protected abstract int getItemCount(Item item)
item - the item
protected abstract Item[] getItems(Item item)
item - the item
protected Item getNextItem(Item item,
boolean includeChildren)
null if there is no next item.
item - the itemincludeChildren - true if the children are
considered in determining which item is next, and false
if subtrees are ignored
null if noneprotected abstract Item getParentItem(Item item)
null if there is parent item.
item - the item
null if noneprotected Item getPreviousItem(Item item)
null if there is no previous item.
item - the item
null if noneprotected Object[] getRawChildren(Object parent)
StructuredViewer
Returns an empty array if the given parent is null.
getRawChildren in class StructuredViewerparent - the parent element
protected abstract Item[] getSelection(Control control)
control - the control
protected List getSelectionFromWidget()
StructuredViewerList, from the underlying widget.
getSelectionFromWidget in class StructuredViewerprotected void handleTreeCollapse(TreeEvent event)
event - the SWT tree eventprotected void handleTreeExpand(TreeEvent event)
event - the SWT tree eventprotected void hookControl(Control control)
ContentViewerAll 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 StructuredViewercontrol - the control
protected void inputChanged(Object input,
Object oldInput)
ViewerThe 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.
inputChanged in class Viewerinput - the new input of this viewer, or null if noneoldInput - the old input element or null if there
was previously no input
protected void internalCollapseToLevel(Widget widget,
int level)
Note that the default implementation of this method does not call
setRedraw.
widget - the widgetlevel - non-negative level, or ALL_LEVELS to collapse
all levels of the tree
protected Widget internalExpand(Object element,
boolean expand)
getParent returns the correct
parent of an element.
element - the elementexpand - true if all nodes on the path should be expanded,
and false otherwise
protected void internalExpandToLevel(Widget widget,
int level)
Note that the default implementation of this method does not call
setRedraw.
widget - the widgetlevel - non-negative level, or ALL_LEVELS to collapse
all levels of the treepublic void internalRefresh(Object element)
StructuredViewer
internalRefresh in class StructuredViewerelement - the elementpublic boolean isExpandable(Object element)
The default implementation of this framework method calls
hasChildren on this viewer's content provider.
It may be overridden if necessary.
element - the element
true if the tree node representing
the given element can be expanded, or false if notprotected void labelProviderChanged()
ContentViewer
The ContentViewer implementation of this method calls refresh().
Subclasses may reimplement or extend.
labelProviderChanged in class ContentViewer
protected abstract Item newItem(Widget parent,
int style,
int index)
parent - the parent widgetstyle - SWT style bitsindex - if non-negative, indicates the position to insert the item
into its parent
public void remove(Object[] elements)
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.
elements - the elements to removepublic void remove(Object element)
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.
element - the elementprotected abstract void removeAll(Control control)
control - the controlpublic void removeTreeListener(ITreeViewerListener listener)
listener - a tree viewer listenerpublic void reveal(Object element)
StructuredViewer
reveal in class StructuredViewerelement - the element to reveal
public Item scrollDown(int x,
int y)
Viewernull if no scrolling occurred or if the viewer
doesn't represent an item-based widget.
scrollDown in class Viewerx - horizontal coordinatey - vertical coordinate
public Item scrollUp(int x,
int y)
Viewernull if no scrolling occurred or if the viewer
doesn't represent an item-based widget.
scrollUp in class Viewerx - horizontal coordinatey - vertical coordinatepublic void setAutoExpandLevel(int level)
EXPAND_ALL means that all subtrees should be
expanded.
level - non-negative level, or EXPAND_ALL to expand
all levels of the treepublic void setContentProvider(IContentProvider provider)
AbstractTreeViewer implementation of this method
checks to ensure that the content provider is an ITreeContentProvider.
setContentProvider in class StructuredViewerprovider - the content providerContentViewer.getContentProvider()
protected abstract void setExpanded(Item item,
boolean expand)
item - the itemexpand - the expand state of the itempublic void setExpandedElements(Object[] elements)
This method is typically used when restoring the interesting
state of a viewer captured by an earlier call to getExpandedElements.
elements - the array of expanded elementsgetExpandedElements()
public void setExpandedState(Object element,
boolean expanded)
element - the elementexpanded - true if the node is expanded, and false if collapsedprotected abstract void setSelection(List items)
items - list of items (element type: org.eclipse.swt.widgets.Item)
protected void setSelectionToWidget(List v,
boolean reveal)
StructuredViewerSubclasses should override to set their selection based on the given list of elements.
setSelectionToWidget in class StructuredViewerv - list of selected elements (element type: Object)
or null if the selection is to be clearedreveal - true if the selection is to be made
visible, and false otherwiseprotected abstract void showItem(Item item)
item - the item
protected void updateChildren(Widget widget,
Object parent,
Object[] elementChildren)
widget - the widgetparent - the parent elementelementChildren - the child elements, or null
protected void updatePlus(Item item,
Object element)
isExpandable to determine whether
an element is expandable.
item - the itemelement - the elementpublic Object[] getVisibleExpandedElements()
|
Eclipse Platform 2.0 |
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||