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