diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/ContextMenuSubMenuContributorBase.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/ContextMenuSubMenuContributorBase.java index 9c1475ab3cb5f807008b6402604f0c5182c10703..dba66206b4d7fe537f9f7222fb775f70e378f105 100644 --- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/ContextMenuSubMenuContributorBase.java +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/ContextMenuSubMenuContributorBase.java @@ -18,6 +18,7 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $ package org.fortiss.tooling.kernel.ui.extension.base; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -27,6 +28,7 @@ import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IContributionItem; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; import org.eclipse.jface.resource.ImageDescriptor; import org.fortiss.tooling.kernel.ui.extension.IContextMenuContributor; import org.fortiss.tooling.kernel.ui.extension.base.EObjectActionBase.EObjectActionFactory; @@ -48,7 +50,7 @@ import org.fortiss.tooling.kernel.ui.service.IContextMenuService; * @author trachtenherz * @author $Author: hoelzl $ * @version $Rev: 18709 $ - * @ConQAT.Rating GREEN Hash: 2564CE1D9646C694F694AB86ECF50DDD + * @ConQAT.Rating YELLOW Hash: C9D77819956A4B95AC544B63F2BADF2A */ public abstract class ContextMenuSubMenuContributorBase<T extends EObject> implements IContextMenuContributor { @@ -82,8 +84,31 @@ public abstract class ContextMenuSubMenuContributorBase<T extends EObject> protected IMenuManager createMenu(Collection<Action> actions) { IMenuManager menu = new MenuManager(getMenuName(), getMenuIcon(), getMenuId()); + + // Prepare menu structure hints + MenuStructureHints[] hints; + if (getMenuStructureHints() != null) { + hints = Arrays.copyOf(getMenuStructureHints(), actions.size()); + } else { + hints = new MenuStructureHints[actions.size()]; + Arrays.fill(hints, null); + } + // Now the hints array contains all elements from + // getMenuStructureHints(). It + // also has at least as many elements as the actions collection. If + // getMenuStructureHints() has less elements (or is null), + // than all other elements of the hints array are null. + int i = 0; for (Action a : actions) { + if (hints[i] == MenuStructureHints.SEPARATOR_BEFORE) { + menu.add(new Separator()); + } menu.add(a); + if (hints[i] == MenuStructureHints.SEPARATOR_AFTER) { + menu.add(new Separator()); + } + + ++i; } return menu; } @@ -107,6 +132,31 @@ public abstract class ContextMenuSubMenuContributorBase<T extends EObject> /** Returns the action factories for the actions to be shown in the menu */ protected abstract Collection<EObjectActionFactory<? super T>> getActionFactories(); + /** + * Constants for menu structure hints. + * + * @see ContextMenuSubMenuContributorBase#getMenuStructureHints() + */ + protected static enum MenuStructureHints { + /** Insert a separator before current menu item. */ + SEPARATOR_BEFORE, + /** Insert a separator after current menu item. */ + SEPARATOR_AFTER; + // Further future hints may be e.g.: Begin new sub-menu, End new + // sub-menu + } + + /** + * Returns additional informations about the structure of the menu. If + * {@code null}, the actions are linearly shown in a menu. + * + * @see #getActionFactories() + * @see #createMenu(Collection) + */ + protected MenuStructureHints[] getMenuStructureHints() { + return null; + } + /** The image for the sub-menu */ protected ImageDescriptor getMenuIcon() { return null;