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.model.mdr; |
40 | |
|
41 | |
import java.util.ArrayList; |
42 | |
import java.util.Arrays; |
43 | |
import java.util.Collection; |
44 | |
import java.util.Iterator; |
45 | |
import java.util.List; |
46 | |
|
47 | |
import org.argouml.model.Model; |
48 | |
import org.argouml.model.UmlHelper; |
49 | |
import org.omg.uml.behavioralelements.collaborations.Message; |
50 | |
import org.omg.uml.behavioralelements.commonbehavior.Action; |
51 | |
import org.omg.uml.behavioralelements.commonbehavior.ActionSequence; |
52 | |
import org.omg.uml.behavioralelements.commonbehavior.Argument; |
53 | |
import org.omg.uml.behavioralelements.commonbehavior.Link; |
54 | |
import org.omg.uml.behavioralelements.commonbehavior.LinkEnd; |
55 | |
import org.omg.uml.behavioralelements.statemachines.Event; |
56 | |
import org.omg.uml.behavioralelements.statemachines.Transition; |
57 | |
import org.omg.uml.behavioralelements.usecases.Extend; |
58 | |
import org.omg.uml.behavioralelements.usecases.ExtensionPoint; |
59 | |
import org.omg.uml.behavioralelements.usecases.UseCase; |
60 | |
import org.omg.uml.foundation.core.AssociationEnd; |
61 | |
import org.omg.uml.foundation.core.Attribute; |
62 | |
import org.omg.uml.foundation.core.BehavioralFeature; |
63 | |
import org.omg.uml.foundation.core.Classifier; |
64 | |
import org.omg.uml.foundation.core.Enumeration; |
65 | |
import org.omg.uml.foundation.core.EnumerationLiteral; |
66 | |
import org.omg.uml.foundation.core.Feature; |
67 | |
import org.omg.uml.foundation.core.Operation; |
68 | |
import org.omg.uml.foundation.core.Parameter; |
69 | |
import org.omg.uml.foundation.core.Relationship; |
70 | |
import org.omg.uml.foundation.core.UmlAssociation; |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
class UmlHelperMDRImpl implements UmlHelper { |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
private MDRModelImplementation modelImpl; |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | 900 | UmlHelperMDRImpl(MDRModelImplementation implementation) { |
92 | 900 | modelImpl = implementation; |
93 | 900 | } |
94 | |
|
95 | |
public void addListenersToModel(Object model) { |
96 | |
|
97 | 0 | } |
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
public void deleteCollection(Collection col) { |
103 | 8 | Iterator it = col.iterator(); |
104 | 8 | while (it.hasNext()) { |
105 | 0 | modelImpl.getUmlFactory().delete(it.next()); |
106 | |
} |
107 | 8 | } |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
public Object getSource(Object relationship) { |
113 | 0 | if (relationship instanceof Message) { |
114 | 0 | Message message = (Message) relationship; |
115 | 0 | return message.getSender(); |
116 | |
} |
117 | 0 | if (relationship instanceof Relationship) { |
118 | |
|
119 | |
|
120 | 0 | return modelImpl.getCoreHelper().getSource(relationship); |
121 | |
} |
122 | 0 | if (relationship instanceof Transition) { |
123 | 0 | return modelImpl.getStateMachinesHelper().getSource(relationship); |
124 | |
} |
125 | 0 | if (relationship instanceof AssociationEnd) { |
126 | 0 | return modelImpl.getCoreHelper().getSource(relationship); |
127 | |
} |
128 | 0 | throw new IllegalArgumentException(); |
129 | |
} |
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
public Object getDestination(Object relationship) { |
135 | 0 | if (relationship instanceof Message) { |
136 | 0 | Message message = (Message) relationship; |
137 | 0 | return message.getSender(); |
138 | |
} |
139 | 0 | if (relationship instanceof Relationship) { |
140 | |
|
141 | |
|
142 | 0 | return modelImpl.getCoreHelper().getDestination(relationship); |
143 | |
} |
144 | 0 | if (relationship instanceof Transition) { |
145 | 0 | return modelImpl.getStateMachinesHelper(). |
146 | |
getDestination(relationship); |
147 | |
} |
148 | 0 | if (relationship instanceof AssociationEnd) { |
149 | 0 | return modelImpl.getCoreHelper().getDestination(relationship); |
150 | |
} |
151 | 0 | throw new IllegalArgumentException(); |
152 | |
} |
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
public void move(Object parent, Object element, Direction direction) { |
159 | 0 | if (element instanceof Argument) { |
160 | 0 | final Argument arg = (Argument) element; |
161 | 0 | final Action action = arg.getAction(); |
162 | 0 | final List<Argument> f = action.getActualArgument(); |
163 | 0 | final int oldIndex = f.indexOf(arg); |
164 | 0 | final int newIndex = newPosition(oldIndex, f.size(), direction); |
165 | 0 | f.remove(arg); |
166 | 0 | f.add(newIndex, arg); |
167 | 0 | } else if (element instanceof Action) { |
168 | 0 | final Action act = (Action) element; |
169 | 0 | final ActionSequence actionSequence = act.getActionSequence(); |
170 | 0 | final List<Action> f = actionSequence.getAction(); |
171 | 0 | final int oldIndex = f.indexOf(act); |
172 | 0 | final int newIndex = newPosition(oldIndex, f.size(), direction); |
173 | 0 | f.remove(actionSequence); |
174 | 0 | f.add(newIndex, actionSequence); |
175 | 0 | } else if (element instanceof AssociationEnd) { |
176 | 0 | final AssociationEnd assEnd = (AssociationEnd) element; |
177 | 0 | final UmlAssociation assoc = assEnd.getAssociation(); |
178 | 0 | final List<AssociationEnd> f = assoc.getConnection(); |
179 | 0 | final int oldIndex = f.indexOf(assEnd); |
180 | 0 | final int newIndex = newPosition(oldIndex, f.size(), direction); |
181 | 0 | f.remove(assEnd); |
182 | 0 | f.add(newIndex, assEnd); |
183 | 0 | } else if (element instanceof Attribute && parent instanceof AssociationEnd) { |
184 | 0 | final Attribute attr = (Attribute) element; |
185 | 0 | final AssociationEnd assocEnd = attr.getAssociationEnd(); |
186 | 0 | final List<Attribute> f = assocEnd.getQualifier(); |
187 | 0 | final int oldIndex = f.indexOf(assocEnd); |
188 | 0 | final int newIndex = newPosition(oldIndex, f.size(), direction); |
189 | 0 | f.remove(attr); |
190 | 0 | f.add(newIndex, attr); |
191 | 0 | } else if (element instanceof Feature) { |
192 | 0 | final Feature att = (Feature) element; |
193 | 0 | final Classifier cls = att.getOwner(); |
194 | 0 | final List f = Model.getFacade().getFeatures(cls); |
195 | 0 | final int oldIndex = f.indexOf(att); |
196 | 0 | final int newIndex = newPosition(oldIndex, f.size(), direction); |
197 | 0 | Model.getCoreHelper().removeFeature(cls, att); |
198 | 0 | Model.getCoreHelper().addFeature(cls, newIndex, att); |
199 | 0 | } else if (element instanceof Parameter && parent instanceof Event) { |
200 | 0 | final Parameter param = (Parameter) element; |
201 | 0 | final Event event = (Event) parent; |
202 | 0 | final List<Parameter> f = event.getParameter(); |
203 | 0 | final int oldIndex = f.indexOf(param); |
204 | 0 | final int newIndex = newPosition(oldIndex, f.size(), direction); |
205 | 0 | f.remove(param); |
206 | 0 | f.add(newIndex, param); |
207 | 0 | } else if (element instanceof Parameter) { |
208 | 0 | final Parameter param = (Parameter) element; |
209 | 0 | final BehavioralFeature bf = param.getBehavioralFeature(); |
210 | 0 | final List<Parameter> f = bf.getParameter(); |
211 | 0 | final int oldIndex = f.indexOf(param); |
212 | 0 | final int newIndex = newPosition(oldIndex, f.size(), direction); |
213 | 0 | f.remove(param); |
214 | 0 | f.add(newIndex, param); |
215 | 0 | } else if (element instanceof EnumerationLiteral) { |
216 | 0 | final EnumerationLiteral lit = (EnumerationLiteral) element; |
217 | 0 | final Enumeration enumeration = lit.getEnumeration(); |
218 | 0 | final List<EnumerationLiteral> f = enumeration.getLiteral(); |
219 | 0 | final int oldIndex = f.indexOf(lit); |
220 | 0 | final int newIndex = newPosition(oldIndex, f.size(), direction); |
221 | 0 | f.remove(lit); |
222 | 0 | f.add(newIndex, lit); |
223 | 0 | } else if (element instanceof ExtensionPoint && parent instanceof Extend) { |
224 | 0 | final ExtensionPoint ep = (ExtensionPoint) element; |
225 | 0 | final Extend extend = (Extend) parent; |
226 | 0 | final List<ExtensionPoint> f = extend.getExtensionPoint(); |
227 | 0 | final int oldIndex = f.indexOf(ep); |
228 | 0 | final int newIndex = newPosition(oldIndex, f.size(), direction); |
229 | 0 | f.remove(ep); |
230 | 0 | f.add(newIndex, ep); |
231 | 0 | } else if (element instanceof LinkEnd) { |
232 | 0 | final LinkEnd le = (LinkEnd) element; |
233 | 0 | final Link link = le.getLink(); |
234 | 0 | final List f = new ArrayList(Model.getFacade().getConnections(link)); |
235 | 0 | final int oldIndex = f.indexOf(le); |
236 | 0 | final int newIndex = newPosition(oldIndex, f.size(), direction); |
237 | 0 | f.remove(le); |
238 | 0 | f.add(newIndex, le); |
239 | 0 | Model.getCoreHelper().setConnections(link, f); |
240 | 0 | } else if (element instanceof ExtensionPoint && parent instanceof UseCase) { |
241 | 0 | final ExtensionPoint ep = (ExtensionPoint) element; |
242 | 0 | final UseCase extend = ep.getUseCase(); |
243 | 0 | final List f = new ArrayList(Model.getFacade().getExtensionPoints(extend)); |
244 | 0 | final int oldIndex = f.indexOf(ep); |
245 | 0 | final int newIndex = newPosition(oldIndex, f.size(), direction); |
246 | 0 | f.remove(ep); |
247 | 0 | f.add(newIndex, ep); |
248 | 0 | Model.getUseCasesHelper().setExtensionPoints(ep, f); |
249 | |
} |
250 | 0 | } |
251 | |
|
252 | |
|
253 | |
|
254 | |
|
255 | |
public boolean isMovable(Object metaType) { |
256 | 0 | final Class<?>[] movableMetaType = new Class<?> [] { |
257 | |
Action.class, |
258 | |
Argument.class, |
259 | |
AssociationEnd.class, |
260 | |
Attribute.class, |
261 | |
EnumerationLiteral.class, |
262 | |
Extend.class, |
263 | |
ExtensionPoint.class, |
264 | |
Feature.class, |
265 | |
LinkEnd.class, |
266 | |
Operation.class, |
267 | |
Parameter.class}; |
268 | 0 | return Arrays.asList(movableMetaType).contains(metaType); |
269 | |
} |
270 | |
|
271 | |
|
272 | |
private int newPosition(int index, int size, Direction direction) { |
273 | |
final int posn; |
274 | 0 | if (direction == Direction.DOWN) { |
275 | 0 | posn = index + 1; |
276 | 0 | } else if (direction == Direction.UP) { |
277 | 0 | posn = index - 1; |
278 | 0 | } else if (direction == Direction.TOP) { |
279 | 0 | posn = 0; |
280 | 0 | } else if (direction == Direction.BOTTOM) { |
281 | 0 | posn = size - 1; |
282 | |
} else { |
283 | 0 | posn = 0; |
284 | |
} |
285 | 0 | return posn; |
286 | |
} |
287 | |
} |