1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
package org.argouml.uml.diagram.static_structure.ui; |
40 | |
|
41 | |
import java.awt.event.MouseEvent; |
42 | |
|
43 | |
import javax.swing.Icon; |
44 | |
|
45 | |
import org.argouml.application.helpers.ResourceLoaderWrapper; |
46 | |
import org.argouml.model.Model; |
47 | |
import org.argouml.uml.StereotypeUtility; |
48 | |
import org.argouml.uml.diagram.deployment.DeploymentDiagramGraphModel; |
49 | |
import org.argouml.uml.diagram.ui.SelectionNodeClarifiers2; |
50 | |
import org.tigris.gef.base.Globals; |
51 | |
import org.tigris.gef.graph.MutableGraphModel; |
52 | |
import org.tigris.gef.presentation.Fig; |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
public class SelectionStereotype extends SelectionNodeClarifiers2 { |
63 | |
|
64 | 0 | private static Icon inheritIcon = |
65 | |
ResourceLoaderWrapper.lookupIconResource("Generalization"); |
66 | 0 | private static Icon dependIcon = |
67 | |
ResourceLoaderWrapper.lookupIconResource("Dependency"); |
68 | |
|
69 | |
private boolean useComposite; |
70 | |
|
71 | 0 | private static Icon icons[] = |
72 | |
{dependIcon, |
73 | |
inheritIcon, |
74 | |
null, |
75 | |
null, |
76 | |
null, |
77 | |
}; |
78 | |
|
79 | |
|
80 | 0 | private static String instructions[] = |
81 | |
{"Add a baseClass", |
82 | |
"Add a subStereotype", |
83 | |
null, |
84 | |
null, |
85 | |
null, |
86 | |
"Move object(s)", |
87 | |
}; |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
public SelectionStereotype(Fig f) { |
95 | 0 | super(f); |
96 | 0 | } |
97 | |
|
98 | |
@Override |
99 | |
public void mouseEntered(MouseEvent me) { |
100 | 0 | super.mouseEntered(me); |
101 | 0 | useComposite = me.isShiftDown(); |
102 | 0 | } |
103 | |
|
104 | |
@Override |
105 | |
protected Object getNewNode(int index) { |
106 | 0 | if (index == 0) { |
107 | 0 | index = getButton(); |
108 | |
} |
109 | 0 | Object ns = Model.getFacade().getNamespace(getContent().getOwner()); |
110 | 0 | switch (index) { |
111 | |
case 10: |
112 | 0 | Object clazz = Model.getCoreFactory().buildClass(ns); |
113 | 0 | StereotypeUtility.dealWithStereotypes(clazz, "metaclass", false); |
114 | 0 | return clazz; |
115 | |
case 11: |
116 | 0 | Object st = |
117 | |
Model.getExtensionMechanismsFactory().createStereotype(); |
118 | 0 | Model.getCoreHelper().setNamespace(st, ns); |
119 | 0 | return st; |
120 | |
} |
121 | 0 | return null; |
122 | |
} |
123 | |
|
124 | |
@Override |
125 | |
protected Object getNewNodeType(int index) { |
126 | 0 | switch (index) { |
127 | |
case 10: |
128 | 0 | return Model.getMetaTypes().getClass(); |
129 | |
case 11: |
130 | 0 | return Model.getMetaTypes().getStereotype(); |
131 | |
} |
132 | 0 | return null; |
133 | |
} |
134 | |
|
135 | |
@Override |
136 | |
protected Object createEdgeAbove(MutableGraphModel mgm, Object newNode) { |
137 | 0 | Object dep = super.createEdgeAbove(mgm, newNode); |
138 | 0 | StereotypeUtility.dealWithStereotypes(dep, "stereotype", false); |
139 | 0 | return dep; |
140 | |
} |
141 | |
|
142 | |
@Override |
143 | |
protected Icon[] getIcons() { |
144 | |
|
145 | 0 | if (Globals.curEditor().getGraphModel() |
146 | |
instanceof DeploymentDiagramGraphModel) { |
147 | 0 | return null; |
148 | |
} |
149 | 0 | if (Model.getModelManagementHelper().isReadOnly( |
150 | |
getContent().getOwner())) { |
151 | 0 | return new Icon[] {null, inheritIcon, null, null, null }; |
152 | |
} |
153 | 0 | return icons; |
154 | |
} |
155 | |
|
156 | |
@Override |
157 | |
protected String getInstructions(int index) { |
158 | 0 | return instructions[index - BASE]; |
159 | |
} |
160 | |
|
161 | |
@Override |
162 | |
protected Object getNewEdgeType(int index) { |
163 | 0 | if (index == TOP) { |
164 | 0 | return Model.getMetaTypes().getDependency(); |
165 | 0 | } else if (index == BOTTOM) { |
166 | 0 | return Model.getMetaTypes().getGeneralization(); |
167 | |
} |
168 | 0 | return null; |
169 | |
} |
170 | |
|
171 | |
@Override |
172 | |
protected boolean isReverseEdge(int index) { |
173 | 0 | if (index == BOTTOM) { |
174 | 0 | return true; |
175 | |
} |
176 | 0 | return false; |
177 | |
} |
178 | |
|
179 | |
@Override |
180 | |
protected boolean isEdgePostProcessRequested() { |
181 | 0 | return useComposite; |
182 | |
} |
183 | |
|
184 | |
} |