Skip to content
Snippets Groups Projects
Commit 2e552b65 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

Extended context menu service

parent 3f36da9a
No related branches found
No related tags found
No related merge requests found
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
<menuContribution <menuContribution
allPopups="false" allPopups="false"
locationURI="popup:org.fortiss.tooling.kernel.model.navigator?before=repository"> locationURI="popup:org.fortiss.tooling.kernel.model.navigator?before=custom">
<menu <menu
icon="icons/add.png" icon="icons/add.png"
id="org.fortiss.tooling.kernel.model.navigator.newmenu" id="org.fortiss.tooling.kernel.model.navigator.newmenu"
...@@ -69,6 +69,10 @@ ...@@ -69,6 +69,10 @@
id="org.fortiss.tooling.kernel.model.navigator.newmenu.content"> id="org.fortiss.tooling.kernel.model.navigator.newmenu.content">
</dynamic> </dynamic>
</menu> </menu>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="popup:org.fortiss.tooling.kernel.model.navigator?after=repository">
<menu <menu
icon="icons/server.png" icon="icons/server.png"
id="org.fortiss.tooling.kernel.model.navigator.repositorymenu" id="org.fortiss.tooling.kernel.model.navigator.repositorymenu"
......
/*--------------------------------------------------------------------------+
$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
}
...@@ -21,8 +21,7 @@ import org.eclipse.emf.ecore.EObject; ...@@ -21,8 +21,7 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jface.action.Action; import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.ui.IActionBars; import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorSite; import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.ISharedImages; import org.eclipse.ui.ISharedImages;
...@@ -109,11 +108,7 @@ public class ActionService implements IActionService { ...@@ -109,11 +108,7 @@ public class ActionService implements IActionService {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void addGlobalDefaultActionSectionToMenu(MenuManager menuManager) { public void addGlobalDefaultActionSectionToMenu(IMenuManager menuManager) {
Separator globalDefaults = new Separator(GROUP_GLOBAL_DEFAULTS);
globalDefaults.setVisible(true);
menuManager.add(globalDefaults);
menuManager.appendToGroup(GROUP_GLOBAL_DEFAULTS, globalDeleteAction); menuManager.appendToGroup(GROUP_GLOBAL_DEFAULTS, globalDeleteAction);
menuManager.appendToGroup(GROUP_GLOBAL_DEFAULTS, globalUndoAction); menuManager.appendToGroup(GROUP_GLOBAL_DEFAULTS, globalUndoAction);
} }
......
...@@ -17,6 +17,13 @@ $Id$ ...@@ -17,6 +17,13 @@ $Id$
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.internal; 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; import org.fortiss.tooling.kernel.services.IContextMenuService;
/** /**
...@@ -29,4 +36,55 @@ import org.fortiss.tooling.kernel.services.IContextMenuService; ...@@ -29,4 +36,55 @@ import org.fortiss.tooling.kernel.services.IContextMenuService;
*/ */
public class ContextMenuService implements 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);
}
} }
...@@ -25,7 +25,6 @@ import org.eclipse.emf.common.notify.Notification; ...@@ -25,7 +25,6 @@ import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl; import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.viewers.DecoratingLabelProvider; import org.eclipse.jface.viewers.DecoratingLabelProvider;
import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.IDoubleClickListener;
...@@ -34,11 +33,9 @@ import org.eclipse.jface.viewers.IStructuredSelection; ...@@ -34,11 +33,9 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IDecoratorManager; import org.eclipse.ui.IDecoratorManager;
import org.eclipse.ui.ISelectionListener; import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI; import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart; import org.eclipse.ui.part.ViewPart;
...@@ -49,6 +46,7 @@ import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; ...@@ -49,6 +46,7 @@ import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import org.fortiss.tooling.kernel.ToolingKernelActivator; import org.fortiss.tooling.kernel.ToolingKernelActivator;
import org.fortiss.tooling.kernel.internal.NavigatorService; import org.fortiss.tooling.kernel.internal.NavigatorService;
import org.fortiss.tooling.kernel.services.IActionService; 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.IEditorService;
import org.fortiss.tooling.kernel.services.INavigatorService; import org.fortiss.tooling.kernel.services.INavigatorService;
import org.fortiss.tooling.kernel.services.IPropertiesService; import org.fortiss.tooling.kernel.services.IPropertiesService;
...@@ -178,23 +176,27 @@ public final class NavigatorViewPart extends ViewPart implements ...@@ -178,23 +176,27 @@ public final class NavigatorViewPart extends ViewPart implements
viewer = new TreeViewer(parent, SWT.MULTI); viewer = new TreeViewer(parent, SWT.MULTI);
if (workspace != null) { if (workspace != null) {
// NOTE that the order of this important. See also JDT package
// explorer.
IDecoratorManager decoratorManager = PlatformUI.getWorkbench() IDecoratorManager decoratorManager = PlatformUI.getWorkbench()
.getDecoratorManager(); .getDecoratorManager();
viewer.setLabelProvider(new DecoratingLabelProvider( viewer.setLabelProvider(new DecoratingLabelProvider(
new NavigatorTreeLabelProvider(), decoratorManager new NavigatorTreeLabelProvider(), decoratorManager
.getLabelDecorator())); .getLabelDecorator()));
viewer.setContentProvider(new NavigatorTreeContentProvider()); viewer.setContentProvider(new NavigatorTreeContentProvider());
createContextMenu();
getSite().setSelectionProvider(viewer);
viewer.setInput(workspace); viewer.setInput(workspace);
viewer.addDoubleClickListener(this);
}
createContextMenu(); viewer.addDoubleClickListener(this);
IActionService.INSTANCE.registerGlobalActions(getViewSite()); IActionService.INSTANCE.registerGlobalActions(getViewSite());
PlatformUI.getWorkbench().getActiveWorkbenchWindow() PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getSelectionService().addSelectionListener(this); .getSelectionService().addSelectionListener(this);
getSite().setSelectionProvider(viewer); }
// FIXME: whats that good for? // FIXME: whats that good for?
// if (viewer.getTree().getItems().length > 0) { // if (viewer.getTree().getItems().length > 0) {
...@@ -205,25 +207,13 @@ public final class NavigatorViewPart extends ViewPart implements ...@@ -205,25 +207,13 @@ public final class NavigatorViewPart extends ViewPart implements
/** Creates the context menu. */ /** Creates the context menu. */
private void createContextMenu() { private void createContextMenu() {
menuManager = new MenuManager("#PopupMenu"); menuManager = IContextMenuService.INSTANCE
.createDefaultContextMenu(null);
Separator repositorySection = new Separator("repository");
repositorySection.setVisible(true);
menuManager.add(repositorySection);
IActionService.INSTANCE Menu contextMenu = menuManager.createContextMenu(viewer.getControl());
.addGlobalDefaultActionSectionToMenu(menuManager); viewer.getControl().setMenu(contextMenu);
Separator additions = new Separator(
IWorkbenchActionConstants.MB_ADDITIONS);
additions.setVisible(true);
menuManager.add(additions);
getSite().registerContextMenu(menuManager, viewer); getSite().registerContextMenu(menuManager, viewer);
Control control = viewer.getControl();
Menu menu = menuManager.createContextMenu(control);
control.setMenu(menu);
} }
/** Creates the actions. */ /** Creates the actions. */
......
...@@ -17,7 +17,7 @@ $Id$ ...@@ -17,7 +17,7 @@ $Id$
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.services; 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.IEditorSite;
import org.eclipse.ui.IViewSite; import org.eclipse.ui.IViewSite;
import org.fortiss.tooling.kernel.internal.ActionService; import org.fortiss.tooling.kernel.internal.ActionService;
...@@ -43,7 +43,7 @@ public interface IActionService { ...@@ -43,7 +43,7 @@ public interface IActionService {
void registerGlobalActions(IEditorSite site); void registerGlobalActions(IEditorSite site);
/** Adds the global default actions like undo to the given context menu. */ /** 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. */ /** Updates the enabled state of the global actions. */
void update(); void update();
......
...@@ -17,6 +17,8 @@ $Id$ ...@@ -17,6 +17,8 @@ $Id$
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.services; 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; import org.fortiss.tooling.kernel.internal.ContextMenuService;
/** /**
...@@ -30,6 +32,15 @@ import org.fortiss.tooling.kernel.internal.ContextMenuService; ...@@ -30,6 +32,15 @@ import org.fortiss.tooling.kernel.internal.ContextMenuService;
*/ */
public interface IContextMenuService { 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. */ /** Returns the singleton instance of the service. */
public static final IContextMenuService INSTANCE = new ContextMenuService(); public static final IContextMenuService INSTANCE = new ContextMenuService();
/** Creates the default context menu provided by the kernel. */
MenuManager createDefaultContextMenu(ICustomMenuContributor menuContributor);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment