tmf: Simple warning fixes in tmf.ui and tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / loader / TmfUml2SDSyncLoader.java
1 /**********************************************************************
2 * Copyright (c) 2011, 2012 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org.eclipse.linuxtools.tmf.ui.views.uml2sd.loader;
13
14 import java.util.ArrayList;
15 import java.util.HashMap;
16 import java.util.List;
17 import java.util.Map;
18 import java.util.concurrent.CopyOnWriteArrayList;
19 import java.util.concurrent.locks.ReentrantLock;
20
21 import org.eclipse.core.runtime.IProgressMonitor;
22 import org.eclipse.core.runtime.IStatus;
23 import org.eclipse.core.runtime.Status;
24 import org.eclipse.core.runtime.jobs.Job;
25 import org.eclipse.jface.viewers.ISelection;
26 import org.eclipse.jface.viewers.StructuredSelection;
27 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
28 import org.eclipse.linuxtools.tmf.core.component.TmfComponent;
29 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
30 import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
31 import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
32 import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
33 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
34 import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
35 import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
36 import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
37 import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
38 import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentDisposedSignal;
39 import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal;
40 import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;
41 import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
42 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
43 import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;
44 import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
45 import org.eclipse.linuxtools.tmf.core.uml2sd.ITmfSyncSequenceDiagramEvent;
46 import org.eclipse.linuxtools.tmf.core.uml2sd.TmfSyncSequenceDiagramEvent;
47 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView;
48 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Frame;
49 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode;
50 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline;
51 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.Criteria;
52 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.FilterCriteria;
53 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.FilterListDialog;
54 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider;
55 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFilterProvider;
56 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFindProvider;
57 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter;
58 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader;
59 import org.eclipse.swt.widgets.Display;
60 import org.eclipse.ui.ISelectionListener;
61 import org.eclipse.ui.IWorkbenchPart;
62 import org.eclipse.ui.PlatformUI;
63 import org.eclipse.ui.progress.IProgressConstants;
64
65 /**
66 * <p>
67 * This class is a reference implementation of the
68 * <code>org.eclipse.linuxtools.tmf.ui.Uml2SDLoader</code> extension point. It
69 * provides a Sequence Diagram loader for a user space trace with specific trace
70 * content for sending and receiving signals between components. I also includes
71 * a default implementation for the <code>ITmfEvent</code> parsing.
72 * </p>
73 *
74 * The class <code>TmfUml2SDSyncLoader</code> analyzes events from type
75 * <code>ITmfEvent</code> and creates events type
76 * <code>ITmfSyncSequenceDiagramEvent</code> if the <code>ITmfEvent</code>
77 * contains all relevant information. The analysis checks that the event type
78 * strings contains either string SEND or RECEIVE. If event type matches these
79 * key words, the analyzer will look for strings sender, receiver and signal in
80 * the event fields of type <code>ITmfEventField</code>. If all the data is
81 * found a sequence diagram event from can be created. Note that Sync Messages
82 * are assumed, which means start and end time are the same. <br>
83 * <br>
84 * The parsing of the <code>ITmfEvent</code> is done in the method
85 * <code>getSequnceDiagramEvent()</code> of class
86 * <code>TmfUml2SDSyncLoader</code>. By extending the class
87 * <code>TmfUml2SDSyncLoader</code> and overwriting
88 * <code>getSequnceDiagramEvent()</code> a customized parsing algorithm can be
89 * implemented.<br>
90 * <br>
91 * Note that combined traces of multiple components, that contain the trace
92 * information about the same interactions are not supported in the class
93 * <code>TmfUml2SDSyncLoader</code>.
94 *
95 * @version 1.0
96 * @author Bernd Hufmann
97 */
98 public class TmfUml2SDSyncLoader extends TmfComponent implements IUml2SDLoader, ISDFindProvider, ISDFilterProvider, ISDAdvancedPagingProvider, ISelectionListener {
99
100 // ------------------------------------------------------------------------
101 // Constants
102 // ------------------------------------------------------------------------
103 /**
104 * Default title name.
105 */
106 protected final static String TITLE = Messages.TmfUml2SDSyncLoader_ViewName;
107 /**
108 * Default block size for background request.
109 */
110 protected final static int DEFAULT_BLOCK_SIZE = 50000;
111 /**
112 * Maximum number of messages per page.
113 */
114 protected final static int MAX_NUM_OF_MSG = 10000;
115 /**
116 * Initial time range window.
117 */
118 protected final static long INITIAL_WINDOW_OFFSET = (1L * 100 * 1000 * 1000); // .1sec
119
120 // ------------------------------------------------------------------------
121 // Attributes
122 // ------------------------------------------------------------------------
123
124 // Experiment attributes
125 /**
126 * The TMF experiment reference.
127 */
128 protected TmfExperiment<ITmfEvent> fExperiment = null;
129 /**
130 * The current indexing event request.
131 */
132 protected ITmfEventRequest<ITmfEvent> fIndexRequest = null;
133 /**
134 * The current request to fill a page.
135 */
136 protected ITmfEventRequest<ITmfEvent> fPageRequest = null;
137 /**
138 * Flag whether the time range signal was sent by this loader class or not
139 */
140 volatile protected boolean fIsSignalSent = false;
141 /**
142 * The initial request window size.
143 */
144 volatile protected long fInitialWindow = INITIAL_WINDOW_OFFSET;
145
146 // The view and event attributes
147 /**
148 * The sequence diagram view reference.
149 */
150 protected SDView fView = null;
151 /**
152 * The current sequence diagram frame reference.
153 */
154 protected Frame fFrame = null;
155 /**
156 * The list of sequence diagram events of current page.
157 */
158 protected List<ITmfSyncSequenceDiagramEvent> fEvents = new ArrayList<ITmfSyncSequenceDiagramEvent>();
159
160 // Checkpoint and page attributes
161 /**
162 * The checkpoints of the whole sequence diagram trace (i.e. start time stamp of each page)
163 */
164 protected List<TmfTimeRange> fCheckPoints = new ArrayList<TmfTimeRange>(MAX_NUM_OF_MSG);
165 /**
166 * The current page displayed.
167 */
168 volatile protected int fCurrentPage = 0;
169 /**
170 * The current time selected.
171 */
172 protected ITmfTimestamp fCurrentTime = null;
173 /**
174 * Flag to specify that selection of message is done by selection or by signal.
175 */
176 volatile protected boolean fIsSelect = false;
177
178 // Search attributes
179 /**
180 * The job for searching across pages.
181 */
182 protected SearchJob fFindJob = null;
183 /**
184 * List of found nodes within a page.
185 */
186 protected List<GraphNode> fFindResults = new ArrayList<GraphNode>();
187 /**
188 * The current find criteria reference
189 */
190 protected Criteria fFindCriteria = null;
191 /**
192 * The current find index within the list of found nodes (<code>fFindeResults</code> within a page.
193 */
194 volatile protected int fCurrentFindIndex = 0;
195
196 // Filter attributes
197 /**
198 * The list of active filters.
199 */
200 protected List<FilterCriteria> fFilterCriteria = null;
201
202 // Thread synchronization
203 /**
204 * The synchronization lock.
205 */
206 protected ReentrantLock fLock = new ReentrantLock();
207
208 // ------------------------------------------------------------------------
209 // Constructors
210 // ------------------------------------------------------------------------
211 /**
212 * Default constructor
213 */
214 public TmfUml2SDSyncLoader() {
215 super(TITLE);
216 }
217
218 /**
219 * Constructor
220 *
221 * @param name Name of loader
222 */
223 public TmfUml2SDSyncLoader(String name) {
224 super(name);
225 }
226
227 // ------------------------------------------------------------------------
228 // Operations
229 // ------------------------------------------------------------------------
230 /**
231 * Returns the current time if available else null.
232 *
233 * @return the current time if available else null
234 */
235 public ITmfTimestamp getCurrentTime() {
236 fLock.lock();
237 try {
238 if (fCurrentTime != null) {
239 return fCurrentTime.clone();
240 }
241 return null;
242 } finally {
243 fLock.unlock();
244 }
245 }
246
247 /**
248 * Waits for the page request to be completed
249 */
250 public void waitForCompletion() {
251 fLock.lock();
252 ITmfEventRequest<ITmfEvent> request = fPageRequest;
253 fLock.unlock();
254 if (request != null) {
255 try {
256 request.waitForCompletion();
257 } catch (InterruptedException e) {
258 // ignore
259 }
260 }
261 }
262
263 /**
264 * Signal handler for the experiment selected signal.
265 *
266 * Spawns a request to index the experiment (checkpoints creation) as well as it fills
267 * the first page.
268 *
269 * @param signal The experiment selected signal
270 */
271 @SuppressWarnings("unchecked")
272 @TmfSignalHandler
273 public void experimentSelected(TmfExperimentSelectedSignal<ITmfEvent> signal) {
274
275 final Job job = new IndexingJob("Indexing " + getName() + "..."); //$NON-NLS-1$ //$NON-NLS-2$
276 job.setUser(false);
277 job.schedule();
278
279 fLock.lock();
280 try {
281 // Update the trace reference
282 TmfExperiment<ITmfEvent> exp = (TmfExperiment<ITmfEvent>) signal.getExperiment();
283 if (!exp.equals(fExperiment)) {
284 fExperiment = exp;
285 }
286
287 TmfTimeRange window = TmfTimeRange.ETERNITY;
288
289 fIndexRequest = new TmfEventRequest<ITmfEvent>(ITmfEvent.class, window, TmfDataRequest.ALL_DATA, DEFAULT_BLOCK_SIZE, ITmfDataRequest.ExecutionType.BACKGROUND) {
290
291 private ITmfTimestamp fFirstTime = null;
292 private ITmfTimestamp fLastTime = null;
293 private int fNbSeqEvents = 0;
294 private final List<ITmfSyncSequenceDiagramEvent> fSdEvents = new ArrayList<ITmfSyncSequenceDiagramEvent>(MAX_NUM_OF_MSG);
295
296 /*
297 * (non-Javadoc)
298 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
299 */
300 @Override
301 public void handleData(ITmfEvent event) {
302 super.handleData(event);
303
304 ITmfSyncSequenceDiagramEvent sdEvent = getSequnceDiagramEvent(event);
305
306 if (sdEvent != null) {
307 ++fNbSeqEvents;
308
309 if (fFirstTime == null) {
310 fFirstTime = event.getTimestamp().clone();
311 }
312
313 fLastTime = event.getTimestamp().clone();
314
315 if ((fNbSeqEvents % MAX_NUM_OF_MSG) == 0) {
316 fLock.lock();
317 try {
318 fCheckPoints.add(new TmfTimeRange(fFirstTime, fLastTime));
319 if (fView != null) {
320 fView.updateCoolBar();
321 }
322 } finally {
323 fLock.unlock();
324 }
325 fFirstTime = null;
326
327 }
328
329 if (fNbSeqEvents > MAX_NUM_OF_MSG) {
330 // page is full
331 return;
332 }
333
334 fSdEvents.add(sdEvent);
335
336 if (fNbSeqEvents == MAX_NUM_OF_MSG) {
337 fillCurrentPage(fSdEvents);
338 }
339 }
340 }
341
342 /*
343 * (non-Javadoc)
344 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleSuccess()
345 */
346 @Override
347 public void handleSuccess() {
348 if ((fFirstTime != null) && (fLastTime != null)) {
349
350 fLock.lock();
351 try {
352 fCheckPoints.add(new TmfTimeRange(fFirstTime, fLastTime));
353 if (fView != null) {
354 fView.updateCoolBar();
355 }
356 } finally {
357 fLock.unlock();
358 }
359 }
360
361 if (fNbSeqEvents <= MAX_NUM_OF_MSG) {
362 fillCurrentPage(fSdEvents);
363 }
364
365 super.handleSuccess();
366 }
367
368 /*
369 * (non-Javadoc)
370 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleCompleted()
371 */
372 @Override
373 public void handleCompleted() {
374 if (fEvents.isEmpty()) {
375 fFrame = new Frame();
376 fView.setFrameSync(fFrame);
377 }
378 super.handleCompleted();
379 job.cancel();
380 }
381 };
382
383 fExperiment.sendRequest(fIndexRequest);
384 } finally {
385 fLock.unlock();
386 }
387
388 }
389
390 /**
391 * Signal handler for the experiment disposed signal.
392 *
393 * @param signal The experiment disposed signal
394 */
395 @TmfSignalHandler
396 public void experimentDisposed(TmfExperimentDisposedSignal<ITmfEvent> signal) {
397 if (signal.getExperiment() != TmfExperiment.getCurrentExperiment()) {
398 return;
399 }
400 fLock.lock();
401 try {
402 if ((fIndexRequest != null) && !fIndexRequest.isCompleted()) {
403 fIndexRequest.cancel();
404 fIndexRequest = null;
405 }
406
407 cancelOngoingRequests();
408
409 if (fFilterCriteria != null) {
410 fFilterCriteria.clear();
411 }
412
413 FilterListDialog.deactivateSavedGlobalFilters();
414
415 resetLoader();
416 } finally {
417 fLock.unlock();
418 }
419 }
420
421 /**
422 * Moves to the page that contains the time provided by the signal. The messages will be selected
423 * if the provided time is the time of a message.
424 *
425 * @param signal The Time synch signal.
426 */
427 @TmfSignalHandler
428 public void synchToTime(TmfTimeSynchSignal signal) {
429 fLock.lock();
430 try {
431 if ((signal.getSource() != this) && (fFrame != null)) {
432
433 fCurrentTime = signal.getCurrentTime();
434 fIsSelect = true;
435 moveToMessage();
436 }
437 } finally {
438 fLock.unlock();
439 }
440 }
441
442 /**
443 * Moves to the page that contains the current time provided by signal.
444 * No message will be selected however the focus will be set to the message
445 * if the provided time is the time of a message.
446 *
447 * @param signal The time range sync signal
448 */
449 @TmfSignalHandler
450 public void synchToTimeRange(TmfRangeSynchSignal signal) {
451 fLock.lock();
452 try {
453 if ((signal.getSource() != this) && (fFrame != null) && !fIsSignalSent) {
454 TmfTimeRange newTimeRange = signal.getCurrentRange();
455 ITmfTimestamp delta = newTimeRange.getEndTime().getDelta(newTimeRange.getStartTime());
456 fInitialWindow = delta.getValue();
457
458 fIsSelect = false;
459 fCurrentTime = newTimeRange.getStartTime();
460
461 moveToMessage();
462 }
463 } finally {
464 fLock.unlock();
465 }
466
467 }
468
469 /*
470 * (non-Javadoc)
471 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#setViewer(org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView)
472 */
473 @SuppressWarnings("unchecked")
474 @Override
475 public void setViewer(SDView viewer) {
476
477 fLock.lock();
478 try {
479 fView = viewer;
480 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
481 fView.setSDFindProvider(this);
482 fView.setSDPagingProvider(this);
483 fView.setSDFilterProvider(this);
484
485 resetLoader();
486
487 fExperiment = (TmfExperiment<ITmfEvent>) TmfExperiment.getCurrentExperiment();
488 if (fExperiment != null) {
489 experimentSelected(new TmfExperimentSelectedSignal<ITmfEvent>(this, fExperiment));
490 }
491 } finally {
492 fLock.unlock();
493 }
494 }
495
496 /*
497 * (non-Javadoc)
498 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#getTitleString()
499 */
500 @Override
501 public String getTitleString() {
502 return getName();
503 }
504
505 /*
506 * (non-Javadoc)
507 * @see org.eclipse.linuxtools.tmf.component.TmfComponent#dispose()
508 */
509 @Override
510 public void dispose() {
511 super.dispose();
512 fLock.lock();
513 try {
514 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().removePostSelectionListener(this);
515 fView.setSDFindProvider(null);
516 fView.setSDPagingProvider(null);
517 fView.setSDFilterProvider(null);
518 fView = null;
519 } finally {
520 fLock.unlock();
521 }
522 }
523
524 /*
525 * (non-Javadoc)
526 * @see org.eclipse.hyades.uml2sd.ui.actions.provider.ISDGraphNodeSupporter#isNodeSupported(int)
527 */
528 @Override
529 public boolean isNodeSupported(int nodeType) {
530 switch (nodeType) {
531 case ISDGraphNodeSupporter.LIFELINE:
532 case ISDGraphNodeSupporter.SYNCMESSAGE:
533 return true;
534
535 default:
536 break;
537 }
538 return false;
539 }
540
541 /*
542 * (non-Javadoc)
543 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter#getNodeName(int, java.lang.String)
544 */
545 @Override
546 public String getNodeName(int nodeType, String loaderClassName) {
547 switch (nodeType) {
548 case ISDGraphNodeSupporter.LIFELINE:
549 return Messages.TmfUml2SDSyncLoader_CategoryLifeline;
550 case ISDGraphNodeSupporter.SYNCMESSAGE:
551 return Messages.TmfUml2SDSyncLoader_CategoryMessage;
552 default:
553 break;
554 }
555 return ""; //$NON-NLS-1$
556 }
557
558 /*
559 * (non-Javadoc)
560 * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
561 */
562 @Override
563 public void selectionChanged(IWorkbenchPart part, ISelection selection) {
564 ISelection sel = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
565 if ((sel != null) && (sel instanceof StructuredSelection)) {
566 StructuredSelection stSel = (StructuredSelection) sel;
567 if (stSel.getFirstElement() instanceof TmfSyncMessage) {
568 TmfSyncMessage syncMsg = ((TmfSyncMessage) stSel.getFirstElement());
569 broadcast(new TmfTimeSynchSignal(this, syncMsg.getStartTime()));
570 }
571 }
572 }
573
574 /*
575 * (non-Javadoc)
576 * @see
577 * org.eclipse.hyades.uml2sd.ui.actions.provider.ISDFindProvider#find(org.eclipse.hyades.uml2sd.ui.actions.widgets.Criteria)
578 */
579 @Override
580 public boolean find(Criteria toSearch) {
581 fLock.lock();
582 try {
583 if (fFrame == null) {
584 return false;
585 }
586
587 if ((fFindResults == null) || (fFindCriteria == null) || !fFindCriteria.compareTo(toSearch)) {
588 fFindResults = new CopyOnWriteArrayList<GraphNode>();
589 fFindCriteria = toSearch;
590 if (fFindCriteria.isLifeLineSelected()) {
591 for (int i = 0; i < fFrame.lifeLinesCount(); i++) {
592 if (fFindCriteria.matches(fFrame.getLifeline(i).getName())) {
593 fFindResults.add(fFrame.getLifeline(i));
594 }
595 }
596 }
597
598 ArrayList<GraphNode> msgs = new ArrayList<GraphNode>();
599 if (fFindCriteria.isSyncMessageSelected()) {
600 for (int i = 0; i < fFrame.syncMessageCount(); i++) {
601 if (fFindCriteria.matches(fFrame.getSyncMessage(i).getName())) {
602 msgs.add(fFrame.getSyncMessage(i));
603 }
604 }
605 }
606
607 if (!msgs.isEmpty()) {
608 fFindResults.addAll(msgs);
609 }
610
611 @SuppressWarnings("rawtypes")
612 List selection = fView.getSDWidget().getSelection();
613 if ((selection != null) && (selection.size() == 1)) {
614 fCurrentFindIndex = fFindResults.indexOf(selection.get(0)) + 1;
615 } else {
616 fCurrentFindIndex = 0;
617 }
618 } else {
619 fCurrentFindIndex++;
620 }
621
622 if (fFindResults.size() > fCurrentFindIndex) {
623 GraphNode current = fFindResults.get(fCurrentFindIndex);
624 fView.getSDWidget().moveTo(current);
625 return true;
626 }
627 fFindResults = null;
628 fCurrentFindIndex =0;
629 return findInNextPages(fFindCriteria); // search in other page
630 } finally {
631 fLock.unlock();
632 }
633 }
634
635 /*
636 * (non-Javadoc)
637 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFindProvider#cancel()
638 */
639 @Override
640 public void cancel() {
641 cancelOngoingRequests();
642 }
643
644 /*
645 * (non-Javadoc)
646 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFilterProvider#filter(java.util.List)
647 */
648 @SuppressWarnings("unchecked")
649 @Override
650 public boolean filter(List<?> filters) {
651 fLock.lock();
652 try {
653 cancelOngoingRequests();
654
655 List<FilterCriteria> list = (List<FilterCriteria>)filters;
656 fFilterCriteria = new ArrayList<FilterCriteria>(list);
657
658 fillCurrentPage(fEvents);
659
660 } finally {
661 fLock.unlock();
662 }
663 return true;
664 }
665
666 /*
667 * (non-Javadoc)
668 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasNextPage()
669 */
670 @Override
671 public boolean hasNextPage() {
672 fLock.lock();
673 try {
674 int size = fCheckPoints.size();
675 if (size > 0) {
676 return fCurrentPage < (size - 1);
677 }
678 } finally {
679 fLock.unlock();
680 }
681 return false;
682 }
683
684 /*
685 * (non-Javadoc)
686 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasPrevPage()
687 */
688 @Override
689 public boolean hasPrevPage() {
690 fLock.lock();
691 try {
692 return fCurrentPage > 0;
693 } finally {
694 fLock.unlock();
695 }
696 }
697
698 /*
699 * (non-Javadoc)
700 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#nextPage()
701 */
702 @Override
703 public void nextPage() {
704 fLock.lock();
705 try {
706 // Safety check
707 if (fCurrentPage >= (fCheckPoints.size() - 1)) {
708 return;
709 }
710
711 cancelOngoingRequests();
712 fCurrentTime = null;
713 fCurrentPage++;
714 moveToPage();
715 } finally {
716 fLock.unlock();
717 }
718 }
719
720 /*
721 * (non-Javadoc)
722 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#prevPage()
723 */
724 @Override
725 public void prevPage() {
726 fLock.lock();
727 try {
728 // Safety check
729 if (fCurrentPage <= 0) {
730 return;
731 }
732
733 cancelOngoingRequests();
734 fCurrentTime = null;
735 fCurrentPage--;
736 moveToPage();
737 } finally {
738 fLock.unlock();
739 }
740 }
741
742 /*
743 * (non-Javadoc)
744 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#firstPage()
745 */
746 @Override
747 public void firstPage() {
748 fLock.lock();
749 try {
750
751 cancelOngoingRequests();
752 fCurrentTime = null;
753 fCurrentPage = 0;
754 moveToPage();
755 } finally {
756 fLock.unlock();
757 }
758 }
759
760 /*
761 * (non-Javadoc)
762 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#lastPage()
763 */
764 @Override
765 public void lastPage() {
766 fLock.lock();
767 try {
768 cancelOngoingRequests();
769 fCurrentTime = null;
770 fCurrentPage = fCheckPoints.size() - 1;
771 moveToPage();
772 } finally {
773 fLock.unlock();
774 }
775 }
776
777 /*
778 * (non-Javadoc)
779 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#currentPage()
780 */
781 @Override
782 public int currentPage() {
783 fLock.lock();
784 try {
785 return fCurrentPage;
786 } finally {
787 fLock.unlock();
788 }
789 }
790
791 /*
792 * (non-Javadoc)
793 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pagesCount()
794 */
795 @Override
796 public int pagesCount() {
797 fLock.lock();
798 try {
799 return fCheckPoints.size();
800 } finally {
801 fLock.unlock();
802 }
803 }
804
805 /*
806 * (non-Javadoc)
807 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pageNumberChanged(int)
808 */
809 @Override
810 public void pageNumberChanged(int pagenNumber) {
811 int localPageNumber = pagenNumber;
812
813 fLock.lock();
814 try {
815 cancelOngoingRequests();
816
817 if (localPageNumber < 0) {
818 localPageNumber = 0;
819 }
820 int size = fCheckPoints.size();
821 if (localPageNumber > (size - 1)) {
822 localPageNumber = size - 1;
823 }
824 fCurrentPage = localPageNumber;
825 moveToPage();
826 } finally {
827 fLock.unlock();
828 }
829 }
830
831 /*
832 * (non-Javadoc)
833 * @see org.eclipse.linuxtools.tmf.component.TmfComponent#broadcast(org.eclipse.linuxtools.tmf.signal.TmfSignal)
834 */
835 @Override
836 public void broadcast(TmfSignal signal) {
837 fIsSignalSent = true;
838 super.broadcast(signal);
839 fIsSignalSent = false;
840 }
841
842 /**
843 * Cancels any ongoing find operation
844 */
845 protected void cancelOngoingRequests() {
846 fLock.lock();
847 try {
848 // Cancel the search thread
849 if (fFindJob != null) {
850 fFindJob.cancel();
851 }
852
853 fFindResults = null;
854 fFindCriteria = null;
855 fCurrentFindIndex = 0;
856
857 if ((fPageRequest != null) && !fPageRequest.isCompleted()) {
858 fPageRequest.cancel();
859 fPageRequest = null;
860 }
861 } finally {
862 fLock.unlock();
863 }
864 }
865
866 /**
867 * Resets loader attributes
868 */
869 protected void resetLoader() {
870 fLock.lock();
871 try {
872 fCurrentTime = null;
873 fEvents.clear();
874 fCheckPoints.clear();
875 fCurrentPage = 0;
876 fCurrentFindIndex = 0;
877 fFindCriteria = null;
878 fFindResults = null;
879 fInitialWindow = INITIAL_WINDOW_OFFSET;
880 fView.setFrameSync(new Frame());
881 fFrame = null;
882 }
883 finally {
884 fLock.unlock();
885 }
886
887 }
888
889 /**
890 * Fills current page with sequence diagram content.
891 *
892 * @param events sequence diagram events
893 */
894 protected void fillCurrentPage(List<ITmfSyncSequenceDiagramEvent> events) {
895
896 fLock.lock();
897 try {
898 fEvents = new ArrayList<ITmfSyncSequenceDiagramEvent>(events);
899 if (fView != null) {
900 fView.toggleWaitCursorAsync(true);
901 }
902 } finally {
903 fLock.unlock();
904 }
905
906 final Frame frame = new Frame();
907
908 if (!events.isEmpty()) {
909 Map<String, Lifeline> nodeToLifelineMap = new HashMap<String, Lifeline>();
910
911 frame.setName(Messages.TmfUml2SDSyncLoader_FrameName);
912
913 for (int i = 0; i < events.size(); i++) {
914
915 ITmfSyncSequenceDiagramEvent sdEvent = events.get(i);
916
917 if ((nodeToLifelineMap.get(sdEvent.getSender()) == null) && (!filterLifeLine(sdEvent.getSender()))) {
918 Lifeline lifeline = new Lifeline();
919 lifeline.setName(sdEvent.getSender());
920 nodeToLifelineMap.put(sdEvent.getSender(), lifeline);
921 frame.addLifeLine(lifeline);
922 }
923
924 if ((nodeToLifelineMap.get(sdEvent.getReceiver()) == null) && (!filterLifeLine(sdEvent.getReceiver()))) {
925 Lifeline lifeline = new Lifeline();
926 lifeline.setName(sdEvent.getReceiver());
927 nodeToLifelineMap.put(sdEvent.getReceiver(), lifeline);
928 frame.addLifeLine(lifeline);
929 }
930 }
931
932 int eventOccurence = 1;
933
934 for (int i = 0; i < events.size(); i++) {
935 ITmfSyncSequenceDiagramEvent sdEvent = events.get(i);
936
937 // Check message filter
938 if (filterMessage(sdEvent)) {
939 continue;
940 }
941
942 // Set the message sender and receiver
943 Lifeline startLifeline = nodeToLifelineMap.get(sdEvent.getSender());
944 Lifeline endLifeline = nodeToLifelineMap.get(sdEvent.getReceiver());
945
946 // Check if any of the lifelines were filtered
947 if ((startLifeline == null) || (endLifeline == null)) {
948 continue;
949 }
950
951 int tmp = Math.max(startLifeline.getEventOccurrence(), endLifeline.getEventOccurrence());
952 eventOccurence = Math.max(eventOccurence, tmp);
953
954 startLifeline.setCurrentEventOccurrence(eventOccurence);
955 endLifeline.setCurrentEventOccurrence(eventOccurence);
956
957 TmfSyncMessage message = new TmfSyncMessage(sdEvent, eventOccurence++);
958
959 message.setStartLifeline(startLifeline);
960 message.setEndLifeline(endLifeline);
961
962 message.setTime(sdEvent.getStartTime());
963
964 // add the message to the frame
965 frame.addMessage(message);
966
967 }
968 fLock.lock();
969 try {
970 if (!fView.getSDWidget().isDisposed()) {
971 fView.getSDWidget().getDisplay().asyncExec(new Runnable() {
972
973 @Override
974 public void run() {
975
976 fLock.lock();
977 try {
978 // check if view was disposed in the meanwhile
979 if ((fView != null) && (!fView.getSDWidget().isDisposed())) {
980 fFrame = frame;
981 fView.setFrame(fFrame);
982
983 if (fCurrentTime != null) {
984 moveToMessageInPage();
985 }
986
987 if (fFindCriteria != null) {
988 find(fFindCriteria);
989 }
990
991 fView.toggleWaitCursorAsync(false);
992 }
993 } finally {
994 fLock.unlock();
995 }
996
997 }
998 });
999 }
1000 }
1001 finally {
1002 fLock.unlock();
1003 }
1004 }
1005 }
1006
1007 /**
1008 * Moves to a certain message defined by timestamp (across pages)
1009 */
1010 protected void moveToMessage() {
1011 int page = 0;
1012
1013 fLock.lock();
1014 try {
1015 page = getPage(fCurrentTime);
1016
1017 if (page == fCurrentPage) {
1018 moveToMessageInPage();
1019 return;
1020 }
1021 fCurrentPage = page;
1022 moveToPage(false);
1023 } finally {
1024 fLock.unlock();
1025 }
1026 }
1027
1028 /**
1029 * Moves to a certain message defined by timestamp in current page
1030 */
1031 protected void moveToMessageInPage() {
1032 fLock.lock();
1033 try {
1034 if (!fView.getSDWidget().isDisposed()) {
1035 // Check for GUI thread
1036 if(Display.getCurrent() != null) {
1037 // Already in GUI thread - execute directly
1038 TmfSyncMessage prevMessage = null;
1039 TmfSyncMessage syncMessage = null;
1040 boolean isExactTime = false;
1041 for (int i = 0; i < fFrame.syncMessageCount(); i++) {
1042 if (fFrame.getSyncMessage(i) instanceof TmfSyncMessage) {
1043 syncMessage = (TmfSyncMessage) fFrame.getSyncMessage(i);
1044 if (syncMessage.getStartTime().compareTo(fCurrentTime, false) == 0) {
1045 isExactTime = true;
1046 break;
1047 } else if ((syncMessage.getStartTime().compareTo(fCurrentTime, false) > 0) && (prevMessage != null)) {
1048 syncMessage = prevMessage;
1049 break;
1050 }
1051 prevMessage = syncMessage;
1052 }
1053 }
1054 if (fIsSelect && isExactTime) {
1055 fView.getSDWidget().moveTo(syncMessage);
1056 }
1057 else {
1058 fView.getSDWidget().ensureVisible(syncMessage);
1059 fView.getSDWidget().clearSelection();
1060 fView.getSDWidget().redraw();
1061 }
1062 }
1063 else {
1064 // Not in GUI thread - queue action in GUI thread.
1065 fView.getSDWidget().getDisplay().asyncExec(new Runnable() {
1066 @Override
1067 public void run() {
1068 moveToMessageInPage();
1069 }
1070 });
1071 }
1072 }
1073 }
1074 finally {
1075 fLock.unlock();
1076 }
1077 }
1078
1079 /**
1080 * Moves to a certain message defined by timestamp (across pages)
1081 */
1082 protected void moveToPage() {
1083 moveToPage(true);
1084 }
1085
1086 /**
1087 * Moves to a certain page.
1088 *
1089 * @param notifyAll true to broadcast time range signal to other signal handlers else false
1090 */
1091 protected void moveToPage(boolean notifyAll) {
1092
1093 TmfTimeRange window = null;
1094
1095 fLock.lock();
1096 try {
1097 // Safety check
1098 if (fCurrentPage > fCheckPoints.size()) {
1099 return;
1100 }
1101 window = fCheckPoints.get(fCurrentPage);
1102 } finally {
1103 fLock.unlock();
1104 }
1105
1106 if (window == null) {
1107 window = TmfTimeRange.ETERNITY;
1108 }
1109
1110 fPageRequest = new TmfEventRequest<ITmfEvent>(ITmfEvent.class, window, TmfDataRequest.ALL_DATA, 1, ITmfDataRequest.ExecutionType.FOREGROUND) {
1111 private final List<ITmfSyncSequenceDiagramEvent> fSdEvent = new ArrayList<ITmfSyncSequenceDiagramEvent>();
1112
1113 @Override
1114 public void handleData(ITmfEvent event) {
1115 super.handleData(event);
1116
1117 ITmfSyncSequenceDiagramEvent sdEvent = getSequnceDiagramEvent(event);
1118
1119 if (sdEvent != null) {
1120 fSdEvent.add(sdEvent);
1121 }
1122 }
1123
1124 @Override
1125 public void handleSuccess() {
1126 fillCurrentPage(fSdEvent);
1127 super.handleSuccess();
1128 }
1129
1130 };
1131
1132 fExperiment.sendRequest(fPageRequest);
1133
1134 if (notifyAll) {
1135 TmfTimeRange timeRange = getSignalTimeRange(window.getStartTime());
1136 broadcast(new TmfRangeSynchSignal(this, timeRange, timeRange.getStartTime()));
1137 }
1138 }
1139
1140 /**
1141 * Gets page that contains timestamp
1142 *
1143 * @param time The timestamp
1144 * @return page that contains the time
1145 */
1146 protected int getPage(ITmfTimestamp time) {
1147 int page;
1148 int size;
1149 fLock.lock();
1150 try {
1151 size = fCheckPoints.size();
1152 for (page = 0; page < size; page++) {
1153 TmfTimeRange timeRange = fCheckPoints.get(page);
1154 if (timeRange.getEndTime().compareTo(time, false) >= 0) {
1155 break;
1156 }
1157 }
1158 if (page >= size) {
1159 page = size - 1;
1160 }
1161 return page;
1162 } finally {
1163 fLock.unlock();
1164 }
1165 }
1166
1167 /**
1168 * Background search in trace for expression in criteria.
1169 *
1170 * @param findCriteria The find criteria
1171 * @return true if background request was started else false
1172 */
1173 protected boolean findInNextPages(Criteria findCriteria) {
1174 fLock.lock();
1175 try {
1176 if (fFindJob != null) {
1177 return true;
1178 }
1179
1180 int nextPage = fCurrentPage + 1;
1181
1182 if ((nextPage) >= fCheckPoints.size()) {
1183 // we are at the end
1184 return false;
1185 }
1186
1187 TmfTimeRange window = new TmfTimeRange(fCheckPoints.get(nextPage).getStartTime().clone(), fCheckPoints.get(fCheckPoints.size()-1).getEndTime().clone());
1188 fFindJob = new SearchJob(findCriteria, window);
1189 fFindJob.schedule();
1190 fView.toggleWaitCursorAsync(true);
1191 } finally {
1192 fLock.unlock();
1193 }
1194 return true;
1195 }
1196
1197 /**
1198 * Gets time range for time range signal.
1199 *
1200 * @param startTime The start time of time range.
1201 * @return the time range
1202 */
1203 protected TmfTimeRange getSignalTimeRange(ITmfTimestamp startTime) {
1204 fLock.lock();
1205 try {
1206 TmfTimestamp initialEndOfWindow = new TmfTimestamp(startTime.getValue() + fInitialWindow, startTime.getScale(), startTime.getPrecision());
1207 return new TmfTimeRange(startTime, initialEndOfWindow);
1208 }
1209 finally {
1210 fLock.unlock();
1211 }
1212 }
1213
1214 /**
1215 * Checks if filter criteria matches the message name in given SD event.
1216 *
1217 * @param sdEvent The SD event to check
1218 * @return true if match else false.
1219 */
1220 protected boolean filterMessage(ITmfSyncSequenceDiagramEvent sdEvent) {
1221 fLock.lock();
1222 try {
1223 if (fFilterCriteria != null) {
1224 for(FilterCriteria criteria : fFilterCriteria) {
1225 if (criteria.isActive() && criteria.getCriteria().isSyncMessageSelected() && criteria.getCriteria().matches(sdEvent.getName())) {
1226 return true;
1227 }
1228 }
1229 }
1230 } finally {
1231 fLock.unlock();
1232 }
1233 return false;
1234 }
1235
1236 /**
1237 * Checks if filter criteria matches a lifeline name (sender or receiver) in given SD event.
1238 *
1239 * @param lifeline the message receiver
1240 * @return true if match else false.
1241 */
1242 protected boolean filterLifeLine(String lifeline) {
1243 fLock.lock();
1244 try {
1245 if (fFilterCriteria != null) {
1246 for(FilterCriteria criteria : fFilterCriteria) {
1247 if (criteria.isActive() && criteria.getCriteria().isLifeLineSelected() && criteria.getCriteria().matches(lifeline)) {
1248 return true;
1249 }
1250 }
1251 }
1252 } finally {
1253 fLock.unlock();
1254 }
1255 return false;
1256 }
1257
1258 /**
1259 * Job to search in trace for given time range.
1260 */
1261 protected class SearchJob extends Job {
1262
1263 /**
1264 * The search event request.
1265 */
1266 final protected SearchEventRequest fSearchRequest;
1267
1268 /**
1269 * Constructor
1270 *
1271 * @param findCriteria The search criteria
1272 * @param window Time range to search in
1273 */
1274 public SearchJob(Criteria findCriteria, TmfTimeRange window) {
1275 super(Messages.TmfUml2SDSyncLoader_SearchJobDescrition);
1276 fSearchRequest = new SearchEventRequest(window, TmfDataRequest.ALL_DATA, 1, ITmfDataRequest.ExecutionType.FOREGROUND, findCriteria);
1277 }
1278
1279 /*
1280 * (non-Javadoc)
1281 * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
1282 */
1283 @Override
1284 protected IStatus run(IProgressMonitor monitor) {
1285 fSearchRequest.setMonitor(monitor);
1286
1287 fExperiment.sendRequest(fSearchRequest);
1288
1289 try {
1290 fSearchRequest.waitForCompletion();
1291 } catch (InterruptedException e) {
1292 Activator.getDefault().logError("Search request interrupted!", e); //$NON-NLS-1$
1293 }
1294
1295 IStatus status = Status.OK_STATUS;
1296 if (fSearchRequest.isFound() && (fSearchRequest.getFoundTime() != null)) {
1297 fCurrentTime = fSearchRequest.getFoundTime();
1298
1299 // Avoid double-selection. Selection will be done when calling find(criteria)
1300 // after moving to relevant page
1301 fIsSelect = false;
1302 if (!fView.getSDWidget().isDisposed()) {
1303 fView.getSDWidget().getDisplay().asyncExec(new Runnable() {
1304
1305 @Override
1306 public void run() {
1307 moveToMessage();
1308 }
1309 });
1310 }
1311 }
1312 else {
1313 if (monitor.isCanceled()) {
1314 status = Status.CANCEL_STATUS;
1315 }
1316 else {
1317 // String was not found
1318 status = new Status(IStatus.WARNING, Activator.PLUGIN_ID, Messages.TmfUml2SDSyncLoader_SearchNotFound);
1319 }
1320 setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);
1321 }
1322 monitor.done();
1323
1324 fLock.lock();
1325 try {
1326 fView.toggleWaitCursorAsync(false);
1327 fFindJob = null;
1328 } finally {
1329 fLock.unlock();
1330 }
1331
1332 return status;
1333 }
1334
1335 /*
1336 * (non-Javadoc)
1337 * @see org.eclipse.core.runtime.jobs.Job#canceling()
1338 */
1339 @Override
1340 protected void canceling() {
1341 fSearchRequest.cancel();
1342 fLock.lock();
1343 try {
1344 fFindJob = null;
1345 } finally {
1346 fLock.unlock();
1347 }
1348 }
1349 }
1350
1351 /**
1352 * TMF event request for searching within trace.
1353 */
1354 protected class SearchEventRequest extends TmfEventRequest<ITmfEvent> {
1355
1356 /**
1357 * The find criteria.
1358 */
1359 final private Criteria fCriteria;
1360 /**
1361 * A progress monitor
1362 */
1363 private IProgressMonitor fMonitor;
1364 /**
1365 * Flag to indicate that node was found according the criteria .
1366 */
1367 private boolean fIsFound = false;
1368 /**
1369 * Time stamp of found item.
1370 */
1371 private ITmfTimestamp fFoundTime = null;
1372
1373 /**
1374 * Constructor
1375 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1376 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1377 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1378 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1379 * @param criteria The search criteria
1380 */
1381 public SearchEventRequest(TmfTimeRange range, int nbRequested, int blockSize, ExecutionType execType, Criteria criteria) {
1382 this(range, nbRequested, blockSize, execType, criteria, null);
1383 }
1384
1385 /**
1386 * Constructor
1387 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1388 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1389 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1390 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1391 * @param criteria The search criteria
1392 * @param monitor progress monitor
1393 */
1394 public SearchEventRequest(TmfTimeRange range, int nbRequested, int blockSize, ExecutionType execType, Criteria criteria, IProgressMonitor monitor) {
1395 super(ITmfEvent.class, range, nbRequested, blockSize, execType);
1396 fCriteria = new Criteria(criteria);
1397 fMonitor = monitor;
1398 }
1399
1400 /*
1401 * (non-Javadoc)
1402 * @see org.eclipse.linuxtools.tmf.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.event.TmfData)
1403 */
1404 @Override
1405 public void handleData(ITmfEvent event) {
1406 super.handleData(event);
1407
1408 if ((fMonitor!= null) && fMonitor.isCanceled()) {
1409 super.cancel();
1410 return;
1411 }
1412
1413 ITmfSyncSequenceDiagramEvent sdEvent = getSequnceDiagramEvent(event);
1414
1415 if (sdEvent != null) {
1416
1417 if (fCriteria.isLifeLineSelected()) {
1418 if (fCriteria.matches(sdEvent.getSender())) {
1419 fFoundTime = event.getTimestamp().clone();
1420 fIsFound = true;
1421 super.cancel();
1422 }
1423
1424 if (fCriteria.matches(sdEvent.getReceiver())) {
1425 fFoundTime = event.getTimestamp().clone();
1426 fIsFound = true;
1427 super.cancel();
1428 }
1429 }
1430
1431 if (fCriteria.isSyncMessageSelected() && fCriteria.matches(sdEvent.getName())) {
1432 fFoundTime = event.getTimestamp().clone();
1433 fIsFound = true;
1434 super.cancel();
1435 }
1436 }
1437 }
1438
1439 /**
1440 * Set progress monitor.
1441 *
1442 * @param monitor The monitor to assign
1443 */
1444 public void setMonitor(IProgressMonitor monitor) {
1445 fMonitor = monitor;
1446 }
1447
1448 /**
1449 * Check if find criteria was met.
1450 *
1451 * @return true if find criteria was met.
1452 */
1453 public boolean isFound() {
1454 return fIsFound;
1455 }
1456
1457 /**
1458 * Returns timestamp of found time.
1459 *
1460 * @return timestamp of found time.
1461 */
1462 public ITmfTimestamp getFoundTime() {
1463 return fFoundTime;
1464 }
1465 }
1466
1467 /**
1468 * Job class to provide progress monitor feedback.
1469 *
1470 * @version 1.0
1471 * @author Bernd Hufmann
1472 *
1473 */
1474 protected static class IndexingJob extends Job {
1475
1476 public IndexingJob(String name) {
1477 super(name);
1478 }
1479
1480 @Override
1481 protected IStatus run(IProgressMonitor monitor) {
1482 while (!monitor.isCanceled()) {
1483 try {
1484 Thread.sleep(100);
1485 } catch (InterruptedException e) {
1486 return Status.OK_STATUS;
1487 }
1488 }
1489 monitor.done();
1490 return Status.OK_STATUS;
1491 }
1492 }
1493
1494
1495 /**
1496 * Returns sequence diagram event if details in given event are available else null.
1497 *
1498 * @param tmfEvent Event to parse for sequence diagram event details
1499 * @return sequence diagram event if details are available else null
1500 */
1501 protected ITmfSyncSequenceDiagramEvent getSequnceDiagramEvent(ITmfEvent tmfEvent){
1502 //type = .*RECEIVE.* or .*SEND.*
1503 //content = sender:<sender name>:receiver:<receiver name>,signal:<signal name>
1504 String eventType = tmfEvent.getType().toString();
1505 if (eventType.contains(Messages.TmfUml2SDSyncCloader_EventTypeSend) || eventType.contains(Messages.TmfUml2SDSyncCloader_EventTypeReceive)) {
1506 Object sender = tmfEvent.getContent().getField(Messages.TmfUml2SDSyncCloader_FieldSender);
1507 Object receiver = tmfEvent.getContent().getField(Messages.TmfUml2SDSyncCloader_FieldReceiver);
1508 Object name = tmfEvent.getContent().getField(Messages.TmfUml2SDSyncCloader_FieldSignal);
1509 if ((sender instanceof ITmfEventField) && (receiver instanceof ITmfEventField) && (name instanceof ITmfEventField)) {
1510 ITmfSyncSequenceDiagramEvent sdEvent = new TmfSyncSequenceDiagramEvent(tmfEvent,
1511 ((ITmfEventField) sender).getValue().toString(),
1512 ((ITmfEventField) receiver).getValue().toString(),
1513 ((ITmfEventField) name).getValue().toString());
1514
1515 return sdEvent;
1516 }
1517 }
1518 return null;
1519 }
1520 }
This page took 0.062608 seconds and 6 git commands to generate.