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