Skip to content
Snippets Groups Projects
Commit 33f98f9e authored by David Trachtenherz's avatar David Trachtenherz
Browse files

Added menu structuring

refs 451
parent 4fb00ea0
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
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