001: package org.openwfe.gpe;
002:
003: import org.eclipse.jface.action.IAction;
004: import org.eclipse.jface.action.IMenuManager;
005: import org.eclipse.jface.action.MenuManager;
006: import org.eclipse.jface.action.Separator;
007: import org.eclipse.ui.IWorkbenchActionConstants;
008:
009: import org.eclipse.gef.EditPartViewer;
010: import org.eclipse.gef.ui.actions.ActionRegistry;
011: import org.eclipse.gef.ui.actions.GEFActionConstants;
012:
013: public class FlowContextMenuProvider extends
014: org.eclipse.gef.ContextMenuProvider {
015:
016: private ActionRegistry actionRegistry;
017:
018: public FlowContextMenuProvider(EditPartViewer viewer,
019: ActionRegistry registry) {
020: super (viewer);
021: setActionRegistry(registry);
022: }
023:
024: /* (non-Javadoc)
025: * @see org.eclipse.gef.ContextMenuProvider#menuAboutToShow(org.eclipse.jface.action.IMenuManager)
026: */
027: public void buildContextMenu(IMenuManager manager) {
028: GEFActionConstants.addStandardActionGroups(manager);
029:
030: IAction action;
031:
032: action = getActionRegistry().getAction(GEFActionConstants.UNDO);
033: manager.appendToGroup(GEFActionConstants.GROUP_UNDO, action);
034:
035: action = getActionRegistry().getAction(GEFActionConstants.REDO);
036: manager.appendToGroup(GEFActionConstants.GROUP_UNDO, action);
037:
038: action = getActionRegistry().getAction(
039: IWorkbenchActionConstants.PASTE);
040: if (action.isEnabled())
041: manager
042: .appendToGroup(GEFActionConstants.GROUP_EDIT,
043: action);
044:
045: action = getActionRegistry().getAction(
046: IWorkbenchActionConstants.DELETE);
047: if (action.isEnabled())
048: manager
049: .appendToGroup(GEFActionConstants.GROUP_EDIT,
050: action);
051:
052: action = getActionRegistry().getAction(
053: GEFActionConstants.DIRECT_EDIT);
054: if (action.isEnabled())
055: manager
056: .appendToGroup(GEFActionConstants.GROUP_EDIT,
057: action);
058:
059: // Alignment Actions
060: MenuManager submenu = new MenuManager("Menu");
061:
062: action = getActionRegistry().getAction(
063: GEFActionConstants.ALIGN_LEFT);
064: if (action.isEnabled())
065: submenu.add(action);
066:
067: action = getActionRegistry().getAction(
068: GEFActionConstants.ALIGN_CENTER);
069: if (action.isEnabled())
070: submenu.add(action);
071:
072: action = getActionRegistry().getAction(
073: GEFActionConstants.ALIGN_RIGHT);
074: if (action.isEnabled())
075: submenu.add(action);
076:
077: submenu.add(new Separator());
078:
079: action = getActionRegistry().getAction(
080: GEFActionConstants.ALIGN_TOP);
081: if (action.isEnabled())
082: submenu.add(action);
083:
084: action = getActionRegistry().getAction(
085: GEFActionConstants.ALIGN_MIDDLE);
086: if (action.isEnabled())
087: submenu.add(action);
088:
089: action = getActionRegistry().getAction(
090: GEFActionConstants.ALIGN_BOTTOM);
091: if (action.isEnabled())
092: submenu.add(action);
093:
094: if (!submenu.isEmpty())
095: manager.appendToGroup(GEFActionConstants.GROUP_REST,
096: submenu);
097:
098: action = getActionRegistry().getAction(
099: IWorkbenchActionConstants.SAVE);
100: manager.appendToGroup(GEFActionConstants.GROUP_SAVE, action);
101:
102: }
103:
104: private ActionRegistry getActionRegistry() {
105: return actionRegistry;
106: }
107:
108: private void setActionRegistry(ActionRegistry registry) {
109: actionRegistry = registry;
110: }
111:
112: }
|