public class CommonNavigator extends ViewPart implements ISetSelectionTarget, ISaveablePart, ISaveablesSource, IShowInTarget
This class provides the IViewPart for the Common Navigator framework in the Eclipse workbench. This class also serves as the backbone for navigational viewers. The following types are used by this class to render the Common Navigator:
CommonViewer
: The viewer that renders the
extensible tree. Creates and manages the lifecycle of the Navigator Content
Service (described below).
NavigatorActionService
: Manages instances of
CommonActionProvider
s provided by individual
extensions and content extensions.
INavigatorContentService
: Manages instances
of Navigator Content Extensions. Instances are created as needed, and
disposed of upon the disposal of the Navigator Content Service.
Clients that wish to define their own custom extensible navigator view using CommonNavigator need to specify an instance of the org.eclipse.ui.views extension point:
<extension point="org.eclipse.ui.views"> <view name="My Custom View" icon="relative/path/to/icon.gif" category="org.acme.mycategory" class="org.eclipse.ui.navigator.CommonNavigator" id="org.acme.MyCustomNavigatorID"> </view> </extension>
CommonNavigator gets its initial input (during initialization) from the
Workbench by calling getSite().getPage().getInput(). This is done in
getInitialInput()
. Clients may create a subclass of CommonNavigator
to provide their own means of getting the initial input. Or they may access
the CommonViewer
and set its input directly after startup.
In the IDE scenario, the default page input is IWorkspaceRoot, in the RCP scenario it is null and can be configured in the WorkbenchAdvisor.
Clients that wish to extend the view menu provided via the org.eclipse.ui.popupMenus extension may specify the the popupMenuId specified by org.eclipse.ui.navigator.viewer (or a nested popupMenu element) of their target viewer as their target menu id.
This class may be instantiated or subclassed
Modifier and Type | Field and Description |
---|---|
static int |
IS_LINKING_ENABLED_PROPERTY
Used to track changes to the
isLinkingEnabled property. |
protected IMemento |
memento
To allow
createCommonViewer(Composite) to be subclassed |
PROP_DIRTY
PROP_TITLE
Constructor and Description |
---|
CommonNavigator() |
Modifier and Type | Method and Description |
---|---|
protected ActionGroup |
createCommonActionGroup()
The ActionGroup is used to populate the ActionBars of Common Navigator
View Part, and the returned implementation will have an opportunity to
fill the ActionBars of the view as soon as it is created.
|
protected CommonNavigatorManager |
createCommonManager()
The Common Navigator Manager handles the setup of the Common Navigator
Menu, manages updates to the ActionBars from
CommonActionProvider extensions as the user's selection
changes, and also updates the status bar based on the current selection. |
protected CommonViewer |
createCommonViewer(Composite aParent)
Creates and initializes an instance of
CommonViewer . |
protected CommonViewer |
createCommonViewerObject(Composite aParent)
Constructs and returns an instance of
CommonViewer . |
void |
createPartControl(Composite aParent)
Create the CommonViewer part control and setup the default providers as
necessary.
|
void |
dispose()
Note: This method is for internal use only.
|
void |
doSave(IProgressMonitor monitor)
Saves the contents of this part.
|
void |
doSaveAs()
Saves the contents of this part to another object.
|
Saveable[] |
getActiveSaveables()
Returns the saveables currently active in the workbench part.
|
<T> T |
getAdapter(Class<T> adapter)
Returns an object which is an instance of the given class
associated with this object.
|
CommonViewer |
getCommonViewer()
Provides access to the commonViewer used by the current CommonNavigator.
|
String |
getFrameToolTipText(Object anElement)
Returns the tool tip text for the given element.
|
protected Object |
getInitialInput()
Used to provide the initial input for the
CommonViewer . |
protected LinkHelperService |
getLinkHelperService() |
protected IMemento |
getMemento() |
NavigatorActionService |
getNavigatorActionService() |
INavigatorContentService |
getNavigatorContentService() |
int |
getRootMode() |
Saveable[] |
getSaveables()
Returns the saveables presented by the workbench part.
|
String |
getWorkingSetLabel() |
protected void |
handleDoubleClick(DoubleClickEvent anEvent)
Note: This method is for internal use only.
|
void |
init(IViewSite aSite,
IMemento aMemento)
Note: This method is for internal use only.
|
protected void |
initListeners(TreeViewer viewer)
Adds the listeners to the Common Viewer.
|
boolean |
isDirty()
Returns whether the contents of this part have changed since the last save
operation.
|
boolean |
isLinkingEnabled() |
boolean |
isSaveAsAllowed()
Returns whether the "Save As" operation is supported by this part.
|
boolean |
isSaveOnCloseNeeded()
Returns whether the contents of this part should be saved when the part
is closed.
|
void |
saveState(IMemento aMemento)
Note: This method is for internal use only.
|
void |
selectReveal(ISelection selection)
Set the selection to the Common Navigator tree, and expand nodes if
necessary.
|
void |
setFocus()
Force the workbench to focus on the Common Navigator tree.
|
void |
setLinkingEnabled(boolean toEnableLinking)
Linking is handled by an action which listens for
changes to the
IS_LINKING_ENABLED_PROPERTY . |
void |
setRootMode(int mode) |
void |
setWorkingSetLabel(String label) |
boolean |
show(ShowInContext context)
Shows the given context in this target.
|
void |
updateTitle()
Updates the title text and title tool tip.
|
checkSite, getViewSite, init, setContentDescription, setInitializationData, setPartName
addPartPropertyListener, addPropertyListener, firePartPropertyChanged, firePropertyChange, getConfigurationElement, getContentDescription, getDefaultImage, getOrientation, getPartName, getPartProperties, getPartProperty, getSite, getTitle, getTitleImage, getTitleToolTip, removePartPropertyListener, removePropertyListener, setPartProperty, setSite, setTitle, setTitleImage, setTitleToolTip, showBusy
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addPropertyListener, getSite, getTitle, getTitleImage, getTitleToolTip, removePropertyListener
public static final int IS_LINKING_ENABLED_PROPERTY
Used to track changes to the isLinkingEnabled
property.
protected IMemento memento
createCommonViewer(Composite)
to be subclassedpublic void createPartControl(Composite aParent)
Create the CommonViewer part control and setup the default providers as necessary.
createPartControl
in interface IWorkbenchPart
createPartControl
in class WorkbenchPart
aParent
- the parent controlWorkbenchPart.createPartControl(org.eclipse.swt.widgets.Composite)
public void updateTitle()
Updates the title text and title tool tip. Called whenever the input of the viewer changes.
public String getFrameToolTipText(Object anElement)
Returns the tool tip text for the given element. Used as the tool tip text for the current frame, and for the view title tooltip.
anElement
- public void dispose()
Note: This method is for internal use only. Clients should not call this method.
This method will be invoked when the DisposeListener is notified of the disposal of the Eclipse view part.
dispose
in interface IWorkbenchPart
dispose
in class WorkbenchPart
WorkbenchPart.dispose()
public void init(IViewSite aSite, IMemento aMemento) throws PartInitException
Note: This method is for internal use only. Clients should not call this method.
init
in interface IViewPart
init
in class ViewPart
aSite
- the view siteaMemento
- the IViewPart state or null if there is no previous saved statePartInitException
- if this view was not initialized successfullyViewPart.init(org.eclipse.ui.IViewSite,
org.eclipse.ui.IMemento)
public void saveState(IMemento aMemento)
Note: This method is for internal use only. Clients should not call this method.
saveState
in interface IPersistable
saveState
in interface IViewPart
saveState
in class ViewPart
aMemento
- a memento to receive the object stateViewPart.saveState(org.eclipse.ui.IMemento)
public void setFocus()
Force the workbench to focus on the Common Navigator tree.
setFocus
in interface IWorkbenchPart
setFocus
in class WorkbenchPart
WorkbenchPart.setFocus()
public void selectReveal(ISelection selection)
Set the selection to the Common Navigator tree, and expand nodes if necessary. Use caution when invoking this method as it can cause Navigator Content Extensions to load, thus causing plugin activation.
selectReveal
in interface ISetSelectionTarget
selection
- the new element to selectISetSelectionTarget.selectReveal(org.eclipse.jface.viewers.ISelection)
public final void setLinkingEnabled(boolean toEnableLinking)
Linking is handled by an action which listens for
changes to the IS_LINKING_ENABLED_PROPERTY
.
Custom implementations that wish to override this functionality, need to
override the action used by the default ActionGroup and listen for
changes to the above property.
toEnableLinking
- True enables linking the current selection with open editorspublic final boolean isLinkingEnabled()
public CommonViewer getCommonViewer()
Provides access to the commonViewer used by the current CommonNavigator.
The field will not be valid until after
init(IViewSite, IMemento)
has been called by the
Workbench.
public INavigatorContentService getNavigatorContentService()
public <T> T getAdapter(Class<T> adapter)
null
if
no such object can be found.getAdapter
in interface IAdaptable
getAdapter
in class WorkbenchPart
adapter
- the adapter class to look upnull
if this object does not
have an adapter for the given classpublic NavigatorActionService getNavigatorActionService()
protected CommonViewer createCommonViewer(Composite aParent)
CommonViewer
. The ID of
the Eclipse view part will be used to create the viewer. The ID is
important as some extensions indicate they should only be used with a
particular viewer ID.aParent
- A composite parent to contain the Common Viewerprotected CommonViewer createCommonViewerObject(Composite aParent)
CommonViewer
. The ID of
the Eclipse view part will be used to create the viewer.
Override this method if you want a subclass of the CommonVieweraParent
- A composite parent to contain the CommonViewerprotected void initListeners(TreeViewer viewer)
Adds the listeners to the Common Viewer.
viewer
- The viewerprotected void handleDoubleClick(DoubleClickEvent anEvent)
Note: This method is for internal use only. Clients should not call this method.
anEvent
- Supplied by the DoubleClick listener.protected CommonNavigatorManager createCommonManager()
The Common Navigator Manager handles the setup of the Common Navigator
Menu, manages updates to the ActionBars from
CommonActionProvider
extensions as the user's selection
changes, and also updates the status bar based on the current selection.
protected ActionGroup createCommonActionGroup()
The ActionGroup is used to populate the ActionBars of Common Navigator
View Part, and the returned implementation will have an opportunity to
fill the ActionBars of the view as soon as it is created. (ActionGroup.fillActionBars(org.eclipse.ui.IActionBars)
.
The default implementation returns an action group which will add the following actions:
Link with editor support. Allows the user to toggling linking the current selection with the active editors.
Collapse all. Collapses all expanded nodes.
Select Filters. Provides access to the "Select Filters" dialog that allows users to enable/disable filters and also the Content Extension activations.
protected Object getInitialInput()
CommonViewer
. By default
getSite().getPage().getInput() is used. Subclass this to return your desired
input.public Saveable[] getSaveables()
ISaveablesSource
ISaveablesLifecycleListener.handleLifecycleEvent(SaveablesLifecycleEvent)
.
Additions of saveables to the list of saveables of this part are
announced using an event of type
SaveablesLifecycleEvent.POST_OPEN
. Removals are announced in a
two-stage process, first using an event of type
SaveablesLifecycleEvent.PRE_CLOSE
followed by an event of type
SaveablesLifecycleEvent.POST_CLOSE
. Since firing the
PRE_CLOSE
event may trigger prompts to save dirty
saveables, the cancellation status of the event must be checked by the
part after the notification. When removing only non-dirty saveables,
POST_CLOSE
notification is sufficient.
The listener is obtained from the part site by calling
partSite.getService(ISaveablesLifecycleListener.class)
.
The part must not notify from its initialization methods (e.g. init
or createPartControl
), or from its dispose method. Parts that
implement IReusableEditor
must notify when their input is changed
through IReusableEditor.setInput(IEditorInput)
.
getSaveables
in interface ISaveablesSource
ISaveablesLifecycleListener
public Saveable[] getActiveSaveables()
ISaveablesSource
Certain workbench actions, such as Save, target only the active saveables in the active part. For example, the active saveables could be determined based on the current selection in the part.
getActiveSaveables
in interface ISaveablesSource
public void doSave(IProgressMonitor monitor)
ISaveablePart
If the save is successful, the part should fire a property changed event
reflecting the new dirty state (PROP_DIRTY
property).
If the save is cancelled through user action, or for any other reason, the
part should invoke setCancelled
on the IProgressMonitor
to inform the caller.
This method is long-running; progress and cancellation are provided by the given progress monitor.
doSave
in interface ISaveablePart
monitor
- the progress monitorpublic void doSaveAs()
ISaveablePart
Implementors are expected to open a "Save As" dialog where the user will
be able to select a new name for the contents. After the selection is made,
the contents should be saved to that new name. During this operation a
IProgressMonitor
should be used to indicate progress.
If the save is successful, the part fires a property changed event
reflecting the new dirty state (PROP_DIRTY
property).
doSaveAs
in interface ISaveablePart
public boolean isDirty()
ISaveablePart
PROP_DIRTY
.
Note: this method is called often on a part open or part activation switch, for example by actions to determine their enabled status.
isDirty
in interface ISaveablePart
true
if the contents have been modified and need
saving, and false
if they have not changed since the last
savepublic boolean isSaveAsAllowed()
ISaveablePart
isSaveAsAllowed
in interface ISaveablePart
true
if "Save As" is supported, and false
if not supportedpublic boolean isSaveOnCloseNeeded()
ISaveablePart
isSaveOnCloseNeeded
in interface ISaveablePart
true
if the contents of the part should be saved on
close, and false
if the contents are expendablepublic boolean show(ShowInContext context)
IShowInTarget
show
in interface IShowInTarget
context
- the context to showtrue
if the context could be shown,
false
otherwiseprotected LinkHelperService getLinkHelperService()
protected IMemento getMemento()
public void setRootMode(int mode)
mode
- public int getRootMode()
public void setWorkingSetLabel(String label)
label
- public String getWorkingSetLabel()
Copyright (c) 2000, 2018 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.