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 17 Jun 2008 16:40:07 -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; @@ -75,20 +73,20 @@ private final ILabelProvider labelProvider; private UpdateActionBarsJob updateActionBars; - + private ISelectionChangedListener statusBarListener = new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent anEvent) { + public void selectionChanged(SelectionChangedEvent anEvent) { updateStatusBar(anEvent.getSelection()); } - + }; - + private class UpdateActionBarsJob extends UIJob { public UpdateActionBarsJob(String label) { super(label); } - + public IStatus runInUIThread(IProgressMonitor monitor) { SafeRunner.run(new ISafeRunnable() { @@ -98,23 +96,29 @@ * @see org.eclipse.core.runtime.ISafeRunnable#run() */ public void run() throws Exception { - if(commonNavigator.getCommonViewer().getInput() != null) { - IStructuredSelection selection = new StructuredSelection(commonNavigator.getCommonViewer().getInput()); + 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()); } } + /* * (non-Javadoc) * - * @see org.eclipse.core.runtime.ISafeRunnable#handleException(java.lang.Throwable) + * @see + * org.eclipse.core.runtime.ISafeRunnable#handleException(java + * .lang.Throwable) */ public void handleException(Throwable exception) { - NavigatorPlugin.logError(0, exception.getMessage(), exception); + NavigatorPlugin.logError(0, exception.getMessage(), + exception); } }); return Status.OK_STATUS; - } + } } /** @@ -127,10 +131,10 @@ * The CommonNavigator managed by this class. Requires a non-null * value. */ - public CommonNavigatorManager(CommonNavigator aNavigator) { + public CommonNavigatorManager(ICommonNavigator aNavigator) { this(aNavigator, null); } - + /** *

* Adds listeners to aNavigator to listen for selection changes and respond @@ -140,54 +144,55 @@ * @param aNavigator * The CommonNavigator managed by this class. Requires a non-null * value. - * @param aMemento a memento for restoring state, or null + * @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(); labelProvider = (ILabelProvider) commonNavigator.getCommonViewer() .getLabelProvider(); - + init(aMemento); } - private void init(IMemento memento) { - + updateActionBars = new UpdateActionBarsJob(commonNavigator.getTitle()); - + CommonViewer commonViewer = commonNavigator.getCommonViewer(); commonViewer.addSelectionChangedListener(this); 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.setContext(new ActionContext(commonNavigator + .getCommonViewer().getSelection())); + actionService.fillActionBars(commonNavigator.getActionBars()); openAction.run(); } - }); + }); - if(memento != null) + if (memento != null) restoreState(memento); - + initContextMenu(); initViewMenu(); @@ -195,12 +200,13 @@ /** *

- * Called by {@link CommonNavigator} when the View Part is disposed. + * Called by {@link ICommonNavigator} when the View Part is disposed. * */ public void dispose() { commonNavigator.getCommonViewer().removeSelectionChangedListener(this); - commonNavigator.getCommonViewer().removeSelectionChangedListener(statusBarListener); + commonNavigator.getCommonViewer().removeSelectionChangedListener( + statusBarListener); actionService.dispose(); } @@ -217,8 +223,7 @@ IStructuredSelection structuredSelection = (IStructuredSelection) anEvent .getSelection(); actionService.setContext(new ActionContext(structuredSelection)); - actionService.fillActionBars(commonNavigator.getViewSite() - .getActionBars()); + actionService.fillActionBars(commonNavigator.getActionBars()); } } @@ -229,7 +234,7 @@ */ public void restoreState(IMemento aMemento) { actionService.restoreState(aMemento); - + } /** @@ -284,14 +289,14 @@ } 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 + "-end"));//$NON-NLS-1$ - + updateActionBars.schedule(DELAY); - + } /** 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 17 Jun 2008 16:40:06 -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() - .getService(IHandlerService.class); + 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); @@ -103,7 +95,8 @@ collapseAllAction.setImageDescriptor(collapseAllIcon); collapseAllAction.setHoverImageDescriptor(collapseAllIcon); collapseAllHandler = new CollapseAllHandler(commonViewer); - service.activateHandler(CollapseAllHandler.COMMAND_ID, collapseAllHandler); + service.activateHandler(CollapseAllHandler.COMMAND_ID, + collapseAllHandler); } filterGroup = new FilterActionGroup(commonViewer); @@ -113,10 +106,11 @@ /* * (non-Javadoc) * - * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars) + * @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 +118,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,10 +128,7 @@ */ public void dispose() { super.dispose(); - if (toggleLinkingAction != null) { - toggleLinkingAction.dispose(); - } - if (collapseAllHandler!=null) { + 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 17 Jun 2008 16:40:07 -0000 @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2005, 2008 IBM Corporation and others. +# Copyright (c) 2005, 2007 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 @@ -20,7 +20,7 @@ Navigator_statusLineMultiSelect={0} items selected SelectFiltersActionDelegate_1=Select and deselect filters to apply to the content in the tree CommonFilterSelectionDialog_Select_the_available_extensions=Select the available extensions to show (unchecked extensions will not display content)\: -SelectFiltersActionDelegate_0=&Customize View... +SelectFiltersActionDelegate_0=Customize View... CollapseAllActionDelegate_0=Collapse All Too_many_elements_Warning=Too many elements of type\: {0} in extension "{1}" defined in bundle "{2}". NewProjectAction_text=P&roject... @@ -33,7 +33,7 @@ CommonFilterSelectionDialog_Available_Filters=Filters StructuredViewerManager_0=Refresh Common Viewer Tree LinkEditorActionDelegate_1=Link open editors with content in the Navigator -LinkEditorActionDelegate_0=&Link Editor +LinkEditorActionDelegate_0=Link Editor Copy=Copy Cut=Cut NavigatorViewerDescriptor_Popup_Menu_Overridden=Warning\: popupMenuId of "{0}" was overridden\: old value \= "{1}", new value \= "{2}". @@ -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 17 Jun 2008 16:40:07 -0000 @@ -15,9 +15,9 @@ /** * *

- * EXPERIMENTAL. This class or interface has been added as - * part of a work in progress. There is a guarantee neither that this API will - * work nor that it will remain the same. Please do not use this API without + * EXPERIMENTAL. This class or interface has been added as part + * of a work in progress. There is a guarantee neither that this API will work + * nor that it will remain the same. Please do not use this API without * consulting with the Platform/UI team. *

* @@ -123,6 +123,8 @@ /** */ 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 17 Jun 2008 16:40:07 -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,71 +51,32 @@ *

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

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

+ *

* 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. + * 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; it is not intended to be subclassed. *

+ * * @noextend This class is not intended to be subclassed by clients. - * + * * @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; private static final Class ISHOW_IN_TARGET_CLASS = IShowInTarget.class; - - private static final String HELP_CONTEXT = NavigatorPlugin.PLUGIN_ID + ".common_navigator"; //$NON-NLS-1$ + + private static final String HELP_CONTEXT = NavigatorPlugin.PLUGIN_ID + + ".common_navigator"; //$NON-NLS-1$ /** *

@@ -136,7 +98,7 @@ private String LINKING_ENABLED = "CommonNavigator.LINKING_ENABLED"; //$NON-NLS-1$ private LinkHelperService linkService; - + /** * */ @@ -155,30 +117,31 @@ */ public void createPartControl(Composite aParent) { - commonViewer = createCommonViewer(aParent); + commonViewer = createCommonViewer(aParent); try { commonViewer.getControl().setRedraw(false); - + INavigatorFilterService filterService = commonViewer .getNavigatorContentService().getFilterService(); - ViewerFilter[] visibleFilters = filterService.getVisibleFilters(true); + 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 + * make sure input is set after sorters and filters to avoid + * unnecessary refreshes */ - commonViewer.setInput(getInitialInput()); - + commonViewer.setInput(getInitialInput()); + getSite().setSelectionProvider(commonViewer); - + updateTitle(); - } finally { + } finally { commonViewer.getControl().setRedraw(true); } @@ -188,13 +151,13 @@ * the CommonNavigatorManager */ commonManager = createCommonManager(); - if (memento != null) { + if (memento != null) { commonViewer.getNavigatorContentService().restoreState(memento); } commonActionGroup = createCommonActionGroup(); commonActionGroup.fillActionBars(getViewSite().getActionBars()); - + ISaveablesLifecycleListener saveablesLifecycleListener = new ISaveablesLifecycleListener() { ISaveablesLifecycleListener siteSaveablesLifecycleListener = (ISaveablesLifecycleListener) getSite() .getService(ISaveablesLifecycleListener.class); @@ -206,17 +169,19 @@ siteSaveablesLifecycleListener.handleLifecycleEvent(event); } }; - commonViewer.getNavigatorContentService() - .getSaveablesService().init(this, getCommonViewer(), - saveablesLifecycleListener); - - commonViewer.addSelectionChangedListener(new ISelectionChangedListener() { - - public void selectionChanged(SelectionChangedEvent event) { - firePropertyChange(PROP_DIRTY); - }}); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(commonViewer.getControl(), HELP_CONTEXT); + commonViewer.getNavigatorContentService().getSaveablesService().init( + this, getCommonViewer(), saveablesLifecycleListener); + + commonViewer + .addSelectionChangedListener(new ISelectionChangedListener() { + + public void selectionChanged(SelectionChangedEvent event) { + firePropertyChange(PROP_DIRTY); + } + }); + + PlatformUI.getWorkbench().getHelpSystem().setHelp( + commonViewer.getControl(), HELP_CONTEXT); } /** @@ -235,7 +200,7 @@ if (commonManager != null) { commonManager.dispose(); } - if(commonActionGroup != null) { + if (commonActionGroup != null) { commonActionGroup.dispose(); } super.dispose(); @@ -303,13 +268,17 @@ */ public void selectReveal(ISelection selection) { if (commonViewer != null) { - if(selection instanceof IStructuredSelection) { - Object[] newSelection = ((IStructuredSelection)selection).toArray(); + 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); + 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); } @@ -317,9 +286,9 @@ /** *

- * Linking is handled by an action which listens for - * changes to the {@link CommonNavigator#IS_LINKING_ENABLED_PROPERTY}. - * Custom implementations that wish to override this functionality, need to + * Linking is handled by an action which listens for changes to the + * {@link CommonNavigator#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. * @@ -341,42 +310,39 @@ /** *

- * 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. + * {@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(); } /** - * 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 + * 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(); - } else if ( adapter == ISHOW_IN_TARGET_CLASS) { + } else if (adapter == ISHOW_IN_TARGET_CLASS) { return this; } return super.getAdapter(adapter); @@ -392,10 +358,10 @@ /** *

- * Constructs and returns an instance of {@link 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. + * Constructs and returns an instance of {@link 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. *

* * @param aParent @@ -444,16 +410,18 @@ */ protected void handleDoubleClick(DoubleClickEvent anEvent) { - IAction openHandler = getViewSite().getActionBars().getGlobalActionHandler(ICommonActionConstants.OPEN); - - if(openHandler == null) { + IAction openHandler = getViewSite().getActionBars() + .getGlobalActionHandler(ICommonActionConstants.OPEN); + + if (openHandler == null) { IStructuredSelection selection = (IStructuredSelection) anEvent .getSelection(); Object element = selection.getFirstElement(); - + TreeViewer viewer = getCommonViewer(); if (viewer.isExpandable(element)) { - viewer.setExpandedState(element, !viewer.getExpandedState(element)); + viewer.setExpandedState(element, !viewer + .getExpandedState(element)); } } } @@ -461,9 +429,9 @@ /** *

* 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. + * 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 @@ -476,7 +444,8 @@ *

* 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. ({@link ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)}. + * fill the ActionBars of the view as soon as it is created. ( + * {@link ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)}. *

*

* The default implementation returns an action group which will add the @@ -503,7 +472,8 @@ * Part. */ protected ActionGroup createCommonActionGroup() { - return new CommonNavigatorActionGroup(this, commonViewer, getLinkHelperService()); + return new CommonNavigatorViewActionGroup(this, commonViewer, + getLinkHelperService()); } /** @@ -555,22 +525,32 @@ return ""; //$NON-NLS-1$ } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.ui.ISaveablesSource#getSaveables() */ public Saveable[] getSaveables() { - return getNavigatorContentService().getSaveablesService().getSaveables(); + return getNavigatorContentService().getSaveablesService() + .getSaveables(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.ui.ISaveablesSource#getActiveSaveables() */ public Saveable[] getActiveSaveables() { - return getNavigatorContentService().getSaveablesService().getActiveSaveables(); + return getNavigatorContentService().getSaveablesService() + .getActiveSaveables(); } - /* (non-Javadoc) - * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor) + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor + * ) */ public void doSave(IProgressMonitor monitor) { // Ignore. This method is not called because CommonNavigator implements @@ -578,49 +558,60 @@ // Saveable protocol. } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.ui.ISaveablePart#doSaveAs() */ public void doSaveAs() { // ignore } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.ui.ISaveablePart#isDirty() */ public boolean isDirty() { Saveable[] saveables = getSaveables(); for (int i = 0; i < saveables.length; i++) { - if(saveables[i].isDirty()) { + if (saveables[i].isDirty()) { return true; } } return false; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed() */ public boolean isSaveAsAllowed() { return false; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.ui.ISaveablePart#isSaveOnCloseNeeded() */ public boolean isSaveOnCloseNeeded() { return isDirty(); } - /* (non-Javadoc) - * @see org.eclipse.ui.part.IShowInTarget#show(org.eclipse.ui.part.ShowInContext) + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.part.IShowInTarget#show(org.eclipse.ui.part.ShowInContext) */ public boolean show(ShowInContext context) { IStructuredSelection selection = getSelection(context); if (selection != null && !selection.isEmpty()) { selectReveal(selection); return true; - } + } return false; } @@ -628,8 +619,9 @@ if (context == null) return StructuredSelection.EMPTY; ISelection selection = context.getSelection(); - if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) - return (IStructuredSelection)selection; + if (selection != null && !selection.isEmpty() + && selection instanceof IStructuredSelection) + return (IStructuredSelection) selection; Object input = context.getInput(); if (input instanceof IEditorInput) { LinkHelperService lhs = getLinkHelperService(); @@ -643,8 +635,30 @@ private synchronized LinkHelperService getLinkHelperService() { if (linkService == null) - linkService = new LinkHelperService((NavigatorContentService)getCommonViewer().getNavigatorContentService()); + 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 17 Jun 2008 16:40:07 -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 17 Jun 2008 16:40:07 -0000 @@ -69,8 +69,8 @@ ILinkHelper[] helpers = linkService .getLinkHelpersFor(sSelection.getFirstElement()); if (helpers.length > 0) { - helpers[0].activateEditor(commonNavigator.getSite() - .getPage(), sSelection); + helpers[0].activateEditor(commonNavigator + .getWorkbenchSite().getPage(), sSelection); } } } @@ -87,8 +87,8 @@ SafeRunner.run(new ISafeRunnable() { public void run() throws Exception { - IWorkbenchPage page = commonNavigator.getSite() - .getPage(); + IWorkbenchPage page = commonNavigator + .getWorkbenchSite().getPage(); if (page != null) { IEditorPart editor = page.getActiveEditor(); if (editor != null) { @@ -168,7 +168,7 @@ updateLinkingEnabled(commonNavigator.isLinkingEnabled()); - commonNavigator.addPropertyListener(this); + // commonNavigator.addPropertyListener(this); // linkHelperRegistry = new // LinkHelperManager(commonViewer.getNavigatorContentService()); @@ -178,11 +178,11 @@ * */ public void dispose() { - commonNavigator.removePropertyListener(this); + // commonNavigator.removePropertyListener(this); if (isChecked()) { commonViewer.removePostSelectionChangedListener(this); - commonNavigator.getSite().getPage() - .removePartListener(partListener); + commonNavigator.getWorkbenchSite().getPage().removePartListener( + partListener); } } @@ -225,7 +225,7 @@ * (non-Javadoc) * * @see org.eclipse.ui.IPropertyListener#propertyChanged(java.lang.Object, - * int) + * int) */ public void propertyChanged(Object aSource, int aPropertyId) { switch (aPropertyId) { @@ -245,11 +245,12 @@ updateSelectionJob.schedule(BRIEF_DELAY); commonViewer.addPostSelectionChangedListener(this); - commonNavigator.getSite().getPage().addPartListener(partListener); + commonNavigator.getWorkbenchSite().getPage().addPartListener( + partListener); } else { commonViewer.removePostSelectionChangedListener(this); - commonNavigator.getSite().getPage() - .removePartListener(partListener); + 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 17 Jun 2008 16:40:06 -0000 @@ -6,18 +6,11 @@ Bundle-Activator: org.eclipse.ui.internal.navigator.NavigatorPlugin Bundle-Vendor: %Plugin.providerName Bundle-Localization: plugin -Export-Package: org.eclipse.ui.internal.navigator;x-friends:="org.eclipse.ui.navigator.ide,org.eclipse.ui.navigator.resources", - org.eclipse.ui.internal.navigator.actions;x-friends:="org.eclipse.ui.navigator.ide,org.eclipse.ui.navigator.resources", - org.eclipse.ui.internal.navigator.dnd;x-friends:="org.eclipse.ui.navigator.ide,org.eclipse.ui.navigator.resources", - org.eclipse.ui.internal.navigator.extensions;x-friends:="org.eclipse.ui.navigator.ide,org.eclipse.ui.navigator.resources", - org.eclipse.ui.internal.navigator.filters;x-friends:="org.eclipse.ui.navigator.ide,org.eclipse.ui.navigator.resources,org.eclipse.ui.tests.navigator", - org.eclipse.ui.internal.navigator.sorters;x-internal:=true, - org.eclipse.ui.internal.navigator.wizards;x-internal:=true, - org.eclipse.ui.navigator Require-Bundle: org.eclipse.jface;bundle-version="[3.2.0,4.0.0)", 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); + } + } + +}