Class CommonNavigator
- All Implemented Interfaces:
IAdaptable,IExecutableExtension,IPersistable,ISaveablePart,ISaveablesSource,IViewPart,IWorkbenchPart,IWorkbenchPart2,IWorkbenchPart3,ISetSelectionTarget,IShowInTarget,IWorkbenchPartOrientation
- Direct Known Subclasses:
ProjectExplorer
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 ofCommonActionProviders 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
- Since:
- 3.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intUsed to track changes toisLinkingEnabled().protected IMementoTo allowcreateCommonViewer(Composite)to be subclassedFields inherited from interface org.eclipse.ui.ISaveablePart
PROP_DIRTYFields inherited from interface org.eclipse.ui.IWorkbenchPart
PROP_TITLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ActionGroupThe 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 createdprotected CommonNavigatorManagerThe Common Navigator Manager handles the setup of the Common Navigator Menu, manages updates to the ActionBars fromCommonActionProviderextensions as the user's selection changes, and also updates the status bar based on the current selection.protected CommonViewercreateCommonViewer(Composite aParent) Creates and initializes an instance ofCommonViewer.protected CommonViewercreateCommonViewerObject(Composite aParent) Constructs and returns an instance ofCommonViewer.voidcreatePartControl(Composite aParent) Create the CommonViewer part control and setup the default providers as necessary.voiddispose()Note: This method is for internal use only.voiddoSave(IProgressMonitor monitor) Saves the contents of this part.voiddoSaveAs()Saves the contents of this part to another object.Saveable[]Returns the saveables currently active in the workbench part.<T> TgetAdapter(Class<T> adapter) Returns an object which is an instance of the given class associated with this object.Provides access to the commonViewer used by the current CommonNavigator.getFrameToolTipText(Object anElement) Returns the tool tip text for the given element.protected ObjectUsed to provide the initial input for theCommonViewer.protected LinkHelperServiceprotected IMementointSaveable[]Returns the saveables presented by the workbench part.protected voidhandleDoubleClick(DoubleClickEvent anEvent) Note: This method is for internal use only.protected booleanvoidNote: This method is for internal use only.protected voidinitListeners(TreeViewer viewer) Adds the listeners to the Common Viewer.booleanisDirty()Returns whether the contents of this part have changed since the last save operation.final booleanbooleanReturns whether the "Save As" operation is supported by this part.booleanReturns whether the contents of this part should be saved when the part is closed.voidNote: This method is for internal use only.voidselectReveal(ISelection selection) Set the selection to the Common Navigator tree, and expand nodes if necessary.voidsetFocus()Force the workbench to focus on the Common Navigator tree.final voidsetLinkingEnabled(boolean toEnableLinking) Linking is handled by an action which listens for changes to theIS_LINKING_ENABLED_PROPERTY.voidsetRootMode(int mode) voidsetWorkingSetLabel(String label) booleanshow(ShowInContext context) Shows the given context in this target.voidUpdates the title text and title tool tip.Methods inherited from class org.eclipse.ui.part.ViewPart
checkSite, getViewSite, init, setContentDescription, setInitializationData, setPartNameMethods inherited from class org.eclipse.ui.part.WorkbenchPart
addPartPropertyListener, addPropertyListener, firePartPropertyChanged, firePropertyChange, getConfigurationElement, getContentDescription, getDefaultImage, getOrientation, getPartName, getPartProperties, getPartProperty, getSite, getTitle, getTitleImage, getTitleToolTip, removePartPropertyListener, removePropertyListener, setPartProperty, setSite, setTitle, setTitleImage, setTitleToolTip, showBusyMethods inherited from class org.eclipse.core.commands.common.EventManager
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObjectMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.eclipse.ui.IWorkbenchPart
addPropertyListener, getSite, getTitle, getTitleImage, getTitleToolTip, removePropertyListener
-
Field Details
-
IS_LINKING_ENABLED_PROPERTY
public static final int IS_LINKING_ENABLED_PROPERTYUsed to track changes to
Make sure this does not conflict with anything in IWorkbenchPartConstants.isLinkingEnabled().- See Also:
-
memento
To allowcreateCommonViewer(Composite)to be subclassed- Since:
- 3.4
-
-
Constructor Details
-
CommonNavigator
public CommonNavigator()
-
-
Method Details
-
createPartControl
Create the CommonViewer part control and setup the default providers as necessary.
- Specified by:
createPartControlin interfaceIWorkbenchPart- Specified by:
createPartControlin classWorkbenchPart- Parameters:
aParent- the parent control- See Also:
-
updateTitle
public void updateTitle()Updates the title text and title tool tip. Called whenever the input of the viewer changes.
- Since:
- 3.4
-
getFrameToolTipText
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.
- Parameters:
anElement- element to get text for- Returns:
- the tool tip text
- Since:
- 3.4
-
dispose
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.
- Specified by:
disposein interfaceIWorkbenchPart- Overrides:
disposein classWorkbenchPart- See Also:
-
init
Note: This method is for internal use only. Clients should not call this method.
- Specified by:
initin interfaceIViewPart- Overrides:
initin classViewPart- Parameters:
aSite- the view siteaMemento- the IViewPart state or null if there is no previous saved state- Throws:
PartInitException- if this view was not initialized successfully- See Also:
-
saveState
Note: This method is for internal use only. Clients should not call this method.
-
setFocus
public void setFocus()Force the workbench to focus on the Common Navigator tree.
- Specified by:
setFocusin interfaceIWorkbenchPart- Specified by:
setFocusin classWorkbenchPart- See Also:
-
selectReveal
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.
- Specified by:
selectRevealin interfaceISetSelectionTarget- Parameters:
selection- the new element to select- See Also:
-
setLinkingEnabled
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.- Parameters:
toEnableLinking- True enables linking the current selection with open editors
-
isLinkingEnabled
public final boolean isLinkingEnabled()- Returns:
- Whether linking the current selection with open editors is enabled.
-
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.- Returns:
- The (already created) instance of Common Viewer.
-
getAdapter
Returns an object which is an instance of the given class associated with this object. Returnsnullif no such object can be found.- Specified by:
getAdapterin interfaceIAdaptable- Overrides:
getAdapterin classWorkbenchPart- Type Parameters:
T- the class type- Parameters:
adapter- the adapter class to look up- Returns:
- a object castable to the given class,
or
nullif this object does not have an adapter for the given class
-
createCommonViewer
Creates and initializes an instance ofCommonViewer. 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.- Parameters:
aParent- A composite parent to contain the Common Viewer- Returns:
- An initialized instance of CommonViewer
-
createCommonViewerObject
Constructs and returns an instance ofCommonViewer. The ID of the Eclipse view part will be used to create the viewer. Override this method if you want a subclass of the CommonViewer- Parameters:
aParent- A composite parent to contain the CommonViewer- Returns:
- An instance of CommonViewer
- Since:
- 3.4
-
initListeners
Adds the listeners to the Common Viewer.
- Parameters:
viewer- The viewer- Since:
- 2.0
-
handleDoubleClick
Note: This method is for internal use only. Clients should not call this method.
- Parameters:
anEvent- Supplied by the DoubleClick listener.
-
createCommonManager
The Common Navigator Manager handles the setup of the Common Navigator Menu, manages updates to the ActionBars from
CommonActionProviderextensions as the user's selection changes, and also updates the status bar based on the current selection.- Returns:
- The Common Navigator Manager class which handles menu population and ActionBars
- Since:
- 3.4
-
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.
- Returns:
- The Action Group to be associated with the Common Navigator View Part.
-
-
getInitialInput
Used to provide the initial input for theCommonViewer. By default getSite().getPage().getInput() is used. Subclass this to return your desired input.- Returns:
- The initial input for the viewer. Defaults to getSite().getPage().getInput()
- Since:
- 3.4
-
getSaveables
Description copied from interface:ISaveablesSourceReturns the saveables presented by the workbench part. If the return value of this method changes during the lifetime of this part (i.e. after initialization and control creation but before disposal) the part must notify an implicit listener usingISaveablesLifecycleListener.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 typeSaveablesLifecycleEvent.PRE_CLOSEfollowed by an event of typeSaveablesLifecycleEvent.POST_CLOSE. Since firing thePRE_CLOSEevent 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_CLOSEnotification 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.
initorcreatePartControl), or from its dispose method. Parts that implementIReusableEditormust notify when their input is changed throughIReusableEditor.setInput(IEditorInput).- Specified by:
getSaveablesin interfaceISaveablesSource- Returns:
- the saveables presented by the workbench part
- See Also:
-
getActiveSaveables
Description copied from interface:ISaveablesSourceReturns the saveables currently active in the workbench part.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.
- Specified by:
getActiveSaveablesin interfaceISaveablesSource- Returns:
- the saveables currently active in the workbench part
-
hasSaveablesProvider
protected boolean hasSaveablesProvider()- Since:
- 3.9
-
doSave
Description copied from interface:ISaveablePartSaves the contents of this part.If the save is successful, the part should fire a property changed event reflecting the new dirty state (
PROP_DIRTYproperty).If the save is cancelled through user action, or for any other reason, the part should invoke
setCancelledon theIProgressMonitorto inform the caller.This method is long-running; progress and cancellation are provided by the given progress monitor.
- Specified by:
doSavein interfaceISaveablePart- Parameters:
monitor- the progress monitor
-
doSaveAs
public void doSaveAs()Description copied from interface:ISaveablePartSaves the contents of this part to another object.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
IProgressMonitorshould be used to indicate progress.If the save is successful, the part fires a property changed event reflecting the new dirty state (
PROP_DIRTYproperty).- Specified by:
doSaveAsin interfaceISaveablePart
-
isDirty
public boolean isDirty()Description copied from interface:ISaveablePartReturns whether the contents of this part have changed since the last save operation. If this value changes the part must fire a property listener event withPROP_DIRTY.Note: this method is called often on a part open or part activation switch, for example by actions to determine their enabled status.
- Specified by:
isDirtyin interfaceISaveablePart- Returns:
trueif the contents have been modified and need saving, andfalseif they have not changed since the last save
-
isSaveAsAllowed
public boolean isSaveAsAllowed()Description copied from interface:ISaveablePartReturns whether the "Save As" operation is supported by this part.- Specified by:
isSaveAsAllowedin interfaceISaveablePart- Returns:
trueif "Save As" is supported, andfalseif not supported
-
isSaveOnCloseNeeded
public boolean isSaveOnCloseNeeded()Description copied from interface:ISaveablePartReturns whether the contents of this part should be saved when the part is closed.- Specified by:
isSaveOnCloseNeededin interfaceISaveablePart- Returns:
trueif the contents of the part should be saved on close, andfalseif the contents are expendable
-
show
Description copied from interface:IShowInTargetShows the given context in this target. The target should check the context's selection for elements to show. If there are no relevant elements in the selection, then it should check the context's input.- Specified by:
showin interfaceIShowInTarget- Parameters:
context- the context to show- Returns:
trueif the context could be shown,falseotherwise
-
getLinkHelperService
- Since:
- 3.4
-
getMemento
- Since:
- 3.4
-
setRootMode
public void setRootMode(int mode) - Parameters:
mode- new root mode- Since:
- 3.4
- Restriction:
- This method is not intended to be referenced by clients.
- Restriction:
- This method is not intended to be re-implemented or extended by clients.
-
getRootMode
public int getRootMode()- Returns:
- the root mode
- Since:
- 3.4
- Restriction:
- This method is not intended to be referenced by clients.
- Restriction:
- This method is not intended to be re-implemented or extended by clients.
-
setWorkingSetLabel
- Parameters:
label- new working set label- Since:
- 3.4
- Restriction:
- This method is not intended to be referenced by clients.
- Restriction:
- This method is not intended to be re-implemented or extended by clients.
-
getWorkingSetLabel
- Returns:
- the working set label
- Since:
- 3.4
- Restriction:
- This method is not intended to be referenced by clients.
- Restriction:
- This method is not intended to be re-implemented or extended by clients.
-