1 | /** | | 1 | /** |
2 | * @param me the MouseEvent that triggered the popup menu request | | 2 | * This method returns a Vector of one of these 4 types: |
3 | * @return a Vector containing a combination of these 4 types: Action, | | 3 | * AbstractAction, JMenu, JMenuItem, JSeparator. |
4 | * JMenu, JMenuItem, JSeparator. | | 4 | * {@inheritDoc} |
5 | */ | | 5 | */ |
6 | @Override | | 6 | @Override |
7 | public Vector getPopUpActions(MouseEvent me) { | | 7 | public Vector getPopUpActions(MouseEvent me) { |
8 | ActionList popUpActions = | | 8 | ActionList popUpActions = |
9 | new ActionList(super.getPopUpActions(me), isReadOnly()); | | 9 | new ActionList(super.getPopUpActions(me), isReadOnly()); |
10 | | | 10 | |
11 | // Added this part to load the extra menu content | | 11 | final List<Action> modulesActions = |
12 | final List<Action> modulesActions = | | 12 | ContextActionFactoryManager.getContextPopupActions(); |
13 | ContextActionFactoryManager.getContextPopupActions(); | | 13 | |
14 | | | 14 | for (Action a : modulesActions) { |
15 | for (Action a : modulesActions) { | | 15 | if (a instanceof List) { |
16 | if (a instanceof List) { | | 16 | JMenu m = new JMenu(a); |
17 | JMenu m = new JMenu((Action) a); | | 17 | popUpActions.add(m); |
18 | popUpActions.add(m); | | 18 | for (Action subAction : (List<Action>) a) { |
19 | for (Action subAction : (List<Action>) a) { | | 19 | m.add(subAction); |
20 | m.add(subAction); | | 20 | } |
21 | } | | 21 | } else { |
22 | } else { | | 22 | popUpActions.add(a); |
23 | popUpActions.add(a); | | 23 | } |
24 | } | | 24 | } |
25 | } | | 25 | |
26 | | | 26 | // Show ... |
27 | // popupAddOffset should be equal to the number of items added here: | | 27 | ArgoJMenu show = buildShowPopUp(); |
28 | popUpActions.add(new JSeparator()); | | 28 | if (show.getMenuComponentCount() > 0) { |
29 | popupAddOffset = 1; | | 29 | popUpActions.add(show); |
30 | if (removeFromDiagram) { | | 30 | } |
31 | popUpActions.add( | | 31 | |
32 | ProjectActions.getInstance().getRemoveFromDiagramAction()); | | 32 | // popupAddOffset should be equal to the number of items added here: |
33 | popupAddOffset++; | | 33 | popUpActions.add(new JSeparator()); |
34 | } | | 34 | popupAddOffset = 1; |
35 | popUpActions.add(new ActionDeleteModelElements()); | | 35 | if (removeFromDiagram) { |
36 | popupAddOffset++; | | 36 | popUpActions.add( |
37 | | | 37 | ProjectActions.getInstance().getRemoveFromDiagramAction()); |
38 | if (TargetManager.getInstance().getTargets().size() == 1) { | | 38 | popupAddOffset++; |
39 | ToDoList list = Designer.theDesigner().getToDoList(); | | 39 | } |
40 | List<ToDoItem> items = list.elementListForOffender(getOwner()); | | 40 | |
41 | if (items != null && items.size() > 0) { | | 41 | if (!isReadOnly()) { |
42 | // TODO: This creates a dependency on the Critics subsystem. | | 42 | popUpActions.add(new ActionDeleteModelElements()); |
43 | // We need a generic way for modules (including our internal | | 43 | popupAddOffset++; |
44 | // subsystems) to request addition of actions to the popup | | 44 | } |
45 | // menu. - tfm 20080430 | | 45 | |
46 | ArgoJMenu critiques = new ArgoJMenu("menu.popup.critiques"); | | 46 | /* Check if multiple items are selected: */ |
47 | ToDoItem itemUnderMouse = hitClarifier(me.getX(), me.getY()); | | 47 | if (TargetManager.getInstance().getTargets().size() == 1) { |
48 | if (itemUnderMouse != null) { | | 48 | |
49 | critiques.add(new ActionGoToCritique(itemUnderMouse)); | | 49 | // TODO: Having Critics actions here introduces an unnecessary |
50 | critiques.addSeparator(); | | 50 | // dependency on the Critics subsystem. Have it register its |
51 | } | | 51 | // desired actions using an extension mechanism - tfm |
52 | for (ToDoItem item : items) { | | 52 | ToDoList tdList = Designer.theDesigner().getToDoList(); |
53 | if (item == itemUnderMouse) { | | 53 | List<ToDoItem> items = tdList.elementListForOffender(getOwner()); |
54 | continue; | | 54 | if (items != null && items.size() > 0) { |
55 | } | | 55 | // TODO: This creates a dependency on the Critics subsystem. |
56 | critiques.add(new ActionGoToCritique(item)); | | 56 | // We need a generic way for modules (including our internal |
57 | } | | 57 | // subsystems) to request addition of actions to the popup |
58 | popUpActions.add(0, new JSeparator()); | | 58 | // menu. - tfm 20080430 |
59 | popUpActions.add(0, critiques); | | 59 | ArgoJMenu critiques = new ArgoJMenu("menu.popup.critiques"); |
60 | } | | 60 | ToDoItem itemUnderMouse = hitClarifier(me.getX(), me.getY()); |
61 | } | | 61 | if (itemUnderMouse != null) { |
62 | | | 62 | critiques.add(new ActionGoToCritique(itemUnderMouse)); |
63 | // Add stereotypes submenu | | 63 | critiques.addSeparator(); |
64 | Action[] stereoActions = getApplyStereotypeActions(); | | 64 | } |
65 | if (stereoActions != null && stereoActions.length > 0) { | | 65 | for (ToDoItem item : items) { |
66 | popUpActions.add(0, new JSeparator()); | | 66 | if (item != itemUnderMouse) { |
67 | ArgoJMenu stereotypes = new ArgoJMenu( | | 67 | critiques.add(new ActionGoToCritique(item)); |
68 | "menu.popup.apply-stereotypes"); | | 68 | } |
69 | for (int i = 0; i < stereoActions.length; ++i) { | | 69 | } |
70 | stereotypes.addCheckItem(stereoActions[i]); | | 70 | popUpActions.add(0, new JSeparator()); |
71 | } | | 71 | popUpActions.add(0, critiques); |
72 | popUpActions.add(0, stereotypes); | | 72 | } |
73 | } | | 73 | } |
74 | | | 74 | |
75 | return popUpActions; | | 75 | // Add stereotypes submenu |
76 | } | | 76 | Collection<Object> elements = new ArrayList<Object>(); |
| | | 77 | Object owner = getOwner(); |
| | | 78 | if (owner != null) { |
| | | 79 | elements.add(owner); |
| | | 80 | } |
| | | 81 | for (Object o : TargetManager.getInstance().getTargets()) { |
| | | 82 | Object element = null; |
| | | 83 | if (Model.getFacade().isAUMLElement(o)) { |
| | | 84 | element = o; |
| | | 85 | } else if (o instanceof Fig) { |
| | | 86 | element = ((Fig) o).getOwner(); |
| | | 87 | } |
| | | 88 | if (element != null && element != owner) { |
| | | 89 | elements.add(element); |
| | | 90 | } |
| | | 91 | } |
| | | 92 | final Action[] stereoActions = |
| | | 93 | StereotypeUtility.getApplyStereotypeActions(elements); |
| | | 94 | if (stereoActions != null) { |
| | | 95 | popUpActions.add(0, new JSeparator()); |
| | | 96 | final ArgoJMenu stereotypes = |
| | | 97 | new ArgoJMenu("menu.popup.apply-stereotypes"); |
| | | 98 | for (Action action : stereoActions) { |
| | | 99 | stereotypes.addCheckItem(action); |
| | | 100 | } |
| | | 101 | popUpActions.add(0, stereotypes); |
| | | 102 | } |
| | | 103 | |
| | | 104 | if (TargetManager.getInstance().getTargets().size() == 1) { |
| | | 105 | // add stereotype view submenu |
| | | 106 | ArgoJMenu stereotypesView = |
| | | 107 | new ArgoJMenu("menu.popup.stereotype-view"); |
| | | 108 | |
| | | 109 | // TODO: There are cyclic dependencies between ActionStereotypeView* |
| | | 110 | // and FigNodeModelElement. Register these actions opaquely since |
| | | 111 | // we don't what they are. - tfm |
| | | 112 | stereotypesView.addRadioItem(new ActionStereotypeViewTextual(this)); |
| | | 113 | stereotypesView.addRadioItem(new ActionStereotypeViewBigIcon(this)); |
| | | 114 | stereotypesView.addRadioItem( |
| | | 115 | new ActionStereotypeViewSmallIcon(this)); |
| | | 116 | |
| | | 117 | popUpActions.add(0, stereotypesView); |
| | | 118 | } |
| | | 119 | |
| | | 120 | return popUpActions; |
| | | 121 | } |