Eclipse Platform
Release 3.3

org.eclipse.ui.navigator
Class CommonViewer

java.lang.Object
  extended byorg.eclipse.jface.viewers.Viewer
      extended byorg.eclipse.jface.viewers.ContentViewer
          extended byorg.eclipse.jface.viewers.StructuredViewer
              extended byorg.eclipse.jface.viewers.ColumnViewer
                  extended byorg.eclipse.jface.viewers.AbstractTreeViewer
                      extended byorg.eclipse.jface.viewers.TreeViewer
                          extended byorg.eclipse.ui.navigator.CommonViewer
All Implemented Interfaces:
IInputProvider, IInputSelectionProvider, IPostSelectionProvider, ISelectionProvider

public class CommonViewer
extends TreeViewer

Provides the Tree Viewer for the Common Navigator. Content and labels are provided by an instance of INavigatorContentService  which uses the ID supplied in the constructor CommonViewer(String, Composite, int) or through NavigatorContentServiceFactory.createContentService(String, org.eclipse.jface.viewers.StructuredViewer).

Clients may extend this class.

Note that as of 3.2.1 and 3.3, the common viewer caches its selection. Clients must not set the selection of the viewer's tree control directly.

Since:
3.2

Nested Class Summary
 
Nested classes inherited from class org.eclipse.jface.viewers.StructuredViewer
StructuredViewer.ColorAndFontCollector, StructuredViewer.ColorAndFontCollectorWithProviders
 
Field Summary
 
Fields inherited from class org.eclipse.jface.viewers.AbstractTreeViewer
ALL_LEVELS
 
Fields inherited from class org.eclipse.jface.viewers.Viewer
WIDGET_DATA_KEY
 
Constructor Summary
CommonViewer(String aViewerId, Composite aParent, int aStyle)
           Constructs the Tree Viewer for the Common Navigator and the corresponding NavigatorContentService.
 
Method Summary
 void add(Object parentElement, Object[] childElements)
          Adds the given child elements to this viewer as children of the given parent element.
protected  void createTreeItem(Widget parent, Object element, int index)
          Creates a single item for the given parent and synchronizes it with the given element.
 void dispose()
           Disposes of the NavigatorContentService, which will dispose the Content and Label providers.
 INavigatorContentService getNavigatorContentService()
           The INavigatorContentServiceprovides the hook into the framework to provide content from the various extensions.
 ISelection getSelection()
          Returns the current selection.
protected  void handleDispose(DisposeEvent event)
          Handles a dispose event on this viewer's control.
protected  void handleDoubleSelect(SelectionEvent event)
          Handles a double-click select event from the widget.
protected  void handleLabelProviderChanged(LabelProviderChangedEvent event)
          The StructuredViewer implementation of this ContentViewer method calls update if the event specifies that the label of a given element has changed, otherwise it calls super.
protected  void handleOpen(SelectionEvent event)
          Handles an open event from the OpenStrategy.
protected  void handlePostSelect(SelectionEvent e)
          Handles a post select event from the widget.
protected  void handleSelect(SelectionEvent event)
          Handles a select event from the widget.
protected  void init()
           Initializes the content provider, label provider, and drag and drop support.
protected  void initDragAndDrop()
           Adds DND support to the Navigator.
protected  void internalRefresh(Object element, boolean updateLabels)
          Refreshes this viewer starting at the given element.
 void refresh(Object element)
          Refreshes this viewer starting with the given element.
 void refresh(Object element, boolean updateLabels)
          Refreshes this viewer starting with the given element.
 void remove(Object[] elements)
           Removals are handled by refreshing the parents of each of the given elements.
protected  void removeWithoutRefresh(Object[] elements)
           
 void setSelection(ISelection selection, boolean reveal)
          Sets a new selection for this viewer and optionally makes it visible.
protected  void setSelectionToWidget(List v, boolean reveal)
          This implementation of setSelectionToWidget accepts a list of elements or a list of tree paths.
 void setSorter(ViewerSorter sorter)
          Sets this viewer's sorter and triggers refiltering and resorting of this viewer's element.
 String toString()
           
 void update(Object element, String[] properties)
          Updates the given element's presentation when one or more of its properties changes.
 
Methods inherited from class org.eclipse.jface.viewers.TreeViewer
addTreeListener, assertContentProviderType, createChildren, createViewerEditor, disassociate, doGetColumnCount, editElement, getChild, getChildren, getColumnViewerOwner, getControl, getExpanded, getItemAt, getItemCount, getItemCount, getItems, getLabelProvider, getParentElement, getParentItem, getRawChildren, getSelection, getTree, getViewerRowFromItem, handleTreeExpand, hookControl, internalAdd, internalInitializeTree, internalRefreshStruct, isExpandable, mapElement, newItem, remove, removeAll, replace, setChildCount, setContentProvider, setExpanded, setHasChildren, setSelection, showItem, updatePlus
 
Methods inherited from class org.eclipse.jface.viewers.AbstractTreeViewer
add, addSelectionListener, addTreeListener, associate, buildLabel, collapseAll, collapseToLevel, doFindInputItem, doFindItem, doUpdateItem, doUpdateItem, expandAll, expandToLevel, expandToLevel, fireTreeCollapsed, fireTreeExpanded, getAutoExpandLevel, getExpandedElements, getExpandedState, getExpandedTreePaths, getFilteredChildren, getNextItem, getPreviousItem, getSelectionFromWidget, getSortedChildren, getTreePathFromItem, getVisibleExpandedElements, handleTreeCollapse, indexForElement, inputChanged, insert, internalCollapseToLevel, internalExpand, internalExpandToLevel, internalFindItems, internalGetWidgetToSelect, internalIsInputOrEmptyPath, internalRefresh, internalRefresh, internalRemove, internalRemove, isSameSelection, labelProviderChanged, remove, remove, removeTreeListener, reveal, scrollDown, scrollUp, setAutoExpandLevel, setExpandedElements, setExpandedState, setExpandedTreePaths, setSelectionToWidget, updateChildren
 
Methods inherited from class org.eclipse.jface.viewers.ColumnViewer
applyEditorValue, cancelEditing, getCellEditors, getCellModifier, getColumnProperties, getColumnViewerEditor, getItem, getLabelProvider, getViewerRow, hookEditingSupport, isCellEditorActive, setCellEditors, setCellModifier, setColumnProperties, setColumnViewerEditor, setLabelProvider, triggerEditorActivationEvent
 
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, getFilters, getRoot, getSorter, handleInvalidSelection, hasFilters, internalUpdate, needsRefilter, preservingSelection, refresh, refresh, refreshItem, removeDoubleClickListener, removeFilter, removeOpenListener, removePostSelectionChangedListener, resetFilters, setComparator, setComparer, setFilters, setInput, setUseHashlookup, testFindItem, testFindItems, unmapAllElements, unmapElement, unmapElement, update, updateItem, updateSelection, usingElementMap
 
Methods inherited from class org.eclipse.jface.viewers.ContentViewer
getContentProvider, getInput
 
Methods inherited from class org.eclipse.jface.viewers.Viewer
addHelpListener, addSelectionChangedListener, fireHelpRequested, fireSelectionChanged, getData, handleHelpRequest, removeHelpListener, removeSelectionChangedListener, setData, setSelection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.eclipse.jface.viewers.ISelectionProvider
addSelectionChangedListener, removeSelectionChangedListener, setSelection
 

Constructor Detail

CommonViewer

public CommonViewer(String aViewerId,
                    Composite aParent,
                    int aStyle)

Constructs the Tree Viewer for the Common Navigator and the corresponding NavigatorContentService. The NavigatorContentService will provide the Content Provider and Label Provider -- these need not be supplied by clients.

For the valid bits to supply in the style mask (aStyle), see documentation provided by TreeViewer.

Parameters:
aViewerId - An id tied to the extensions that is used to focus specific content to a particular instance of the Common Navigator
aParent - A Composite parent to contain the actual SWT widget
aStyle - A style mask that will be used to create the TreeViewer Composite.
Method Detail

init

protected void init()

Initializes the content provider, label provider, and drag and drop support. Should not be called by clients -- this method is invoked when the constructor is invoked.


removeWithoutRefresh

protected void removeWithoutRefresh(Object[] elements)

initDragAndDrop

protected void initDragAndDrop()

Adds DND support to the Navigator. Uses hooks into the extensible framework for DND.

By default, the following Transfer types are supported:

See Also:
CommonDragAdapter, CommonDropAdapter

createTreeItem

protected void createTreeItem(Widget parent,
                              Object element,
                              int index)
Description copied from class: AbstractTreeViewer
Creates a single item for the given parent and synchronizes it with the given element.

Overrides:
createTreeItem in class AbstractTreeViewer
Parameters:
parent - the parent widget
element - the element
index - if non-negative, indicates the position to insert the item into its parent

handleLabelProviderChanged

protected void handleLabelProviderChanged(LabelProviderChangedEvent event)
Description copied from class: StructuredViewer
The StructuredViewer implementation of this ContentViewer method calls update if the event specifies that the label of a given element has changed, otherwise it calls super. Subclasses may reimplement or extend.

Overrides:
handleLabelProviderChanged in class StructuredViewer
Parameters:
event - the event that generated this update

handleDispose

protected void handleDispose(DisposeEvent event)
Description copied from class: ContentViewer
Handles a dispose event on this viewer's control.

The ContentViewer implementation of this method disposes of this viewer's label provider and content provider (if it has one). Subclasses should override this method to perform any additional cleanup of resources; however, overriding methods must invoke super.handleDispose.

Overrides:
handleDispose in class StructuredViewer

dispose

public void dispose()

Disposes of the NavigatorContentService, which will dispose the Content and Label providers.


setSorter

public void setSorter(ViewerSorter sorter)
Sets this viewer's sorter and triggers refiltering and resorting of this viewer's element. Passing null turns sorting off.

Overrides:
setSorter in class StructuredViewer
Parameters:
sorter - a viewer sorter, or null if none

getNavigatorContentService

public INavigatorContentService getNavigatorContentService()

The INavigatorContentServiceprovides the hook into the framework to provide content from the various extensions.

Returns:
The INavigatorContentServicethat was created when the viewer was created.

add

public void add(Object parentElement,
                Object[] childElements)
Description copied from class: AbstractTreeViewer
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.

Overrides:
add in class AbstractTreeViewer
Parameters:
parentElement - the parent element
childElements - the child elements to add

remove

public void remove(Object[] elements)

Removals are handled by refreshing the parents of each of the given elements. The parents are determined via calls ot the contentProvider.

Overrides:
remove in class AbstractTreeViewer
Parameters:
elements - the elements to remove
See Also:
AbstractTreeViewer.remove(java.lang.Object[])

refresh

public void refresh(Object element,
                    boolean updateLabels)
Description copied from class: StructuredViewer
Refreshes this viewer starting with the given element. Labels are updated as described in refresh(boolean updateLabels).

Unlike the update methods, this handles structural changes to the given element (e.g. addition or removal of children). If only the given element needs updating, it is more efficient to use the update methods.

Overrides:
refresh in class ColumnViewer

setSelection

public void setSelection(ISelection selection,
                         boolean reveal)
Description copied from class: TreeViewer
Sets a new selection for this viewer and optionally makes it visible.

Currently the reveal parameter is not honored because Tree does not provide an API to only select an item without scrolling it into view

Overrides:
setSelection in class TreeViewer
Parameters:
selection - the new selection
reveal - true if the selection is to be made visible, and false otherwise

setSelectionToWidget

protected void setSelectionToWidget(List v,
                                    boolean reveal)
Description copied from class: AbstractTreeViewer
This implementation of setSelectionToWidget accepts a list of elements or a list of tree paths.

Overrides:
setSelectionToWidget in class AbstractTreeViewer

handleDoubleSelect

protected void handleDoubleSelect(SelectionEvent event)
Description copied from class: StructuredViewer
Handles a double-click select event from the widget.

This method is internal to the framework; subclassers should not call this method.

Overrides:
handleDoubleSelect in class AbstractTreeViewer

handleOpen

protected void handleOpen(SelectionEvent event)
Description copied from class: StructuredViewer
Handles an open event from the OpenStrategy.

This method is internal to the framework; subclassers should not call this method.

Overrides:
handleOpen in class StructuredViewer
Parameters:
event - the SWT selection event

handlePostSelect

protected void handlePostSelect(SelectionEvent e)
Description copied from class: StructuredViewer
Handles a post select event from the widget.

This method is internal to the framework; subclassers should not call this method.

Overrides:
handlePostSelect in class StructuredViewer
Parameters:
e - the SWT selection event

handleSelect

protected void handleSelect(SelectionEvent event)
Description copied from class: StructuredViewer
Handles a select event from the widget.

This method is internal to the framework; subclassers should not call this method.

Overrides:
handleSelect in class StructuredViewer
Parameters:
event - the SWT selection event

getSelection

public ISelection getSelection()
Returns the current selection.

Note that as of 3.2.1 and 3.3, the common viewer caches its selection. Clients must not set the selection of the viewer's tree control directly.

Specified by:
getSelection in interface ISelectionProvider
Overrides:
getSelection in class AbstractTreeViewer
See Also:
AbstractTreeViewer.getSelection()

refresh

public void refresh(Object element)
Description copied from class: StructuredViewer
Refreshes this viewer starting with the given element.

Unlike the update methods, this handles structural changes to the given element (e.g. addition or removal of children). If only the given element needs updating, it is more efficient to use the update methods.

Overrides:
refresh in class ColumnViewer

update

public void update(Object element,
                   String[] properties)
Description copied from class: StructuredViewer
Updates the given element's presentation when one or more of its properties changes. Only the given element is updated.

This does not handle structural changes (e.g. addition or removal of elements), and does not update any other related elements (e.g. child elements). To handle structural changes, use the refresh methods instead.

This should be called when an element has changed in the model, in order to have the viewer accurately reflect the model. This method only affects the viewer, not the model.

Specifying which properties are affected may allow the viewer to optimize the update. For example, if the label provider is not affected by changes to any of these properties, an update may not actually be required. Specifying properties as null forces a full update of the element.

If the viewer has a sorter which is affected by a change to one of the properties, the element's position is updated to maintain the sort order. Note that resorting does not happen if properties is null.

If the viewer has a filter which is affected by a change to one of the properties, the element may appear or disappear if the change affects whether or not the element is filtered out.

Overrides:
update in class ColumnViewer

toString

public String toString()

internalRefresh

protected void internalRefresh(Object element,
                               boolean updateLabels)
Description copied from class: StructuredViewer
Refreshes this viewer starting at the given element. Labels are updated as described in refresh(boolean updateLabels).

The default implementation simply calls internalRefresh(element), ignoring updateLabels.

If this method is overridden to do the actual refresh, then internalRefresh(Object element) should simply call internalRefresh(element, true).

Overrides:
internalRefresh in class AbstractTreeViewer

Eclipse Platform
Release 3.3

Guidelines for using Eclipse APIs.

Copyright (c) IBM Corp. and others 2000, 2007. All rights reserved.