1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
package org.argouml.model.euml; |
14 | |
|
15 | |
import java.util.Collection; |
16 | |
import java.util.HashSet; |
17 | |
|
18 | |
import org.argouml.model.UseCasesHelper; |
19 | |
import org.eclipse.emf.edit.command.CommandParameter; |
20 | |
import org.eclipse.uml2.uml.Actor; |
21 | |
import org.eclipse.uml2.uml.Extend; |
22 | |
import org.eclipse.uml2.uml.ExtensionPoint; |
23 | |
import org.eclipse.uml2.uml.Include; |
24 | |
import org.eclipse.uml2.uml.UseCase; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | 0 | class UseCasesHelperEUMLImpl implements UseCasesHelper { |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
private EUMLModelImplementation modelImpl; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | 0 | public UseCasesHelperEUMLImpl(EUMLModelImplementation implementation) { |
43 | 0 | modelImpl = implementation; |
44 | 0 | } |
45 | |
|
46 | |
public void addExtend(final Object handle, final Object extend) { |
47 | 0 | if (!(handle instanceof UseCase) && !(handle instanceof ExtensionPoint)) { |
48 | 0 | throw new IllegalArgumentException(); |
49 | |
} |
50 | 0 | if (!(extend instanceof Extend)) { |
51 | 0 | throw new IllegalArgumentException(); |
52 | |
} |
53 | 0 | RunnableClass run = new RunnableClass() { |
54 | |
public void run() { |
55 | 0 | if (handle instanceof UseCase) { |
56 | 0 | ((UseCase) handle).getExtends().add((Extend) extend); |
57 | 0 | } else if (handle instanceof ExtensionPoint) { |
58 | 0 | ((Extend) extend).getExtensionLocations().add( |
59 | |
(ExtensionPoint) handle); |
60 | |
} |
61 | 0 | } |
62 | |
}; |
63 | 0 | modelImpl.getEditingDomain().getCommandStack().execute( |
64 | |
new ChangeCommand( |
65 | |
modelImpl, run, "Add the extend # to the #", extend, |
66 | |
handle)); |
67 | 0 | } |
68 | |
|
69 | |
public void addExtensionPoint(final Object handle, |
70 | |
final Object extensionPoint) { |
71 | 0 | addExtensionPoint(handle, CommandParameter.NO_INDEX, extensionPoint); |
72 | 0 | } |
73 | |
|
74 | |
public void addExtensionPoint(final Object handle, final int position, |
75 | |
final Object extensionPoint) { |
76 | 0 | if (!(handle instanceof UseCase) && !(handle instanceof Extend)) { |
77 | 0 | throw new IllegalArgumentException(); |
78 | |
} |
79 | 0 | if (!(extensionPoint instanceof ExtensionPoint)) { |
80 | 0 | throw new IllegalArgumentException(); |
81 | |
} |
82 | 0 | RunnableClass run = new RunnableClass() { |
83 | |
public void run() { |
84 | 0 | if (handle instanceof UseCase) { |
85 | 0 | ((UseCase) handle).getExtensionPoints().add( |
86 | |
position, (ExtensionPoint) extensionPoint); |
87 | 0 | } else if (handle instanceof Extend) { |
88 | 0 | ((Extend) handle).getExtensionLocations().add( |
89 | |
position, (ExtensionPoint) extensionPoint); |
90 | |
} |
91 | 0 | } |
92 | |
}; |
93 | 0 | modelImpl.getEditingDomain().getCommandStack().execute( |
94 | |
new ChangeCommand( |
95 | |
modelImpl, run, "Add the extension point # to the #", |
96 | |
extensionPoint, handle)); |
97 | 0 | } |
98 | |
|
99 | |
public void addInclude(final Object usecase, final Object include) { |
100 | 0 | if (!(usecase instanceof UseCase)) { |
101 | 0 | throw new IllegalArgumentException(); |
102 | |
} |
103 | 0 | if (!(include instanceof Include)) { |
104 | 0 | throw new IllegalArgumentException(); |
105 | |
} |
106 | 0 | RunnableClass run = new RunnableClass() { |
107 | |
public void run() { |
108 | 0 | ((UseCase) usecase).getIncludes().add((Include) include); |
109 | 0 | } |
110 | |
}; |
111 | 0 | modelImpl.getEditingDomain().getCommandStack().execute( |
112 | |
new ChangeCommand( |
113 | |
modelImpl, run, "Add the include # to the case #", |
114 | |
include, usecase)); |
115 | 0 | } |
116 | |
|
117 | |
public Collection getAllActors(Object ns) { |
118 | 0 | return modelImpl.getModelManagementHelper().getAllModelElementsOfKind( |
119 | |
ns, Actor.class); |
120 | |
} |
121 | |
|
122 | |
public Collection getAllUseCases(Object ns) { |
123 | 0 | return modelImpl.getModelManagementHelper().getAllModelElementsOfKind( |
124 | |
ns, UseCase.class); |
125 | |
} |
126 | |
|
127 | |
public Collection getExtendedUseCases(Object ausecase) { |
128 | 0 | if (!(ausecase instanceof UseCase)) { |
129 | 0 | throw new IllegalArgumentException(); |
130 | |
} |
131 | 0 | Collection<UseCase> result = new HashSet<UseCase>(); |
132 | 0 | for (Extend extend : ((UseCase) ausecase).getExtends()) { |
133 | 0 | result.add(extend.getExtension()); |
134 | |
} |
135 | 0 | return result; |
136 | |
} |
137 | |
|
138 | |
public Extend getExtends(Object abase, Object anextension) { |
139 | 0 | if (!(abase instanceof UseCase) || !(anextension instanceof UseCase)) { |
140 | 0 | throw new IllegalArgumentException(); |
141 | |
} |
142 | 0 | return ((UseCase) anextension).getExtend(null, (UseCase) abase); |
143 | |
} |
144 | |
|
145 | |
public Collection<UseCase> getIncludedUseCases(Object ausecase) { |
146 | 0 | if (!(ausecase instanceof UseCase)) { |
147 | 0 | throw new IllegalArgumentException(); |
148 | |
} |
149 | 0 | Collection<UseCase> result = new HashSet<UseCase>(); |
150 | 0 | for (Include include : ((UseCase) ausecase).getIncludes() ) { |
151 | 0 | result.add(include.getAddition()); |
152 | |
} |
153 | 0 | return result; |
154 | |
} |
155 | |
|
156 | |
public Include getIncludes(Object abase, Object aninclusion) { |
157 | 0 | if (!(abase instanceof UseCase) || !(aninclusion instanceof UseCase)) { |
158 | 0 | throw new IllegalArgumentException(); |
159 | |
} |
160 | 0 | return ((UseCase) abase).getInclude(null, (UseCase) aninclusion); |
161 | |
} |
162 | |
|
163 | |
public Collection getSpecificationPath(Object ausecase) { |
164 | |
|
165 | 0 | return null; |
166 | |
} |
167 | |
|
168 | |
public void removeExtend(Object elem, Object extend) { |
169 | |
|
170 | 0 | } |
171 | |
|
172 | |
public void removeExtensionPoint(Object elem, Object ep) { |
173 | |
|
174 | 0 | } |
175 | |
|
176 | |
public void removeInclude(final Object usecase, final Object include) { |
177 | 0 | if (!(usecase instanceof UseCase)) { |
178 | 0 | throw new IllegalArgumentException(); |
179 | |
} |
180 | 0 | if (!(include instanceof Include)) { |
181 | 0 | throw new IllegalArgumentException(); |
182 | |
} |
183 | 0 | RunnableClass run = new RunnableClass() { |
184 | |
public void run() { |
185 | 0 | ((UseCase) usecase).getIncludes().remove((Include) include); |
186 | 0 | } |
187 | |
}; |
188 | 0 | modelImpl.getEditingDomain().getCommandStack().execute( |
189 | |
new ChangeCommand( |
190 | |
modelImpl, run, "Remove the include # from the case #", |
191 | |
include, usecase)); |
192 | 0 | } |
193 | |
|
194 | |
public void setAddition(final Object handle, final Object useCase) { |
195 | 0 | if (!(handle instanceof Include)) { |
196 | 0 | throw new IllegalArgumentException(); |
197 | |
} |
198 | 0 | if (!(useCase instanceof UseCase)) { |
199 | 0 | throw new IllegalArgumentException(); |
200 | |
} |
201 | 0 | RunnableClass run = new RunnableClass() { |
202 | |
public void run() { |
203 | 0 | ((Include) handle).setAddition((UseCase) useCase); |
204 | 0 | } |
205 | |
}; |
206 | 0 | modelImpl.getEditingDomain().getCommandStack().execute( |
207 | |
new ChangeCommand( |
208 | |
modelImpl, run, "Set the addition # to the include #", |
209 | |
useCase, handle)); |
210 | 0 | } |
211 | |
|
212 | |
public void setBase(Object extend, Object base) { |
213 | |
|
214 | 0 | } |
215 | |
|
216 | |
public void setCondition(Object handle, Object booleanExpression) { |
217 | |
|
218 | 0 | } |
219 | |
|
220 | |
public void setExtension(Object handle, Object ext) { |
221 | 0 | } |
222 | |
|
223 | |
public void setExtensionPoints(final Object handle, |
224 | |
final Collection extensionPoints) { |
225 | 0 | if (!(handle instanceof UseCase) && !(handle instanceof Extend)) { |
226 | 0 | throw new IllegalArgumentException(); |
227 | |
} |
228 | 0 | if (extensionPoints == null) { |
229 | 0 | throw new IllegalArgumentException(); |
230 | |
} |
231 | 0 | for (Object o : extensionPoints) { |
232 | 0 | if (!(o instanceof ExtensionPoint)) { |
233 | 0 | throw new IllegalArgumentException(o.toString()); |
234 | |
} |
235 | |
} |
236 | 0 | RunnableClass run = new RunnableClass() { |
237 | |
public void run() { |
238 | 0 | if (handle instanceof Extend) { |
239 | 0 | ((Extend) handle).getExtensionLocations().clear(); |
240 | 0 | for (Object o : extensionPoints) { |
241 | 0 | ((Extend) handle).getExtensionLocations().add( |
242 | |
(ExtensionPoint) o); |
243 | |
} |
244 | 0 | } else if (handle instanceof UseCase) { |
245 | 0 | ((UseCase) handle).getExtensionPoints().clear(); |
246 | 0 | for (Object o : extensionPoints) { |
247 | 0 | ((UseCase) handle).getExtensionPoints().add( |
248 | |
(ExtensionPoint) o); |
249 | |
} |
250 | |
} |
251 | |
|
252 | 0 | } |
253 | |
}; |
254 | 0 | modelImpl.getEditingDomain().getCommandStack().execute( |
255 | |
new ChangeCommand( |
256 | |
modelImpl, run, |
257 | |
"Set # extension points for the case #", |
258 | |
extensionPoints.size(), handle)); |
259 | 0 | } |
260 | |
|
261 | |
public void setIncludes(Object handle, Collection includes) { |
262 | |
|
263 | 0 | } |
264 | |
|
265 | |
public void setLocation(Object handle, String loc) { |
266 | |
|
267 | 0 | } |
268 | |
|
269 | |
public void setUseCase(Object elem, Object usecase) { |
270 | |
|
271 | 0 | } |
272 | |
|
273 | |
} |