1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 /***
19 * <p>Title: WSMO Studio</p>
20 * <p>Description: Semantic Web Service Editor</p>
21 * <p>Copyright: Copyright (c) 2004-2007</p>
22 * <p>Company: Ontotext Lab. / SIRMA </p>
23 */
24
25 package org.wsmostudio.bpmo.ui.editor;
26
27 import java.util.*;
28
29 import org.eclipse.jface.action.IAction;
30 import org.eclipse.jface.action.IMenuManager;
31 import org.eclipse.ui.actions.ActionFactory;
32
33 import org.eclipse.gef.*;
34 import org.eclipse.gef.ui.actions.ActionRegistry;
35 import org.eclipse.gef.ui.actions.GEFActionConstants;
36 import org.wsmostudio.bpmo.model.WorkflowEntityNode;
37 import org.wsmostudio.bpmo.ui.actions.*;
38
39
40 class BpmoEditorContextMenuProvider extends ContextMenuProvider {
41
42 /*** The editor's action registry. */
43 private ActionRegistry actionRegistry;
44
45 /***
46 * Instantiate a new menu context provider for the specified EditPartViewer
47 * and ActionRegistry.
48 * @param viewer the editor's graphical viewer
49 * @param registry the editor's action registry
50 * @throws IllegalArgumentException if registry is <tt>null</tt>.
51 */
52 public BpmoEditorContextMenuProvider(EditPartViewer viewer, ActionRegistry registry) {
53 super(viewer);
54 if (registry == null) {
55 throw new IllegalArgumentException();
56 }
57 actionRegistry = registry;
58 }
59
60 /***
61 * Called when the context menu is about to show. Actions,
62 * whose state is enabled, will appear in the context menu.
63 * @see org.eclipse.gef.ContextMenuProvider#buildContextMenu(org.eclipse.jface.action.IMenuManager)
64 */
65 public void buildContextMenu(IMenuManager menu) {
66
67 GEFActionConstants.addStandardActionGroups(menu);
68
69 menu.appendToGroup(
70 GEFActionConstants.GROUP_UNDO,
71 getAction(ActionFactory.UNDO.getId()));
72 menu.appendToGroup(
73 GEFActionConstants.GROUP_UNDO,
74 getAction(ActionFactory.REDO.getId()));
75 menu.appendToGroup(
76 GEFActionConstants.GROUP_EDIT,
77 getAction(ActionFactory.DELETE.getId()));
78
79 IAction action = getAction(GEFActionConstants.DIRECT_EDIT);
80 if (action != null
81 && action.isEnabled())
82 menu.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
83
84 menu.appendToGroup(
85 GEFActionConstants.GROUP_COPY,
86 getAction(ActionFactory.COPY.getId()));
87 menu.appendToGroup(
88 GEFActionConstants.GROUP_COPY,
89 getAction(ActionFactory.PASTE.getId()));
90
91
92 action = getAction(ExportImageAction.ID);
93 if (action != null
94 && action.isEnabled()) {
95 menu.appendToGroup(GEFActionConstants.MB_ADDITIONS, action);
96 }
97 action = getAction(LayoutAction.ID);
98 if (action != null
99 && action.isEnabled()) {
100 menu.appendToGroup(GEFActionConstants.MB_ADDITIONS, action);
101 }
102
103 List<?> sel = getViewer().getSelectedEditParts();
104 Set<WorkflowEntityNode> uiModels = new HashSet<WorkflowEntityNode>();
105 for(Object uiPart : sel) {
106 uiModels.add((WorkflowEntityNode)((EditPart)uiPart).getModel());
107 }
108 Set<WorkflowEntityNode> rootUIModels = new HashSet<WorkflowEntityNode>(uiModels);
109 for(Iterator<WorkflowEntityNode> iter = rootUIModels.iterator(); iter.hasNext();) {
110 if (uiModels.contains(iter.next().getOwner())) {
111 iter.remove();
112 }
113 }
114 for (Iterator<?> it = this.actionRegistry.getActions(); it.hasNext();) {
115 IAction customAction = (IAction)it.next();
116 if (false == customAction instanceof AbstractDiagramAction) {
117 continue;
118 }
119 if (((AbstractDiagramAction)customAction).isApplicableTo(rootUIModels)) {
120 menu.appendToGroup(GEFActionConstants.MB_ADDITIONS, customAction);
121 }
122
123 }
124 }
125
126 private IAction getAction(String actionId) {
127 return actionRegistry.getAction(actionId);
128 }
129
130 }