Commit | Line | Data |
---|---|---|
73005152 BH |
1 | package org.eclipse.linuxtools.tmf.ui.tests.uml2sd.load; |
2 | ||
3 | import java.net.URL; | |
4 | import java.util.ArrayList; | |
5 | import java.util.List; | |
6 | ||
7 | import org.eclipse.jface.action.Action; | |
8 | import org.eclipse.jface.resource.ImageDescriptor; | |
9 | import org.eclipse.jface.viewers.ISelection; | |
10 | import org.eclipse.jface.viewers.StructuredSelection; | |
6c13869b | 11 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; |
73005152 BH |
12 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView; |
13 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.AsyncMessageReturn; | |
14 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BasicExecutionOccurrence; | |
15 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.EllipsisisMessage; | |
16 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.ExecutionOccurrence; | |
17 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Frame; | |
18 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode; | |
19 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.HotSpot; | |
20 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline; | |
21 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.LifelineCategories; | |
22 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Stop; | |
23 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.SyncMessage; | |
24 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.SyncMessageReturn; | |
25 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IImage; | |
26 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFilterProvider; | |
27 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFindProvider; | |
28 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter; | |
29 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider; | |
30 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.widgets.Criteria; | |
31 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.widgets.FilterCriteria; | |
32 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader; | |
33 | import org.eclipse.swt.graphics.Image; | |
34 | import org.eclipse.ui.ISelectionListener; | |
35 | import org.eclipse.ui.IWorkbenchPart; | |
36 | import org.eclipse.ui.PlatformUI; | |
37 | ||
38 | // Referenced classes of package org.eclipse.hyades.uml2sd.ztest: | |
39 | // OpenToolBox | |
40 | ||
41 | public class TestLoaders implements IUml2SDLoader, ISDFindProvider, ISDFilterProvider, ISDPagingProvider, ISelectionListener { | |
42 | ||
43 | public SDView v; | |
44 | public int page; | |
45 | protected static URL BASIC_URL = null; | |
46 | ||
47 | private List<GraphNode> findResults = new ArrayList<GraphNode>(); | |
48 | private Criteria findCriteria; | |
49 | private int currentFindIndex = 0; | |
50 | ||
51 | private Frame savedFrame = null; | |
52 | ||
53 | static { | |
54 | try { | |
55 | BASIC_URL = new URL("platform", "localhost", "plugin"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ | |
56 | } catch (Exception E) { | |
57 | System.err.println(E); | |
58 | } | |
59 | } | |
60 | ||
61 | public TestLoaders() { | |
62 | this(""); //$NON-NLS-1$ | |
63 | } | |
64 | ||
65 | public TestLoaders(String name) { | |
66 | page = 1; | |
67 | } | |
68 | ||
69 | @Override | |
70 | public void setViewer(SDView j) { | |
71 | PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addPostSelectionListener(this); | |
72 | v = j; | |
73 | v.setSDPagingProvider(this); | |
74 | v.setSDFindProvider(this); | |
75 | v.setSDFilterProvider(this); | |
76 | page = 1; | |
77 | createFrame(); | |
78 | } | |
79 | ||
80 | @Override | |
81 | public boolean hasNextPage() { | |
82 | return page == 1; | |
83 | } | |
84 | ||
85 | @Override | |
86 | public boolean hasPrevPage() { | |
87 | return page == 2; | |
88 | } | |
89 | ||
90 | @Override | |
91 | public void prevPage() { | |
92 | page--; | |
93 | createFrame(); | |
94 | } | |
95 | ||
96 | @Override | |
97 | public void nextPage() { | |
98 | page++; | |
99 | createFrame(); | |
100 | } | |
101 | ||
102 | @SuppressWarnings("nls") | |
103 | private void createFrame() { | |
104 | Frame testFrame = new Frame(); | |
105 | if (page == 1) { | |
106 | testFrame.setName("Sequence Diagram - First Page"); | |
107 | LifelineCategories tt[] = new LifelineCategories[2]; | |
108 | tt[0] = new LifelineCategories(); | |
109 | tt[1] = new LifelineCategories(); | |
110 | tt[1].setName("Categorie 1"); | |
111 | tt[1].setImage(new LocalImageImpl("obj16/node_obj.gif")); | |
112 | tt[0].setImage(new LocalImageImpl("obj16/class.gif")); | |
113 | tt[0].setName("Categorie 0"); | |
114 | testFrame.setLifelineCategories(tt); | |
115 | Lifeline lifeline = new Lifeline(); | |
116 | lifeline.setName("LifeLine 0"); | |
117 | testFrame.addLifeLine(lifeline); | |
118 | EllipsisisMessage mn = new EllipsisisMessage(); | |
119 | lifeline.getNewEventOccurrence(); | |
120 | mn.setStartLifeline(lifeline); | |
121 | mn.setName("******************* EllipsisisMessage TEST ****************"); | |
122 | testFrame.addMessage(mn); | |
123 | SyncMessage mn3 = new SyncMessage(); | |
124 | mn3.setStartLifeline(lifeline); | |
125 | testFrame.addMessage(mn3); | |
126 | SyncMessage mn2 = new SyncMessage(); | |
127 | lifeline.getNewEventOccurrence(); | |
128 | lifeline.setCategory(0); | |
129 | mn2.setEndLifeline(lifeline); | |
130 | mn2.setName("*******************Sync TEST ****************"); | |
131 | testFrame.addMessage(mn2); | |
132 | for (int i = 1; i < 300; i++) { | |
133 | lifeline = new Lifeline(); | |
134 | lifeline.setName((new StringBuilder("LifeLine ")).append(i).toString()); | |
135 | lifeline.setCategory(1); | |
136 | testFrame.addLifeLine(lifeline); | |
137 | SyncMessage m3 = new SyncMessage(); | |
138 | testFrame.getLifeline(i - 1).getNewEventOccurrence(); | |
139 | m3.setStartLifeline(testFrame.getLifeline(i - 1)); | |
140 | m3.setEndLifeline(testFrame.getLifeline(i)); | |
141 | m3.setName((new StringBuilder("Sync Message ")).append(i).toString()); | |
142 | testFrame.addMessage(m3); | |
143 | // if (i == 11) | |
144 | // m3.setTime(new TmfTimestamp(i - 400)); | |
145 | // else if (i == 6) | |
146 | // m3.setTime(new TmfTimestamp(i)); | |
147 | // else | |
148 | m3.setTime(new TmfTimestamp(i + 1)); | |
149 | } | |
150 | ||
151 | for (int i = testFrame.lifeLinesCount() - 1; i > 0; i--) { | |
152 | SyncMessageReturn m = new SyncMessageReturn(); | |
153 | testFrame.getLifeline(i).getNewEventOccurrence(); | |
154 | m.setStartLifeline(testFrame.getLifeline(i)); | |
155 | m.setEndLifeline(testFrame.getLifeline(i - 1)); | |
156 | testFrame.addMessage(m); | |
157 | m.setName((new StringBuilder("Sync Message return ")).append(i).toString()); | |
158 | if (i + 1 < testFrame.lifeLinesCount()) { | |
159 | SyncMessage h = testFrame.getSyncMessage(i + 1); | |
160 | m.setMessage(h); | |
161 | } | |
162 | } | |
163 | ||
164 | for (int i = 0; i < testFrame.lifeLinesCount(); i++) | |
165 | if (i > 0) { | |
166 | ExecutionOccurrence occ = new ExecutionOccurrence(); | |
167 | occ.setStartOccurrence(testFrame.getSyncMessage(i).getEventOccurrence() + 1); | |
168 | occ.setEndOccurrence(testFrame.getSyncMessageReturn(testFrame.syncMessageReturnCount() - i).getEventOccurrence()); | |
169 | testFrame.getLifeline(i).addExecution(occ); | |
170 | occ.setName("******************* Execution Occurance TEST ****************"); | |
171 | } | |
172 | ||
173 | Stop s = new Stop(); | |
174 | s.setLifeline(testFrame.getLifeline(1)); | |
175 | s.setEventOccurrence(testFrame.getLifeline(1).getNewEventOccurrence()); | |
176 | testFrame.getLifeline(1).addNode(s); | |
177 | HotSpot gg = new HotSpot(); | |
178 | gg.setImage(new LocalImageImpl("obj16/plus_obj.gif")); | |
179 | gg.setExecution((BasicExecutionOccurrence) testFrame.getLifeline(1).getExecutions().get(0)); | |
180 | AsyncMessageReturn m = new AsyncMessageReturn(); | |
181 | m.setStartLifeline(testFrame.getLifeline(1)); | |
182 | m.setEndLifeline(testFrame.getLifeline(3)); | |
183 | m.setStartOccurrence(2); | |
184 | m.setEndOccurrence(6); | |
185 | m.setStartTime(new TmfTimestamp(2)); | |
186 | m.setEndTime(new TmfTimestamp(6)); | |
187 | m.setName("*******************Async TEST ****************"); | |
188 | testFrame.addMessage(m); | |
189 | v.setFrame(testFrame); | |
190 | v.getSDWidget().setReorderMode(true); | |
191 | } else { | |
192 | ||
193 | // if (page == 2) { | |
194 | testFrame.setName("Sequence Diagram"); | |
195 | Lifeline lifeline = new Lifeline(); | |
196 | lifeline.setName("LifeLine 0"); | |
197 | testFrame.addLifeLine(lifeline); | |
198 | lifeline = new Lifeline(); | |
199 | lifeline.setName("LifeLine 1"); | |
200 | testFrame.addLifeLine(lifeline); | |
201 | for (int i = 1; i < 30; i++) { | |
202 | SyncMessage m3 = new SyncMessage(); | |
203 | m3.autoSetStartLifeline(testFrame.getLifeline(0)); | |
204 | m3.autoSetEndLifeline(testFrame.getLifeline(0)); | |
205 | m3.setName((new StringBuilder("Message ")).append(i).toString()); | |
206 | testFrame.addMessage(m3); | |
207 | SyncMessageReturn m = new SyncMessageReturn(); | |
208 | m.autoSetStartLifeline(testFrame.getLifeline(0)); | |
209 | m.autoSetEndLifeline(testFrame.getLifeline(0)); | |
210 | testFrame.addMessage(m); | |
211 | m.setName((new StringBuilder("Message return ")).append(i).toString()); | |
212 | ExecutionOccurrence occ = new ExecutionOccurrence(); | |
213 | occ.setStartOccurrence(testFrame.getSyncMessage(i - 1).getEventOccurrence()); | |
214 | occ.setEndOccurrence(testFrame.getSyncMessageReturn(i - 1).getEventOccurrence()); | |
215 | testFrame.getLifeline(0).addExecution(occ); | |
216 | } | |
217 | } | |
218 | v.setFrame(testFrame); | |
219 | } | |
220 | ||
221 | /* | |
222 | * (non-Javadoc) | |
223 | * @see org.eclipse.hyades.uml2sd.ui.actions.provider.ISDFindProvider#find(org.eclipse.hyades.uml2sd.ui.actions.widgets.Criteria) | |
224 | */ | |
225 | @Override | |
226 | public boolean find(Criteria toSearch) { | |
227 | Frame frame = v.getFrame(); | |
228 | ||
229 | if (frame == null) | |
230 | return false; | |
231 | if (findResults == null || findCriteria == null || !findCriteria.compareTo(toSearch)) { | |
232 | findResults = new ArrayList<GraphNode>(); | |
233 | findCriteria = toSearch; | |
234 | if (findCriteria.isLifeLineSelected()) { | |
235 | for (int i = 0; i < frame.lifeLinesCount(); i++) { | |
236 | if (findCriteria.matches(frame.getLifeline(i).getName())) | |
237 | findResults.add(frame.getLifeline(i)); | |
238 | } | |
239 | ||
240 | } | |
241 | ArrayList<GraphNode> msgs = new ArrayList<GraphNode>(); | |
242 | if (findCriteria.isSyncMessageSelected()) { | |
243 | for (int i = 0; i < frame.syncMessageCount(); i++) { | |
244 | if (findCriteria.matches(frame.getSyncMessage(i).getName())) | |
245 | msgs.add(frame.getSyncMessage(i)); | |
246 | } | |
247 | ||
248 | for (int i = 0; i < frame.syncMessageReturnCount(); i++) | |
249 | if (findCriteria.matches(frame.getSyncMessageReturn(i).getName())) | |
250 | msgs.add(frame.getSyncMessageReturn(i)); | |
251 | ||
252 | } | |
253 | // if(msgs.size() > 0) { | |
254 | // GraphNode temp[] = msgs.toArray(new GraphNode[0]); | |
255 | // Arrays.sort(temp, new DateComparator()); | |
256 | // findResults.addAll(Arrays.asList(temp)); | |
257 | // } | |
258 | ||
259 | msgs = new ArrayList<GraphNode>(); | |
260 | if (findCriteria.isAsyncMessageSelected()) { | |
261 | for (int i = 0; i < frame.asyncMessageCount(); i++) | |
262 | if (findCriteria.matches(frame.getAsyncMessage(i).getName())) | |
263 | msgs.add(frame.getAsyncMessage(i)); | |
264 | ||
265 | for (int i = 0; i < frame.asyncMessageReturnCount(); i++) | |
266 | if (findCriteria.matches(frame.getAsyncMessageReturn(i).getName())) | |
267 | msgs.add(frame.getAsyncMessageReturn(i)); | |
268 | ||
269 | } | |
270 | // if(msgs.size() > 0) { | |
271 | // GraphNode temp[] = msgs.toArray(new GraphNode[0]); | |
272 | // Arrays.sort(temp, new DateComparator()); | |
273 | // findResults.addAll(Arrays.asList(temp)); | |
274 | // } | |
275 | ||
276 | @SuppressWarnings("rawtypes") | |
277 | List selection = v.getSDWidget().getSelection(); | |
278 | if (selection != null && selection.size() == 1) | |
279 | currentFindIndex = findResults.indexOf(selection.get(0)) + 1; | |
280 | else | |
281 | currentFindIndex = 0; | |
282 | } else { | |
283 | currentFindIndex++; | |
284 | } | |
285 | if (findResults.size() > currentFindIndex) { | |
286 | GraphNode current = (GraphNode) findResults.get(currentFindIndex); | |
287 | v.getSDWidget().moveTo(current); | |
288 | return true; | |
289 | } else { | |
290 | // return notFoundYet(findCriteria); // search in other page | |
291 | return false; | |
292 | } | |
293 | // return false; | |
294 | } | |
295 | ||
296 | @Override | |
297 | public void cancel() { | |
298 | findResults = null; | |
299 | findCriteria = null; | |
300 | currentFindIndex = 0; | |
301 | } | |
302 | ||
303 | public boolean isLifelineSupported() { | |
304 | return false; | |
305 | } | |
306 | ||
307 | public boolean isSyncMessageSupported() { | |
308 | return false; | |
309 | } | |
310 | ||
311 | public boolean isSyncMessageReturnSupported() { | |
312 | return false; | |
313 | } | |
314 | ||
315 | public boolean isAsyncMessageSupported() { | |
316 | return false; | |
317 | } | |
318 | ||
319 | public boolean isAsyncMessageReturnSupported() { | |
320 | return false; | |
321 | } | |
322 | ||
323 | public boolean isStopSupported() { | |
324 | return false; | |
325 | } | |
326 | ||
327 | public Action getFindAction() { | |
328 | return null; | |
329 | } | |
330 | ||
331 | @Override | |
332 | public boolean filter(List<?> filters) { | |
333 | ||
334 | if (savedFrame != null) { | |
335 | savedFrame = v.getFrame(); | |
336 | } | |
337 | ||
338 | Frame frame = v.getFrame(); | |
339 | ||
340 | if (frame == null) { | |
341 | return false; | |
342 | } | |
343 | ||
344 | if (filters.size() != 1) { | |
345 | return false; | |
346 | } | |
347 | ||
348 | FilterCriteria filterCriteria = (FilterCriteria) filters.get(0); | |
349 | ||
350 | // One way is to set visiblity of the item, but this only works for messages and not | |
351 | // for lifelines! It's better to create a new frame without the filtered messages. | |
352 | boolean found = false; | |
353 | if (filterCriteria.getCriteria().isSyncMessageSelected()) { | |
354 | for (int i = 0; i < frame.syncMessageCount(); i++) { | |
355 | if (filterCriteria.getCriteria().matches(frame.getSyncMessage(i).getName())) { | |
356 | frame.getSyncMessage(i).setVisible(false); | |
357 | found = true; | |
358 | } | |
359 | } | |
360 | ||
361 | for (int i = 0; i < frame.syncMessageReturnCount(); i++) | |
362 | if (filterCriteria.getCriteria().matches(frame.getSyncMessageReturn(i).getName())) { | |
363 | frame.getSyncMessageReturn(i).setVisible(false); | |
364 | found = true; | |
365 | } | |
366 | } | |
367 | ||
368 | v.getSDWidget().redraw(); | |
369 | return found; | |
370 | } | |
371 | ||
372 | public ArrayList<?> getCurrentFilters() { | |
373 | return null; | |
374 | } | |
375 | ||
376 | @SuppressWarnings("nls") | |
377 | @Override | |
378 | public String getTitleString() { | |
379 | return "Test Loader"; | |
380 | } | |
381 | ||
382 | @Override | |
383 | public void dispose() { | |
384 | } | |
385 | ||
386 | ||
387 | @Override | |
388 | public void selectionChanged(IWorkbenchPart part, ISelection selection) { | |
389 | ISelection sel = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection(); | |
390 | if (sel != null && (sel instanceof StructuredSelection)) { | |
391 | StructuredSelection stSel = (StructuredSelection) sel; | |
392 | if (stSel.getFirstElement() instanceof HotSpot) { | |
393 | // OpenToolBox gg = new OpenToolBox(v); | |
394 | // gg.run(); | |
395 | } | |
396 | } | |
397 | } | |
398 | ||
399 | /* | |
400 | * (non-Javadoc) | |
401 | * @see org.eclipse.hyades.uml2sd.ui.actions.provider.ISDGraphNodeSupporter#isNodeSupported(int) | |
402 | */ | |
403 | @Override | |
404 | public boolean isNodeSupported(int nodeType) { | |
405 | switch (nodeType) { | |
406 | case ISDGraphNodeSupporter.LIFELINE: | |
407 | case ISDGraphNodeSupporter.SYNCMESSAGE: | |
408 | case ISDGraphNodeSupporter.SYNCMESSAGERETURN: | |
409 | case ISDGraphNodeSupporter.ASYNCMESSAGE: | |
410 | case ISDGraphNodeSupporter.ASYNCMESSAGERETURN: | |
411 | case ISDGraphNodeSupporter.STOP: | |
412 | return true; | |
413 | ||
414 | default: | |
415 | break; | |
416 | } | |
417 | return false; | |
418 | } | |
419 | ||
420 | @Override | |
421 | public String getNodeName(int nodeType, String loaderClassName) { | |
422 | return null; | |
423 | } | |
424 | ||
425 | public class LocalImageImpl implements IImage { | |
426 | protected Image img; | |
427 | ||
428 | public LocalImageImpl(String file) { | |
429 | img = null; | |
430 | img = getResourceImage(file); | |
431 | } | |
432 | ||
433 | public LocalImageImpl(Image img_) { | |
434 | img = null; | |
435 | img = img_; | |
436 | } | |
437 | ||
438 | @SuppressWarnings("nls") | |
439 | public Image getResourceImage(String _name) { | |
440 | ImageDescriptor img; | |
441 | try { | |
442 | URL url = new URL(BASIC_URL, (new StringBuilder("plugin/org.eclipse.linuxtools.tmf.ui/icons/")).append(_name).toString()); | |
443 | img = ImageDescriptor.createFromURL(url); | |
444 | return img.createImage(); | |
445 | } catch (Exception e) { | |
446 | System.err.println(e); | |
447 | } | |
448 | return null; | |
449 | } | |
450 | ||
451 | @Override | |
452 | public Object getImage() { | |
453 | return img; | |
454 | } | |
455 | ||
456 | @Override | |
457 | public void dispose() { | |
458 | if (img != null) | |
459 | img.dispose(); | |
460 | } | |
461 | ||
462 | } | |
463 | ||
464 | @Override | |
465 | public void firstPage() { | |
466 | page = 0; | |
467 | createFrame(); | |
468 | ||
469 | } | |
470 | ||
471 | @Override | |
472 | public void lastPage() { | |
473 | page = 2; | |
474 | createFrame(); | |
475 | } | |
476 | } |