1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
package org.argouml.model.euml; |
13 | |
|
14 | |
import java.util.ArrayList; |
15 | |
import java.util.Arrays; |
16 | |
import java.util.Collection; |
17 | |
import java.util.Iterator; |
18 | |
import java.util.List; |
19 | |
|
20 | |
import org.argouml.model.Model; |
21 | |
import org.argouml.model.UmlHelper; |
22 | |
import org.eclipse.uml2.uml.Action; |
23 | |
import org.eclipse.uml2.uml.ActivityEdge; |
24 | |
import org.eclipse.uml2.uml.Behavior; |
25 | |
import org.eclipse.uml2.uml.Element; |
26 | |
import org.eclipse.uml2.uml.Enumeration; |
27 | |
import org.eclipse.uml2.uml.EnumerationLiteral; |
28 | |
import org.eclipse.uml2.uml.Extend; |
29 | |
import org.eclipse.uml2.uml.ExtensionPoint; |
30 | |
import org.eclipse.uml2.uml.Feature; |
31 | |
import org.eclipse.uml2.uml.Operation; |
32 | |
import org.eclipse.uml2.uml.Parameter; |
33 | |
import org.eclipse.uml2.uml.ParameterSet; |
34 | |
import org.eclipse.uml2.uml.Property; |
35 | |
import org.eclipse.uml2.uml.Relationship; |
36 | |
import org.eclipse.uml2.uml.Transition; |
37 | |
import org.eclipse.uml2.uml.UseCase; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
class UmlHelperEUMLImpl implements UmlHelper { |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
private EUMLModelImplementation modelImpl; |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | 0 | public UmlHelperEUMLImpl(EUMLModelImplementation implementation) { |
56 | 0 | modelImpl = implementation; |
57 | 0 | } |
58 | |
|
59 | |
public void addListenersToModel(Object model) { |
60 | |
|
61 | |
|
62 | 0 | } |
63 | |
|
64 | |
|
65 | |
public void deleteCollection(Collection col) { |
66 | 0 | Iterator it = col.iterator(); |
67 | 0 | while (it.hasNext()) { |
68 | 0 | modelImpl.getUmlFactory().delete(it.next()); |
69 | |
} |
70 | 0 | } |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
public Object getSource(Object relationship) { |
76 | 0 | if (relationship instanceof Relationship) { |
77 | |
|
78 | |
|
79 | 0 | return modelImpl.getCoreHelper().getSource(relationship); |
80 | 0 | } else if (relationship instanceof Transition) { |
81 | 0 | return modelImpl.getStateMachinesHelper().getSource(relationship); |
82 | 0 | } else if (relationship instanceof ActivityEdge) { |
83 | 0 | return ((ActivityEdge) relationship).getSource(); |
84 | 0 | } else if (relationship instanceof Property) { |
85 | |
|
86 | 0 | return modelImpl.getCoreHelper().getSource(relationship); |
87 | |
} |
88 | 0 | throw new IllegalArgumentException(); |
89 | |
} |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
public Object getDestination(Object relationship) { |
95 | 0 | if (relationship instanceof Relationship) { |
96 | |
|
97 | |
|
98 | 0 | return modelImpl.getCoreHelper().getDestination(relationship); |
99 | 0 | } else if (relationship instanceof ActivityEdge) { |
100 | 0 | return ((ActivityEdge) relationship).getTarget(); |
101 | 0 | } else if (relationship instanceof Transition) { |
102 | 0 | return modelImpl.getStateMachinesHelper(). |
103 | |
getDestination(relationship); |
104 | 0 | } else if (relationship instanceof Property) { |
105 | |
|
106 | 0 | return modelImpl.getCoreHelper().getDestination(relationship); |
107 | |
} |
108 | 0 | throw new IllegalArgumentException(); |
109 | |
} |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
public void move(Object parent, Object element, Direction direction) { |
115 | |
if (false) { |
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | 0 | } else if (element instanceof Feature) { |
150 | 0 | final Feature att = (Feature) element; |
151 | 0 | final Element cls = att.getOwner(); |
152 | 0 | final List f = Model.getFacade().getFeatures(cls); |
153 | 0 | final int oldIndex = f.indexOf(att); |
154 | 0 | final int newIndex = newPosition(oldIndex, f.size(), direction); |
155 | 0 | Model.getCoreHelper().removeFeature(cls, att); |
156 | 0 | Model.getCoreHelper().addFeature(cls, newIndex, att); |
157 | |
|
158 | 0 | } else if (element instanceof Parameter && parent instanceof Behavior) { |
159 | 0 | final Parameter param = (Parameter) element; |
160 | 0 | final Behavior behavior = (Behavior) parent; |
161 | 0 | final List<Parameter> f = behavior.getOwnedParameters(); |
162 | 0 | final int oldIndex = f.indexOf(param); |
163 | 0 | final int newIndex = newPosition(oldIndex, f.size(), direction); |
164 | 0 | f.remove(param); |
165 | 0 | f.add(newIndex, param); |
166 | 0 | } else if (element instanceof Parameter && parent instanceof ParameterSet) { |
167 | 0 | final Parameter param = (Parameter) element; |
168 | 0 | final ParameterSet set = (ParameterSet) parent; |
169 | 0 | final List<Parameter> f = set.getParameters(); |
170 | 0 | final int oldIndex = f.indexOf(param); |
171 | 0 | final int newIndex = newPosition(oldIndex, f.size(), direction); |
172 | 0 | f.remove(param); |
173 | 0 | f.add(newIndex, param); |
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | 0 | } else if (element instanceof Parameter) { |
184 | 0 | final Parameter param = (Parameter) element; |
185 | 0 | final Operation operation = param.getOperation(); |
186 | 0 | final List<Parameter> f = operation.getOwnedParameters(); |
187 | 0 | final int oldIndex = f.indexOf(param); |
188 | 0 | final int newIndex = newPosition(oldIndex, f.size(), direction); |
189 | 0 | f.remove(param); |
190 | 0 | f.add(newIndex, param); |
191 | 0 | } else if (element instanceof EnumerationLiteral) { |
192 | 0 | final EnumerationLiteral lit = (EnumerationLiteral) element; |
193 | 0 | final Enumeration enumeration = lit.getEnumeration(); |
194 | 0 | final List<EnumerationLiteral> f = enumeration.getOwnedLiterals(); |
195 | 0 | final int oldIndex = f.indexOf(lit); |
196 | 0 | final int newIndex = newPosition(oldIndex, f.size(), direction); |
197 | 0 | f.remove(lit); |
198 | 0 | f.add(newIndex, lit); |
199 | 0 | } else if (element instanceof ExtensionPoint && parent instanceof Extend) { |
200 | 0 | final ExtensionPoint ep = (ExtensionPoint) element; |
201 | 0 | final Extend extend = (Extend) parent; |
202 | 0 | final List<ExtensionPoint> f = extend.getExtensionLocations(); |
203 | 0 | final int oldIndex = f.indexOf(ep); |
204 | 0 | final int newIndex = newPosition(oldIndex, f.size(), direction); |
205 | 0 | f.remove(ep); |
206 | 0 | f.add(newIndex, ep); |
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | 0 | } else if (element instanceof ExtensionPoint && parent instanceof UseCase) { |
217 | 0 | final ExtensionPoint ep = (ExtensionPoint) element; |
218 | 0 | final UseCase extend = ep.getUseCase(); |
219 | 0 | final List f = new ArrayList(Model.getFacade().getExtensionPoints(extend)); |
220 | 0 | final int oldIndex = f.indexOf(ep); |
221 | 0 | final int newIndex = newPosition(oldIndex, f.size(), direction); |
222 | 0 | f.remove(ep); |
223 | 0 | f.add(newIndex, ep); |
224 | 0 | Model.getUseCasesHelper().setExtensionPoints(ep, f); |
225 | |
} |
226 | 0 | } |
227 | |
|
228 | |
private int newPosition(int index, int size, Direction direction) { |
229 | |
final int posn; |
230 | 0 | if (direction == Direction.DOWN) { |
231 | 0 | posn = index + 1; |
232 | 0 | } else if (direction == Direction.UP) { |
233 | 0 | posn = index - 1; |
234 | 0 | } else if (direction == Direction.TOP) { |
235 | 0 | posn = 0; |
236 | 0 | } else if (direction == Direction.BOTTOM) { |
237 | 0 | posn = size; |
238 | |
} else { |
239 | 0 | posn = 0; |
240 | |
} |
241 | 0 | return posn; |
242 | |
} |
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
public boolean isMovable(Object metaType) { |
248 | 0 | final Class<?>[] movableMetaType = { |
249 | |
Action.class, |
250 | |
EnumerationLiteral.class, |
251 | |
Extend.class, |
252 | |
ExtensionPoint.class, |
253 | |
Operation.class, |
254 | |
Parameter.class, |
255 | |
Property.class}; |
256 | 0 | return Arrays.asList(movableMetaType).contains(metaType); |
257 | |
} |
258 | |
|
259 | |
|
260 | |
} |