diff --git a/org.fortiss.tooling.kernel/trunk/plugin.xml b/org.fortiss.tooling.kernel/trunk/plugin.xml index e6573c42a08454ba738fdd3987190e2a4d051b27..f5fb82f826d668819f071abb44ed9890521a3bfd 100644 --- a/org.fortiss.tooling.kernel/trunk/plugin.xml +++ b/org.fortiss.tooling.kernel/trunk/plugin.xml @@ -48,7 +48,7 @@ <menuContribution allPopups="false" - locationURI="popup:org.fortiss.tooling.kernel.model.navigator?before=repository"> + locationURI="popup:org.fortiss.tooling.kernel.model.navigator?before=custom"> <menu icon="icons/add.png" id="org.fortiss.tooling.kernel.model.navigator.newmenu" @@ -69,6 +69,10 @@ id="org.fortiss.tooling.kernel.model.navigator.newmenu.content"> </dynamic> </menu> + </menuContribution> + <menuContribution + allPopups="false" + locationURI="popup:org.fortiss.tooling.kernel.model.navigator?after=repository"> <menu icon="icons/server.png" id="org.fortiss.tooling.kernel.model.navigator.repositorymenu" diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/ICustomMenuContributor.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/ICustomMenuContributor.java new file mode 100644 index 0000000000000000000000000000000000000000..9f9704e41cd0c7b290fefa06bfda91bc090a86af --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/ICustomMenuContributor.java @@ -0,0 +1,33 @@ +/*--------------------------------------------------------------------------+ +$Id$ +| | +| Copyright 2011 ForTISS GmbH | +| | +| Licensed under the Apache License, Version 2.0 (the "License"); | +| you may not use this file except in compliance with the License. | +| You may obtain a copy of the License at | +| | +| http://www.apache.org/licenses/LICENSE-2.0 | +| | +| Unless required by applicable law or agreed to in writing, software | +| distributed under the License is distributed on an "AS IS" BASIS, | +| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | +| See the License for the specific language governing permissions and | +| limitations under the License. | ++--------------------------------------------------------------------------*/ +package org.fortiss.tooling.kernel.interfaces; + +import org.fortiss.tooling.kernel.services.IContextMenuService; + +/** + * Classes implementing this interface contribute custom menu entries or + * submenus to the context menu provided by the {@link IContextMenuService}. + * + * @author hoelzlf + * @author $Author$ + * @version $Rev$ + * @levd.rating RED Rev: + */ +public interface ICustomMenuContributor { + // TODO (FH): implement +} diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ActionService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ActionService.java index abcfe4f8de6f5202b0e1289f3dd439aa3218a742..bcd0fd98a3b556f2503822d5d9d1d30f8e08d79e 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ActionService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ActionService.java @@ -21,8 +21,7 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; +import org.eclipse.jface.action.IMenuManager; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IEditorSite; import org.eclipse.ui.ISharedImages; @@ -109,11 +108,7 @@ public class ActionService implements IActionService { /** {@inheritDoc} */ @Override - public void addGlobalDefaultActionSectionToMenu(MenuManager menuManager) { - Separator globalDefaults = new Separator(GROUP_GLOBAL_DEFAULTS); - globalDefaults.setVisible(true); - menuManager.add(globalDefaults); - + public void addGlobalDefaultActionSectionToMenu(IMenuManager menuManager) { menuManager.appendToGroup(GROUP_GLOBAL_DEFAULTS, globalDeleteAction); menuManager.appendToGroup(GROUP_GLOBAL_DEFAULTS, globalUndoAction); } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ContextMenuService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ContextMenuService.java index d9945d0b08634efc6d162bcaab4fc9e9b438395b..5114c99b820d47bce9f4a6f3d429b16d7758e680 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ContextMenuService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ContextMenuService.java @@ -17,6 +17,13 @@ $Id$ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.internal; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.fortiss.tooling.kernel.interfaces.ICustomMenuContributor; +import org.fortiss.tooling.kernel.services.IActionService; import org.fortiss.tooling.kernel.services.IContextMenuService; /** @@ -29,4 +36,55 @@ import org.fortiss.tooling.kernel.services.IContextMenuService; */ public class ContextMenuService implements IContextMenuService { + /** {@inheritDoc} */ + @Override + public MenuManager createDefaultContextMenu( + ICustomMenuContributor menuContributor) { + MenuManager menuManager = new MenuManager("#PopupMenu"); + menuManager.setRemoveAllWhenShown(true); + menuManager.addMenuListener(new MenuCreator(menuContributor)); + + Separator repositorySection = new Separator("repository"); + repositorySection.setVisible(true); + menuManager.add(repositorySection); + + return menuManager; + } + + /** Wrapper class for menu creation. */ + private static class MenuCreator implements IMenuListener { + + /** Stores the custom menu contributor. */ + private final ICustomMenuContributor contributor; + + /** Constructor. */ + public MenuCreator(ICustomMenuContributor contributor) { + this.contributor = contributor; + } + + /** {@inheritDoc} */ + @Override + public void menuAboutToShow(IMenuManager menu) { + if (!menu.isEmpty()) { + return; + } + addVisibleSectionSeparator(menu, CUSTOM_MENU_SEPARATOR_ID); + addVisibleSectionSeparator(menu, + ActionService.GROUP_GLOBAL_DEFAULTS); + addVisibleSectionSeparator(menu, REPOSITORY_MENU_SEPARATOR_ID); + addVisibleSectionSeparator(menu, + IWorkbenchActionConstants.MB_ADDITIONS); + + // TODO (FH): add custom menu to custom section + IActionService.INSTANCE.addGlobalDefaultActionSectionToMenu(menu); + } + } + + /** Adds a visible section separator. */ + private static void addVisibleSectionSeparator(IMenuManager menu, + String sectionName) { + Separator separator = new Separator(sectionName); + separator.setVisible(true); + menu.add(separator); + } } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorViewPart.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorViewPart.java index 1319e0c8d41eee8f35a910f18e6f05db9dd34888..568ca7101bd8617a519418f66ce93d1d16a2da2e 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorViewPart.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorViewPart.java @@ -25,7 +25,6 @@ import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.notify.impl.AdapterImpl; import org.eclipse.emf.ecore.EObject; import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; import org.eclipse.jface.viewers.DecoratingLabelProvider; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; @@ -34,11 +33,9 @@ import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Menu; import org.eclipse.ui.IDecoratorManager; import org.eclipse.ui.ISelectionListener; -import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.ViewPart; @@ -49,6 +46,7 @@ import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; import org.fortiss.tooling.kernel.ToolingKernelActivator; import org.fortiss.tooling.kernel.internal.NavigatorService; import org.fortiss.tooling.kernel.services.IActionService; +import org.fortiss.tooling.kernel.services.IContextMenuService; import org.fortiss.tooling.kernel.services.IEditorService; import org.fortiss.tooling.kernel.services.INavigatorService; import org.fortiss.tooling.kernel.services.IPropertiesService; @@ -178,23 +176,27 @@ public final class NavigatorViewPart extends ViewPart implements viewer = new TreeViewer(parent, SWT.MULTI); if (workspace != null) { + // NOTE that the order of this important. See also JDT package + // explorer. IDecoratorManager decoratorManager = PlatformUI.getWorkbench() .getDecoratorManager(); viewer.setLabelProvider(new DecoratingLabelProvider( new NavigatorTreeLabelProvider(), decoratorManager .getLabelDecorator())); viewer.setContentProvider(new NavigatorTreeContentProvider()); + + createContextMenu(); + getSite().setSelectionProvider(viewer); + viewer.setInput(workspace); - viewer.addDoubleClickListener(this); - } - createContextMenu(); + viewer.addDoubleClickListener(this); - IActionService.INSTANCE.registerGlobalActions(getViewSite()); + IActionService.INSTANCE.registerGlobalActions(getViewSite()); - PlatformUI.getWorkbench().getActiveWorkbenchWindow() - .getSelectionService().addSelectionListener(this); - getSite().setSelectionProvider(viewer); + PlatformUI.getWorkbench().getActiveWorkbenchWindow() + .getSelectionService().addSelectionListener(this); + } // FIXME: whats that good for? // if (viewer.getTree().getItems().length > 0) { @@ -205,25 +207,13 @@ public final class NavigatorViewPart extends ViewPart implements /** Creates the context menu. */ private void createContextMenu() { - menuManager = new MenuManager("#PopupMenu"); - - Separator repositorySection = new Separator("repository"); - repositorySection.setVisible(true); - menuManager.add(repositorySection); + menuManager = IContextMenuService.INSTANCE + .createDefaultContextMenu(null); - IActionService.INSTANCE - .addGlobalDefaultActionSectionToMenu(menuManager); - - Separator additions = new Separator( - IWorkbenchActionConstants.MB_ADDITIONS); - additions.setVisible(true); - menuManager.add(additions); + Menu contextMenu = menuManager.createContextMenu(viewer.getControl()); + viewer.getControl().setMenu(contextMenu); getSite().registerContextMenu(menuManager, viewer); - - Control control = viewer.getControl(); - Menu menu = menuManager.createContextMenu(control); - control.setMenu(menu); } /** Creates the actions. */ diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IActionService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IActionService.java index a0c2c8196ecb397184ce08e785299af58e0aef73..d9ad1d071b57f87111e3ead29f691403362a6c7f 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IActionService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IActionService.java @@ -17,7 +17,7 @@ $Id$ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.services; -import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.IMenuManager; import org.eclipse.ui.IEditorSite; import org.eclipse.ui.IViewSite; import org.fortiss.tooling.kernel.internal.ActionService; @@ -43,7 +43,7 @@ public interface IActionService { void registerGlobalActions(IEditorSite site); /** Adds the global default actions like undo to the given context menu. */ - void addGlobalDefaultActionSectionToMenu(MenuManager menuManager); + void addGlobalDefaultActionSectionToMenu(IMenuManager menuManager); /** Updates the enabled state of the global actions. */ void update(); diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IContextMenuService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IContextMenuService.java index e17bd3f5230dbd164693d80b1c6591ee0352ebe7..65d3712b66caf755036a3c98d00b7e9804429c59 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IContextMenuService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IContextMenuService.java @@ -17,6 +17,8 @@ $Id$ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.services; +import org.eclipse.jface.action.MenuManager; +import org.fortiss.tooling.kernel.interfaces.ICustomMenuContributor; import org.fortiss.tooling.kernel.internal.ContextMenuService; /** @@ -30,6 +32,15 @@ import org.fortiss.tooling.kernel.internal.ContextMenuService; */ public interface IContextMenuService { + /** Custom menu section separator id. */ + public static final String CUSTOM_MENU_SEPARATOR_ID = "custom"; + + /** Repository menu section separator id. */ + public static final String REPOSITORY_MENU_SEPARATOR_ID = "repository"; + /** Returns the singleton instance of the service. */ public static final IContextMenuService INSTANCE = new ContextMenuService(); + + /** Creates the default context menu provided by the kernel. */ + MenuManager createDefaultContextMenu(ICustomMenuContributor menuContributor); }