Index: src/org/eclipse/ui/internal/navigator/CommonNavigatorManager.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.navigator/src/org/eclipse/ui/internal/navigator/CommonNavigatorManager.java,v retrieving revision 1.16 diff -u -r1.16 CommonNavigatorManager.java --- src/org/eclipse/ui/internal/navigator/CommonNavigatorManager.java 9 May 2008 14:12:56 -0000 1.16 +++ src/org/eclipse/ui/internal/navigator/CommonNavigatorManager.java 19 Jun 2008 15:39:20 -0000 @@ -35,11 +35,9 @@ import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.actions.ActionContext; import org.eclipse.ui.actions.RetargetAction; -import org.eclipse.ui.navigator.CommonNavigator; import org.eclipse.ui.navigator.CommonViewer; -import org.eclipse.ui.navigator.CommonViewerSiteFactory; import org.eclipse.ui.navigator.ICommonActionConstants; -import org.eclipse.ui.navigator.ICommonViewerSite; +import org.eclipse.ui.navigator.ICommonNavigator; import org.eclipse.ui.navigator.IDescriptionProvider; import org.eclipse.ui.navigator.INavigatorContentService; import org.eclipse.ui.navigator.NavigatorActionService; @@ -62,7 +60,7 @@ // delay for updating the action bars (in ms) private static final long DELAY = 200; - private final CommonNavigator commonNavigator; + private final ICommonNavigator commonNavigator; private final INavigatorContentService contentService; @@ -101,7 +99,7 @@ if(commonNavigator.getCommonViewer().getInput() != null) { IStructuredSelection selection = new StructuredSelection(commonNavigator.getCommonViewer().getInput()); actionService.setContext(new ActionContext(selection)); - actionService.fillActionBars(commonNavigator.getViewSite().getActionBars()); + actionService.fillActionBars(commonNavigator.getActionBars()); } } /* @@ -127,7 +125,7 @@ * The CommonNavigator managed by this class. Requires a non-null * value. */ - public CommonNavigatorManager(CommonNavigator aNavigator) { + public CommonNavigatorManager(ICommonNavigator aNavigator) { this(aNavigator, null); } @@ -142,11 +140,11 @@ * value. * @param aMemento a memento for restoring state, or null */ - public CommonNavigatorManager(CommonNavigator aNavigator, IMemento aMemento) { + public CommonNavigatorManager(ICommonNavigator aNavigator, IMemento aMemento) { super(); commonNavigator = aNavigator; contentService = commonNavigator.getNavigatorContentService(); - statusLineManager = commonNavigator.getViewSite().getActionBars() + statusLineManager = commonNavigator.getActionBars() .getStatusLineManager(); commonDescriptionProvider = contentService .createCommonDescriptionProvider(); @@ -166,21 +164,19 @@ commonViewer.addPostSelectionChangedListener(statusBarListener); updateStatusBar(commonViewer.getSelection()); - ICommonViewerSite commonViewerSite = CommonViewerSiteFactory - .createCommonViewerSite(commonNavigator.getViewSite()); - actionService = new NavigatorActionService(commonViewerSite, - commonViewer, commonViewer.getNavigatorContentService()); + actionService = new NavigatorActionService(commonNavigator + .getCommonViewerSite(), commonViewer, commonViewer.getNavigatorContentService()); final RetargetAction openAction = new RetargetAction( ICommonActionConstants.OPEN, CommonNavigatorMessages.Open_action_label); - commonNavigator.getViewSite().getPage().addPartListener(openAction); + commonNavigator.getWorkbenchSite().getPage().addPartListener(openAction); openAction.setActionDefinitionId(ICommonActionConstants.OPEN); commonNavigator.getCommonViewer().addOpenListener(new IOpenListener() { public void open(OpenEvent event) { actionService.setContext(new ActionContext(commonNavigator.getCommonViewer().getSelection())); - actionService.fillActionBars(commonNavigator.getViewSite().getActionBars()); + actionService.fillActionBars(commonNavigator.getActionBars()); openAction.run(); } }); @@ -195,7 +191,7 @@ /** *

- * Called by {@link CommonNavigator} when the View Part is disposed. + * Called by {@link ICommonNavigator} when the View Part is disposed. * */ public void dispose() { @@ -217,8 +213,7 @@ IStructuredSelection structuredSelection = (IStructuredSelection) anEvent .getSelection(); actionService.setContext(new ActionContext(structuredSelection)); - actionService.fillActionBars(commonNavigator.getViewSite() - .getActionBars()); + actionService.fillActionBars(commonNavigator.getActionBars()); } } @@ -284,7 +279,7 @@ } protected void initViewMenu() { - IMenuManager viewMenu = commonNavigator.getViewSite().getActionBars() + IMenuManager viewMenu = commonNavigator.getActionBars() .getMenuManager(); viewMenu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); viewMenu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS Index: src/org/eclipse/ui/internal/navigator/CommonNavigatorActionGroup.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.navigator/src/org/eclipse/ui/internal/navigator/CommonNavigatorActionGroup.java,v retrieving revision 1.11 diff -u -r1.11 CommonNavigatorActionGroup.java --- src/org/eclipse/ui/internal/navigator/CommonNavigatorActionGroup.java 24 Mar 2008 19:13:48 -0000 1.11 +++ src/org/eclipse/ui/internal/navigator/CommonNavigatorActionGroup.java 19 Jun 2008 15:39:20 -0000 @@ -10,20 +10,15 @@ *******************************************************************************/ package org.eclipse.ui.internal.navigator; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.commands.ActionHandler; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.actions.ActionGroup; import org.eclipse.ui.handlers.CollapseAllHandler; import org.eclipse.ui.handlers.IHandlerService; import org.eclipse.ui.internal.navigator.actions.CollapseAllAction; -import org.eclipse.ui.internal.navigator.actions.LinkEditorAction; -import org.eclipse.ui.internal.navigator.extensions.LinkHelperService; import org.eclipse.ui.internal.navigator.filters.FilterActionGroup; -import org.eclipse.ui.navigator.CommonNavigator; import org.eclipse.ui.navigator.CommonViewer; +import org.eclipse.ui.navigator.ICommonNavigator; import org.eclipse.ui.navigator.INavigatorViewerDescriptor; /** @@ -33,17 +28,13 @@ */ public class CommonNavigatorActionGroup extends ActionGroup { - private LinkEditorAction toggleLinkingAction; - private CollapseAllAction collapseAllAction; private FilterActionGroup filterGroup; private final CommonViewer commonViewer; - private CommonNavigator commonNavigator; - - private final LinkHelperService linkHelperService; + private ICommonNavigator commonNavigator; private CollapseAllHandler collapseAllHandler; @@ -52,17 +43,15 @@ * Filters. * * @param aNavigator - * The IViewPart for this action group + * The ICommonNavigator for this action group * @param aViewer * The Viewer for this action group - * @param linkHelperService the link service helper */ - public CommonNavigatorActionGroup(CommonNavigator aNavigator, - CommonViewer aViewer, LinkHelperService linkHelperService) { + public CommonNavigatorActionGroup(ICommonNavigator aNavigator, + CommonViewer aViewer) { super(); commonNavigator = aNavigator; commonViewer = aViewer; - this.linkHelperService = linkHelperService; makeActions(); } @@ -75,25 +64,28 @@ } /** + * @return The ICommonNavigator for this action group + */ + protected ICommonNavigator getCommonNavigator() { + return commonNavigator; + } + + /** + * @return The viewer for this action group + */ + protected CommonViewer getCommonViewer() { + return commonViewer; + } + + /** * */ private void makeActions() { - IHandlerService service = (IHandlerService) commonNavigator.getSite() + IHandlerService service = (IHandlerService) commonNavigator.getWorkbenchSite() .getService(IHandlerService.class); INavigatorViewerDescriptor viewerDescriptor = commonViewer .getNavigatorContentService().getViewerDescriptor(); - boolean hideLinkWithEditorAction = viewerDescriptor - .getBooleanConfigProperty(INavigatorViewerDescriptor.PROP_HIDE_LINK_WITH_EDITOR_ACTION); - if (!hideLinkWithEditorAction) { - toggleLinkingAction = new LinkEditorAction(commonNavigator, - commonViewer, linkHelperService); - ImageDescriptor syncIcon = getImageDescriptor("elcl16/synced.gif"); //$NON-NLS-1$ - toggleLinkingAction.setImageDescriptor(syncIcon); - toggleLinkingAction.setHoverImageDescriptor(syncIcon); - service.activateHandler(toggleLinkingAction.getActionDefinitionId(), - new ActionHandler(toggleLinkingAction)); - } boolean hideCollapseAllAction = viewerDescriptor .getBooleanConfigProperty(INavigatorViewerDescriptor.PROP_HIDE_COLLAPSE_ALL_ACTION); @@ -116,7 +108,6 @@ * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars) */ public void fillActionBars(IActionBars theActionBars) { - IMenuManager menu = theActionBars.getMenuManager(); filterGroup.fillActionBars(theActionBars); @@ -124,14 +115,6 @@ theActionBars.getToolBarManager().add(collapseAllAction); } - if (toggleLinkingAction != null) { - menu - .insertAfter(IWorkbenchActionConstants.MB_ADDITIONS - + "-end", toggleLinkingAction); //$NON-NLS-1$ - - theActionBars.getToolBarManager().add(toggleLinkingAction); - } - theActionBars.updateActionBars(); } @@ -142,9 +125,6 @@ */ public void dispose() { super.dispose(); - if (toggleLinkingAction != null) { - toggleLinkingAction.dispose(); - } if (collapseAllHandler!=null) { collapseAllHandler.dispose(); } Index: src/org/eclipse/ui/internal/navigator/messages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.navigator/src/org/eclipse/ui/internal/navigator/messages.properties,v retrieving revision 1.12 diff -u -r1.12 messages.properties --- src/org/eclipse/ui/internal/navigator/messages.properties 6 Jun 2008 16:50:50 -0000 1.12 +++ src/org/eclipse/ui/internal/navigator/messages.properties 19 Jun 2008 15:39:20 -0000 @@ -43,3 +43,4 @@ CommonSorterDescriptorManager_A_navigatorContent_extesnion_in_0_=A navigatorContent extesnion in {0} is missing an id. FilterDialogSelectionListener_Enable_the_0_filter_=Enable the {0} filter. NavigatorContentServiceLabelProvider_Error_no_label_provider_for_0_=Error: no label provider for {0} +CommonNavigatorOutline_DefaultTitle=Common Navigator Outline Index: src/org/eclipse/ui/internal/navigator/CommonNavigatorMessages.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.navigator/src/org/eclipse/ui/internal/navigator/CommonNavigatorMessages.java,v retrieving revision 1.10 diff -u -r1.10 CommonNavigatorMessages.java --- src/org/eclipse/ui/internal/navigator/CommonNavigatorMessages.java 9 May 2008 14:12:56 -0000 1.10 +++ src/org/eclipse/ui/internal/navigator/CommonNavigatorMessages.java 19 Jun 2008 15:39:20 -0000 @@ -123,7 +123,10 @@ /** */ public static String NavigatorContentServiceLabelProvider_Error_no_label_provider_for_0_; - + + /** */ + public static String CommonNavigatorOutline_DefaultTitle; + static { NLS.initializeMessages(BUNDLE_NAME, CommonNavigatorMessages.class); } Index: src/org/eclipse/ui/navigator/CommonNavigator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.navigator/src/org/eclipse/ui/navigator/CommonNavigator.java,v retrieving revision 1.35 diff -u -r1.35 CommonNavigator.java --- src/org/eclipse/ui/navigator/CommonNavigator.java 9 May 2008 14:12:56 -0000 1.35 +++ src/org/eclipse/ui/navigator/CommonNavigator.java 19 Jun 2008 15:39:20 -0000 @@ -25,23 +25,24 @@ import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IActionBars; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IMemento; import org.eclipse.ui.ISaveablePart; import org.eclipse.ui.ISaveablesLifecycleListener; import org.eclipse.ui.ISaveablesSource; import org.eclipse.ui.IViewSite; +import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.Saveable; import org.eclipse.ui.SaveablesLifecycleEvent; import org.eclipse.ui.actions.ActionGroup; -import org.eclipse.ui.internal.navigator.CommonNavigatorActionGroup; import org.eclipse.ui.internal.navigator.CommonNavigatorManager; +import org.eclipse.ui.internal.navigator.CommonNavigatorViewActionGroup; import org.eclipse.ui.internal.navigator.NavigatorContentService; import org.eclipse.ui.internal.navigator.NavigatorPlugin; import org.eclipse.ui.internal.navigator.extensions.LinkHelperService; -import org.eclipse.ui.part.ISetSelectionTarget; import org.eclipse.ui.part.IShowInTarget; import org.eclipse.ui.part.ShowInContext; import org.eclipse.ui.part.ViewPart; @@ -50,50 +51,7 @@ *

* 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: - *

- *

- * Clients are not expected to subclass CommonNavigator. Clients that wish to - * define their own custom extensible navigator view 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> 
- *    
- * 
+ * viewers. * *

* Clients that wish to extend the view menu provided via the @@ -108,7 +66,7 @@ * * @since 3.2 */ -public class CommonNavigator extends ViewPart implements ISetSelectionTarget, ISaveablePart, ISaveablesSource, IShowInTarget { +public class CommonNavigator extends ViewPart implements ICommonNavigator, ISaveablePart, ISaveablesSource, IShowInTarget { private static final Class INAVIGATOR_CONTENT_SERVICE = INavigatorContentService.class; private static final Class COMMON_VIEWER_CLASS = CommonViewer.class; @@ -341,21 +299,20 @@ /** *

- * Provides access to the commonViewer used by the current CommonNavigator. * The field will not be valid until after * {@link #init(IViewSite, IMemento)} has been called by the * Workbench. *

* * @return The (already created) instance of Common Viewer. + * @see org.eclipse.ui.navigator.ICommonNavigator#getCommonViewer() */ public CommonViewer getCommonViewer() { return commonViewer; } /** - * @return The Navigator Content Service which populates this instance of - * Common Navigator + * @see org.eclipse.ui.navigator.ICommonNavigator#getNavigatorContentService() */ public INavigatorContentService getNavigatorContentService() { return getCommonViewer().getNavigatorContentService(); @@ -503,7 +460,7 @@ * Part. */ protected ActionGroup createCommonActionGroup() { - return new CommonNavigatorActionGroup(this, commonViewer, getLinkHelperService()); + return new CommonNavigatorViewActionGroup(this, commonViewer, getLinkHelperService()); } /** @@ -646,5 +603,26 @@ linkService = new LinkHelperService((NavigatorContentService)getCommonViewer().getNavigatorContentService()); return linkService; } + + /** + * @see org.eclipse.ui.navigator.ICommonNavigator#getActionBars() + */ + public IActionBars getActionBars() { + return getViewSite().getActionBars(); + } + + /** + * @see org.eclipse.ui.navigator.ICommonNavigator#getWorkbenchSite() + */ + public IWorkbenchSite getWorkbenchSite() { + return getViewSite(); + } + + /** + * @see org.eclipse.ui.navigator.ICommonNavigator#getCommonViewerSite() + */ + public ICommonViewerSite getCommonViewerSite() { + return CommonViewerSiteFactory.createCommonViewerSite(getViewSite()); + } } Index: src/org/eclipse/ui/navigator/NavigatorActionService.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.navigator/src/org/eclipse/ui/navigator/NavigatorActionService.java,v retrieving revision 1.22 diff -u -r1.22 NavigatorActionService.java --- src/org/eclipse/ui/navigator/NavigatorActionService.java 24 Mar 2008 19:13:48 -0000 1.22 +++ src/org/eclipse/ui/navigator/NavigatorActionService.java 19 Jun 2008 15:39:20 -0000 @@ -60,7 +60,7 @@ * specify an Action Provider. *

*

- * Clients that reuse this service outside of an instance of {@link CommonNavigator} must be sure + * Clients that reuse this service outside of an instance of {@link ICommonNavigator} must be sure * that {{@link #fillActionBars(IActionBars)} is called whenever the selection changes. The * retargetable actions for each selection could change, based on who contributed the items. * Index: src/org/eclipse/ui/internal/navigator/actions/LinkEditorAction.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.navigator/src/org/eclipse/ui/internal/navigator/actions/LinkEditorAction.java,v retrieving revision 1.13 diff -u -r1.13 LinkEditorAction.java --- src/org/eclipse/ui/internal/navigator/actions/LinkEditorAction.java 30 Nov 2007 15:10:09 -0000 1.13 +++ src/org/eclipse/ui/internal/navigator/actions/LinkEditorAction.java 19 Jun 2008 15:39:20 -0000 @@ -69,7 +69,7 @@ ILinkHelper[] helpers = linkService .getLinkHelpersFor(sSelection.getFirstElement()); if (helpers.length > 0) { - helpers[0].activateEditor(commonNavigator.getSite() + helpers[0].activateEditor(commonNavigator.getWorkbenchSite() .getPage(), sSelection); } } @@ -87,7 +87,7 @@ SafeRunner.run(new ISafeRunnable() { public void run() throws Exception { - IWorkbenchPage page = commonNavigator.getSite() + IWorkbenchPage page = commonNavigator.getWorkbenchSite() .getPage(); if (page != null) { IEditorPart editor = page.getActiveEditor(); @@ -245,10 +245,10 @@ updateSelectionJob.schedule(BRIEF_DELAY); commonViewer.addPostSelectionChangedListener(this); - commonNavigator.getSite().getPage().addPartListener(partListener); + commonNavigator.getWorkbenchSite().getPage().addPartListener(partListener); } else { commonViewer.removePostSelectionChangedListener(this); - commonNavigator.getSite().getPage() + commonNavigator.getWorkbenchSite().getPage() .removePartListener(partListener); } } Index: META-INF/MANIFEST.MF =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.navigator/META-INF/MANIFEST.MF,v retrieving revision 1.16 diff -u -r1.16 MANIFEST.MF --- META-INF/MANIFEST.MF 23 Jan 2008 13:27:31 -0000 1.16 +++ META-INF/MANIFEST.MF 19 Jun 2008 15:39:19 -0000 @@ -18,6 +18,7 @@ org.eclipse.ui.workbench;bundle-version="[3.2.1,4.0.0)", org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)", org.eclipse.ui;bundle-version="[3.2.1,4.0.0)", - org.eclipse.core.expressions;bundle-version="[3.2.0,4.0.0)" + org.eclipse.core.expressions;bundle-version="[3.2.0,4.0.0)", + org.eclipse.ui.views;bundle-version="[3.3.0,4.0.0)" Bundle-RequiredExecutionEnvironment: J2SE-1.4 Bundle-ActivationPolicy: lazy Index: src/org/eclipse/ui/navigator/ICommonNavigator.java =================================================================== RCS file: src/org/eclipse/ui/navigator/ICommonNavigator.java diff -N src/org/eclipse/ui/navigator/ICommonNavigator.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/ui/navigator/ICommonNavigator.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,122 @@ +/*********************************************************************** + * Copyright (c) 2008 Anyware Technologies + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Anyware Technologies - initial API and implementation + * + * $Id$ + **********************************************************************/ + +package org.eclipse.ui.navigator; + +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IWorkbenchSite; +import org.eclipse.ui.part.ISetSelectionTarget; + +/** + *

+ * This interface defines the API for common navigators. Common navigators can + * be used in views or outlines. The following types are used by this class to + * render a Common Navigator: + *

+ *

+ * Clients are not expected to subclass CommonNavigator. Clients that wish to + * define their own custom extensible navigator view 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>
+ * 
+ * 
+ * + * @since 3.5 + */ +public interface ICommonNavigator extends ISetSelectionTarget { + + /** + *

+ * Provides access to the commonViewer used by the current CommonNavigator. + *

+ * + * @return The (already created) instance of Common Viewer. + */ + public CommonViewer getCommonViewer(); + + /** + * @return The Navigator Content Service which populates this instance of + * Common Navigator + */ + public INavigatorContentService getNavigatorContentService(); + + /** + *

+ * Provides access to the Workbench Site of the current Common Navigator. + * The workbench site is used to access to the Workbench Page or services. + *

+ * + * @return the Workbench site of the Common Navigator + */ + public IWorkbenchSite getWorkbenchSite(); + + /** + *

+ * Return or creates a valid context for this Common Navigator + *

+ * + * @return the context of this Common Navigator + */ + public ICommonViewerSite getCommonViewerSite(); + + /** + * @return the title of this Common Navigator + */ + public String getTitle(); + + /** + *

+ * Provides access to the ActionBars of this Common Navigator. This method + * is an abstraction to access to ActionBars from IViewPart, + * IContentOutlinePage... + *

+ * + * @return the ActionBar of this Common Navigator + */ + public IActionBars getActionBars(); +} Index: src/org/eclipse/ui/internal/navigator/CommonNavigatorViewActionGroup.java =================================================================== RCS file: src/org/eclipse/ui/internal/navigator/CommonNavigatorViewActionGroup.java diff -N src/org/eclipse/ui/internal/navigator/CommonNavigatorViewActionGroup.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/ui/internal/navigator/CommonNavigatorViewActionGroup.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,114 @@ +/******************************************************************************* + * Copyright (c) 2003, 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.navigator; + +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.commands.ActionHandler; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.handlers.IHandlerService; +import org.eclipse.ui.internal.navigator.actions.LinkEditorAction; +import org.eclipse.ui.internal.navigator.extensions.LinkHelperService; +import org.eclipse.ui.navigator.CommonNavigator; +import org.eclipse.ui.navigator.CommonViewer; +import org.eclipse.ui.navigator.INavigatorViewerDescriptor; + +/** + * + * + * @since 3.5 + */ +public class CommonNavigatorViewActionGroup extends CommonNavigatorActionGroup { + + private LinkEditorAction toggleLinkingAction; + + private final LinkHelperService linkHelperService; + + /** + * Create a action group for Collapse All, Link with editor, and Select + * Filters. + * + * @param aNavigator + * The IViewPart for this action group + * @param aViewer + * The Viewer for this action group + * @param linkHelperService + * the link service helper + */ + public CommonNavigatorViewActionGroup(CommonNavigator aNavigator, + CommonViewer aViewer, LinkHelperService linkHelperService) { + super(aNavigator, aViewer); + this.linkHelperService = linkHelperService; + makeViewActions(); + } + + /** + * + */ + private void makeViewActions() { + IHandlerService service = (IHandlerService) getCommonNavigator() + .getWorkbenchSite().getService(IHandlerService.class); + + INavigatorViewerDescriptor viewerDescriptor = getCommonViewer() + .getNavigatorContentService().getViewerDescriptor(); + boolean hideLinkWithEditorAction = viewerDescriptor + .getBooleanConfigProperty(INavigatorViewerDescriptor.PROP_HIDE_LINK_WITH_EDITOR_ACTION); + if (!hideLinkWithEditorAction) { + toggleLinkingAction = new LinkEditorAction( + (CommonNavigator) getCommonNavigator(), getCommonViewer(), + linkHelperService); + ImageDescriptor syncIcon = getImageDescriptor("elcl16/synced.gif"); //$NON-NLS-1$ + toggleLinkingAction.setImageDescriptor(syncIcon); + toggleLinkingAction.setHoverImageDescriptor(syncIcon); + service.activateHandler( + toggleLinkingAction.getActionDefinitionId(), + new ActionHandler(toggleLinkingAction)); + } + + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars + * ) + */ + public void fillActionBars(IActionBars theActionBars) { + super.fillActionBars(theActionBars); + + IMenuManager menu = theActionBars.getMenuManager(); + + if (toggleLinkingAction != null) { + menu + .insertAfter(IWorkbenchActionConstants.MB_ADDITIONS + + "-end", toggleLinkingAction); //$NON-NLS-1$ + + theActionBars.getToolBarManager().add(toggleLinkingAction); + } + + theActionBars.updateActionBars(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.actions.ActionGroup#dispose() + */ + public void dispose() { + super.dispose(); + if (toggleLinkingAction != null) { + toggleLinkingAction.dispose(); + } + } + +} Index: src/org/eclipse/ui/navigator/CommonNavigatorOutline.java =================================================================== RCS file: src/org/eclipse/ui/navigator/CommonNavigatorOutline.java diff -N src/org/eclipse/ui/navigator/CommonNavigatorOutline.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/ui/navigator/CommonNavigatorOutline.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,406 @@ +/*********************************************************************** + * Copyright (c) 2008 Anyware Technologies + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Anyware Technologies - initial API and implementation + * + * $Id$ + **********************************************************************/ + +package org.eclipse.ui.navigator; + +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.IWorkbenchSite; +import org.eclipse.ui.actions.ActionGroup; +import org.eclipse.ui.internal.navigator.CommonNavigatorActionGroup; +import org.eclipse.ui.internal.navigator.CommonNavigatorManager; +import org.eclipse.ui.internal.navigator.CommonNavigatorMessages; +import org.eclipse.ui.part.Page; +import org.eclipse.ui.views.contentoutline.IContentOutlinePage; + +/** + *

+ * This class provides an implementation of Common Navigator hosted in an + * IContentOutlinePage. + * + *

+ * 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. + * + * @since 3.5 + */ +public abstract class CommonNavigatorOutline extends Page implements + IContentOutlinePage, ICommonNavigator { + + private static final Class INAVIGATOR_CONTENT_SERVICE = INavigatorContentService.class; + private static final Class COMMON_VIEWER_CLASS = CommonViewer.class; + + private CommonViewer commonViewer; + + private CommonNavigatorManager commonManager; + + private ActionGroup commonActionGroup; + + private IMemento memento; + + /** + * + */ + public CommonNavigatorOutline() { + super(); + } + + /** + *

+ * Returns The id used to initialize the Common Viewer from extensions. It + * is recommended to use the same id as the editor providing this Outline. + *

+ * + * @return The Id of the Common Viewer + */ + protected abstract String getCommonViewerId(); + + /** + *

+ * Constructs and returns an instance of {@link CommonViewer}. The ID from + * getCommonViewer() 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. + *

+ * + * @param aParent + * A composite parent to contain the Common Viewer + * @return An initialized instance of CommonViewer + */ + protected CommonViewer createCommonViewer(Composite aParent) { + CommonViewer aViewer = new CommonViewer(getCommonViewerId(), aParent, + SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); + initListeners(aViewer); + aViewer.getNavigatorContentService().restoreState(memento); + return aViewer; + } + + /** + *

+ * Adds the listeners to the Common Viewer. + *

+ * + * @param viewer + * The viewer + * @since 2.0 + */ + protected void initListeners(TreeViewer viewer) { + + viewer.addDoubleClickListener(new IDoubleClickListener() { + + public void doubleClick(DoubleClickEvent event) { + try { + handleDoubleClick(event); + } catch (RuntimeException re) { + re.printStackTrace(); + } + } + }); + } + + /** + *

+ * This method can be overridden to customize the behavior of the double + * click. + *

+ * + * @param anEvent + * Supplied by the DoubleClick listener. + */ + protected void handleDoubleClick(DoubleClickEvent anEvent) { + + IStructuredSelection selection = (IStructuredSelection) anEvent + .getSelection(); + Object element = selection.getFirstElement(); + + TreeViewer viewer = getCommonViewer(); + if (viewer.isExpandable(element)) { + viewer.setExpandedState(element, !viewer.getExpandedState(element)); + } + } + + /** + *

+ * The Common Navigator Manager handles the setup of the Common Navigator + * Menu, manages updates to the ActionBars from {@link CommonActionProvider} + *   extensions as the user's selection changes, and also updates the + * status bar based on the current selection. + * + * @return The Common Navigator Manager class which handles menu population + * and ActionBars + */ + protected CommonNavigatorManager createCommonManager() { + return new CommonNavigatorManager(this, memento); + } + + /** + *

+ * The ActionGroup is used to populate the ActionBars of Common Navigator , + * and the returned implementation will have an opportunity to fill the + * ActionBars of the outline as soon as it is created. ( + * {@link ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)}. + *

+ *

+ * The default implementation returns an action group which will add the + * following actions: + *

+ * + * @return The Action Group to be associated with the Common Navigator View + * Part. + */ + protected ActionGroup createCommonActionGroup() { + return new CommonNavigatorActionGroup(this, commonViewer); + } + + /** + * @see org.eclipse.ui.part.Page#createControl(org.eclipse.swt.widgets.Composite) + */ + public void createControl(Composite parent) { + commonViewer = createCommonViewer(parent); + + try { + commonViewer.getControl().setRedraw(false); + + INavigatorFilterService filterService = commonViewer + .getNavigatorContentService().getFilterService(); + ViewerFilter[] visibleFilters = filterService + .getVisibleFilters(true); + for (int i = 0; i < visibleFilters.length; i++) { + commonViewer.addFilter(visibleFilters[i]); + } + + commonViewer.setSorter(new CommonViewerSorter()); + + /* + * make sure input is set after sorters and filters to avoid + * unnecessary refreshes + */ + commonViewer.setInput(getInitialInput()); + + getSite().setSelectionProvider(commonViewer); + + } finally { + commonViewer.getControl().setRedraw(true); + } + + /* + * Create the CommonNavigatorManager last because information about the + * state of the CommonNavigator is required for the initialization of + * the CommonNavigatorManager + */ + commonManager = createCommonManager(); + if (memento != null) { + commonViewer.getNavigatorContentService().restoreState(memento); + } + + commonActionGroup = createCommonActionGroup(); + commonActionGroup.fillActionBars(getActionBars()); + + } + + /** + *

+ * 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. + *

+ * + * @see org.eclipse.ui.part.WorkbenchPart#dispose() + */ + public void dispose() { + if (commonManager != null) { + commonManager.dispose(); + } + if (commonActionGroup != null) { + commonActionGroup.dispose(); + } + super.dispose(); + } + + /** + * @see org.eclipse.ui.part.Page#getControl() + */ + public Control getControl() { + return commonViewer.getControl(); + } + + /** + * Returns an object which is an instance of the given class associated with + * this object. Returns null if no such object can be found. + * + * @param adapter + * the adapter class to look up + * @return a object castable to the given class, or null if + * this object does not have an adapter for the given class + */ + public Object getAdapter(Class adapter) { + if (adapter == COMMON_VIEWER_CLASS) { + return getCommonViewer(); + } else if (adapter == INAVIGATOR_CONTENT_SERVICE) { + return getCommonViewer().getNavigatorContentService(); + } + return null; + } + + /** + * @see org.eclipse.ui.part.Page#setFocus() + */ + public void setFocus() { + if (commonViewer != null) { + commonViewer.getTree().setFocus(); + } + } + + /** + *

+ * Subclasses should override this method to define the initial input of the + * Common Navigator Outline. + *

+ * + * @return The initial input for the viewer. Defaults to + * getSite().getPage().getInput() + */ + protected Object getInitialInput() { + return getSite().getPage().getInput(); + } + + /** + * @see org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) + */ + public void addSelectionChangedListener(ISelectionChangedListener listener) { + getCommonViewer().addSelectionChangedListener(listener); + } + + /** + * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection() + */ + public ISelection getSelection() { + return getCommonViewer().getSelection(); + } + + /** + * @see org.eclipse.jface.viewers.ISelectionProvider#removeSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) + */ + public void removeSelectionChangedListener( + ISelectionChangedListener listener) { + getCommonViewer().removeSelectionChangedListener(listener); + } + + /** + * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection) + */ + public void setSelection(ISelection selection) { + getCommonViewer().setSelection(selection); + } + + /** + * @see org.eclipse.ui.navigator.ICommonNavigator#getActionBars() + */ + public IActionBars getActionBars() { + return getSite().getActionBars(); + } + + /** + * @see org.eclipse.ui.navigator.ICommonNavigator#getCommonViewer() + */ + public CommonViewer getCommonViewer() { + return commonViewer; + } + + /** + * @see org.eclipse.ui.navigator.ICommonNavigator#getCommonViewerSite() + */ + public ICommonViewerSite getCommonViewerSite() { + return CommonViewerSiteFactory.createCommonViewerSite( + getCommonViewerId(), getSite()); + } + + /** + * @return The Navigator Content Service which populates this instance of + * Common Navigator + */ + public INavigatorContentService getNavigatorContentService() { + return getCommonViewer().getNavigatorContentService(); + } + + /** + * @see org.eclipse.ui.navigator.ICommonNavigator#getTitle() + */ + public String getTitle() { + return CommonNavigatorMessages.CommonNavigatorOutline_DefaultTitle; + } + + /** + * @see org.eclipse.ui.navigator.ICommonNavigator#getWorkbenchSite() + */ + public IWorkbenchSite getWorkbenchSite() { + return getSite(); + } + + /** + *

+ * 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. + *

+ * + * @see org.eclipse.ui.part.ISetSelectionTarget#selectReveal(org.eclipse.jface.viewers.ISelection) + */ + public void selectReveal(ISelection selection) { + if (commonViewer != null) { + if (selection instanceof IStructuredSelection) { + Object[] newSelection = ((IStructuredSelection) selection) + .toArray(); + Object[] expandedElements = commonViewer.getExpandedElements(); + Object[] newExpandedElements = new Object[newSelection.length + + expandedElements.length]; + System.arraycopy(expandedElements, 0, newExpandedElements, 0, + expandedElements.length); + System.arraycopy(newSelection, 0, newExpandedElements, + expandedElements.length, newSelection.length); + commonViewer.setExpandedElements(newExpandedElements); + } + commonViewer.setSelection(selection, true); + } + } + +}