1 /**********************************************************************
2 * Copyright (c) 2011, 2012 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.loader
;
14 import java
.util
.ArrayList
;
15 import java
.util
.HashMap
;
16 import java
.util
.List
;
17 import java
.util
.concurrent
.CopyOnWriteArrayList
;
18 import java
.util
.concurrent
.locks
.ReentrantLock
;
20 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
21 import org
.eclipse
.core
.runtime
.IStatus
;
22 import org
.eclipse
.core
.runtime
.Status
;
23 import org
.eclipse
.core
.runtime
.jobs
.Job
;
24 import org
.eclipse
.jface
.viewers
.ISelection
;
25 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
26 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.TmfUiPlugin
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.component
.TmfComponent
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.experiment
.TmfExperiment
;
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
.uml2sd
.ITmfSyncSequenceDiagramEvent
;
45 import org
.eclipse
.linuxtools
.tmf
.core
.uml2sd
.TmfSyncSequenceDiagramEvent
;
46 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.SDView
;
47 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Frame
;
48 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
49 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Lifeline
;
50 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.Criteria
;
51 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.FilterCriteria
;
52 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.FilterListDialog
;
53 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDAdvancedPagingProvider
;
54 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDFilterProvider
;
55 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDFindProvider
;
56 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDGraphNodeSupporter
;
57 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.load
.IUml2SDLoader
;
58 import org
.eclipse
.swt
.widgets
.Display
;
59 import org
.eclipse
.ui
.ISelectionListener
;
60 import org
.eclipse
.ui
.IWorkbenchPart
;
61 import org
.eclipse
.ui
.PlatformUI
;
62 import org
.eclipse
.ui
.progress
.IProgressConstants
;
66 * This class is a reference implementation of the <code>org.eclipse.linuxtools.tmf.ui.Uml2SDLoader</code> extension point. It provides
67 * a Sequence Diagram loader for a user space trace with specific trace content for sending and
68 * receiving signals between components. I also includes a default implementation for the <code>ITmfEvent</code> parsing.
71 * The class <code>TmfUml2SDSyncLoader</code> analyzes events from type <code>ITmfEvent</code> and creates events type
72 * <code>ITmfSyncSequenceDiagramEvent</code> if the <code>ITmfEvent</code> contains all relevant information.
73 * The analysis checks that the event type strings contains either string SEND or RECEIVE. If event type matches these key
74 * words, the analyzer will look for strings sender, receiver and signal in the event fields of type <code>ITmfEventField</code>.
75 * If all the data is found a sequence diagram event from can be created. Note that Sync Messages are assumed, which
76 * means start and end time are the same. <br>
78 * The parsing of the <code>ITmfEvent</code> is done in the method <code>getSequnceDiagramEvent()</code> of class
79 * <code>TmfUml2SDSyncLoader</code>. By extending the class <code>TmfUml2SDSyncLoader</code> and overwriting
80 * <code>getSequnceDiagramEvent()</code> a customized parsing algorithm can be implemented.<br>
82 * Note that combined traces of multiple components, that contain the trace information about the same interactions are not
83 * supported in the class <code>TmfUml2SDSyncLoader</code>.
86 * @author Bernd Hufmann
88 public class TmfUml2SDSyncLoader
extends TmfComponent
implements IUml2SDLoader
, ISDFindProvider
, ISDFilterProvider
, ISDAdvancedPagingProvider
, ISelectionListener
{
90 // ------------------------------------------------------------------------
92 // ------------------------------------------------------------------------
96 protected final static String TITLE
= Messages
.TmfUml2SDSyncLoader_ViewName
;
98 * Default block size for background request.
100 protected final static int DEFAULT_BLOCK_SIZE
= 50000;
102 * Maximum number of messages per page.
104 protected final static int MAX_NUM_OF_MSG
= 10000;
106 * Initial time range window.
108 protected final static long INITIAL_WINDOW_OFFSET
= (1L * 100 * 1000 * 1000); // .1sec
110 // ------------------------------------------------------------------------
112 // ------------------------------------------------------------------------
114 // Experiment attributes
116 * The TMF experiment reference.
118 protected TmfExperiment
<ITmfEvent
> fExperiment
= null;
120 * The current indexing event request.
122 protected ITmfEventRequest
<ITmfEvent
> fIndexRequest
= null;
124 * The current request to fill a page.
126 protected ITmfEventRequest
<ITmfEvent
> fPageRequest
= null;
128 * Flag whether the time range signal was sent by this loader class or not
130 volatile protected boolean fIsSignalSent
= false;
132 * The initial request window size.
134 volatile protected long fInitialWindow
= INITIAL_WINDOW_OFFSET
;
136 // The view and event attributes
138 * The sequence diagram view reference.
140 protected SDView fView
= null;
142 * The current sequence diagram frame reference.
144 protected Frame fFrame
= null;
146 * The list of sequence diagram events of current page.
148 protected List
<ITmfSyncSequenceDiagramEvent
> fEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>();
150 // Checkpoint and page attributes
152 * The checkpoints of the whole sequence diagram trace (i.e. start time stamp of each page)
154 protected List
<TmfTimeRange
> fCheckPoints
= new ArrayList
<TmfTimeRange
>(MAX_NUM_OF_MSG
);
156 * The current page displayed.
158 volatile protected int fCurrentPage
= 0;
160 * The current time selected.
162 protected ITmfTimestamp fCurrentTime
= null;
164 * Flag to specify that selection of message is done by selection or by signal.
166 volatile protected boolean fIsSelect
= false;
170 * The job for searching across pages.
172 protected SearchJob fFindJob
= null;
174 * List of found nodes within a page.
176 protected List
<GraphNode
> fFindResults
= new ArrayList
<GraphNode
>();
178 * The current find criteria reference
180 protected Criteria fFindCriteria
= null;
182 * The current find index within the list of found nodes (<code>fFindeResults</code> within a page.
184 volatile protected int fCurrentFindIndex
= 0;
188 * The list of active filters.
190 protected List
<FilterCriteria
> fFilterCriteria
= null;
192 // Thread synchronization
194 * The synchronization lock.
196 protected ReentrantLock fLock
= new ReentrantLock();
198 // ------------------------------------------------------------------------
200 // ------------------------------------------------------------------------
202 * Default constructor
204 public TmfUml2SDSyncLoader() {
211 * @param name Name of loader
213 public TmfUml2SDSyncLoader(String name
) {
217 // ------------------------------------------------------------------------
219 // ------------------------------------------------------------------------
221 * Returns the current time if available else null.
223 * @return the current time if available else null
225 public ITmfTimestamp
getCurrentTime() {
228 if (fCurrentTime
!= null) {
229 return fCurrentTime
.clone();
238 * Waits for the page request to be completed
240 public void waitForCompletion() {
242 ITmfEventRequest
<ITmfEvent
> request
= fPageRequest
;
246 request
.waitForCompletion();
247 } catch (InterruptedException e
) {
253 * Signal handler for the experiment selected signal.
255 * Spawns a request to index the experiment (checkpoints creation) as well as it fills
258 * @param signal The experiment selected signal
260 @SuppressWarnings("unchecked")
262 public void experimentSelected(TmfExperimentSelectedSignal
<ITmfEvent
> signal
) {
264 final Job job
= new Job("Indexing " + getName() + "...") { //$NON-NLS-1$ //$NON-NLS-2$
266 protected IStatus
run(IProgressMonitor monitor
) {
267 while (!monitor
.isCanceled()) {
270 } catch (InterruptedException e
) {
271 return Status
.OK_STATUS
;
275 return Status
.OK_STATUS
;
283 // Update the trace reference
284 TmfExperiment
<ITmfEvent
> exp
= (TmfExperiment
<ITmfEvent
>) signal
.getExperiment();
285 if (!exp
.equals(fExperiment
)) {
289 TmfTimeRange window
= TmfTimeRange
.ETERNITY
;
291 fIndexRequest
= new TmfEventRequest
<ITmfEvent
>(ITmfEvent
.class, window
, TmfDataRequest
.ALL_DATA
, DEFAULT_BLOCK_SIZE
, ITmfDataRequest
.ExecutionType
.BACKGROUND
) {
293 private ITmfTimestamp fFirstTime
= null;
294 private ITmfTimestamp fLastTime
= null;
295 private int fNbSeqEvents
= 0;
296 private final List
<ITmfSyncSequenceDiagramEvent
> fSdEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>(MAX_NUM_OF_MSG
);
300 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
303 public void handleData(ITmfEvent event
) {
304 super.handleData(event
);
306 ITmfSyncSequenceDiagramEvent sdEvent
= getSequnceDiagramEvent(event
);
308 if (sdEvent
!= null) {
311 if (fFirstTime
== null) {
312 fFirstTime
= event
.getTimestamp().clone();
315 fLastTime
= event
.getTimestamp().clone();
317 if ((fNbSeqEvents
% MAX_NUM_OF_MSG
) == 0) {
320 fCheckPoints
.add(new TmfTimeRange(fFirstTime
, fLastTime
));
322 fView
.updateCoolBar();
331 if (fNbSeqEvents
> MAX_NUM_OF_MSG
) {
336 fSdEvents
.add(sdEvent
);
338 if (fNbSeqEvents
== MAX_NUM_OF_MSG
) {
339 fillCurrentPage(fSdEvents
);
346 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleSuccess()
349 public void handleSuccess() {
350 if ((fFirstTime
!= null) && (fLastTime
!= null)) {
354 fCheckPoints
.add(new TmfTimeRange(fFirstTime
, fLastTime
));
356 fView
.updateCoolBar();
363 if (fNbSeqEvents
<= MAX_NUM_OF_MSG
) {
364 fillCurrentPage(fSdEvents
);
367 super.handleSuccess();
372 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleCompleted()
375 public void handleCompleted() {
376 if (fEvents
.size() == 0) {
377 fFrame
= new Frame();
378 fView
.setFrameSync(fFrame
);
380 super.handleCompleted();
385 fExperiment
.sendRequest(fIndexRequest
);
393 * Signal handler for the experiment disposed signal.
395 * @param signal The experiment disposed signal
398 public void experimentDisposed(TmfExperimentDisposedSignal
<ITmfEvent
> signal
) {
399 if (signal
.getExperiment() != TmfExperiment
.getCurrentExperiment()) {
404 if ((fIndexRequest
!= null) && !fIndexRequest
.isCompleted()) {
405 fIndexRequest
.cancel();
406 fIndexRequest
= null;
409 cancelOngoingRequests();
411 if (fFilterCriteria
!= null) {
412 fFilterCriteria
.clear();
415 FilterListDialog
.deactivateSavedGlobalFilters();
424 * Moves to the page that contains the time provided by the signal. The messages will be selected
425 * if the provided time is the time of a message.
427 * @param signal The Time synch signal.
430 public void synchToTime(TmfTimeSynchSignal signal
) {
433 if ((signal
.getSource() != this) && (fFrame
!= null)) {
435 fCurrentTime
= signal
.getCurrentTime();
445 * Moves to the page that contains the current time provided by signal.
446 * No message will be selected however the focus will be set to the message
447 * if the provided time is the time of a message.
449 * @param signal The time range sync signal
452 public void synchToTimeRange(TmfRangeSynchSignal signal
) {
455 if ((signal
.getSource() != this) && (fFrame
!= null) && !fIsSignalSent
) {
456 TmfTimeRange newTimeRange
= signal
.getCurrentRange();
457 ITmfTimestamp delta
= newTimeRange
.getEndTime().getDelta(newTimeRange
.getStartTime());
458 fInitialWindow
= delta
.getValue();
461 fCurrentTime
= newTimeRange
.getStartTime();
473 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#setViewer(org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView)
475 @SuppressWarnings("unchecked")
477 public void setViewer(SDView viewer
) {
482 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
483 fView
.setSDFindProvider(this);
484 fView
.setSDPagingProvider(this);
485 fView
.setSDFilterProvider(this);
489 fExperiment
= (TmfExperiment
<ITmfEvent
>) TmfExperiment
.getCurrentExperiment();
490 if (fExperiment
!= null) {
491 experimentSelected(new TmfExperimentSelectedSignal
<ITmfEvent
>(this, fExperiment
));
500 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#getTitleString()
503 public String
getTitleString() {
509 * @see org.eclipse.linuxtools.tmf.component.TmfComponent#dispose()
512 public void dispose() {
516 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().removePostSelectionListener(this);
517 fView
.setSDFindProvider(null);
518 fView
.setSDPagingProvider(null);
519 fView
.setSDFilterProvider(null);
528 * @see org.eclipse.hyades.uml2sd.ui.actions.provider.ISDGraphNodeSupporter#isNodeSupported(int)
531 public boolean isNodeSupported(int nodeType
) {
533 case ISDGraphNodeSupporter
.LIFELINE
:
534 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
545 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter#getNodeName(int, java.lang.String)
548 public String
getNodeName(int nodeType
, String loaderClassName
) {
550 case ISDGraphNodeSupporter
.LIFELINE
:
551 return Messages
.TmfUml2SDSyncLoader_CategoryLifeline
;
552 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
553 return Messages
.TmfUml2SDSyncLoader_CategoryMessage
;
555 return ""; //$NON-NLS-1$
560 * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
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()));
577 * org.eclipse.hyades.uml2sd.ui.actions.provider.ISDFindProvider#find(org.eclipse.hyades.uml2sd.ui.actions.widgets.Criteria)
580 public boolean find(Criteria toSearch
) {
583 if (fFrame
== null) {
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
));
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
));
607 if (msgs
.size() > 0) {
608 fFindResults
.addAll(msgs
);
611 @SuppressWarnings("rawtypes")
612 List selection
= fView
.getSDWidget().getSelection();
613 if ((selection
!= null) && (selection
.size() == 1)) {
614 fCurrentFindIndex
= fFindResults
.indexOf(selection
.get(0)) + 1;
616 fCurrentFindIndex
= 0;
622 if (fFindResults
.size() > fCurrentFindIndex
) {
623 GraphNode current
= fFindResults
.get(fCurrentFindIndex
);
624 fView
.getSDWidget().moveTo(current
);
628 fCurrentFindIndex
=0;
629 return findInNextPages(fFindCriteria
); // search in other page
638 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFindProvider#cancel()
641 public void cancel() {
642 cancelOngoingRequests();
647 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFilterProvider#filter(java.util.List)
649 @SuppressWarnings("unchecked")
651 public boolean filter(List
<?
> filters
) {
654 cancelOngoingRequests();
656 List
<FilterCriteria
> list
= (List
<FilterCriteria
>)filters
;
657 fFilterCriteria
= new ArrayList
<FilterCriteria
>(list
);
659 fillCurrentPage(fEvents
);
669 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasNextPage()
672 public boolean hasNextPage() {
675 int size
= fCheckPoints
.size();
677 return fCurrentPage
< (size
- 1);
687 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasPrevPage()
690 public boolean hasPrevPage() {
693 return fCurrentPage
> 0;
701 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#nextPage()
704 public void nextPage() {
708 if (fCurrentPage
>= (fCheckPoints
.size() - 1)) {
712 cancelOngoingRequests();
723 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#prevPage()
726 public void prevPage() {
730 if (fCurrentPage
<= 0) {
734 cancelOngoingRequests();
745 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#firstPage()
748 public void firstPage() {
752 cancelOngoingRequests();
763 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#lastPage()
766 public void lastPage() {
769 cancelOngoingRequests();
771 fCurrentPage
= fCheckPoints
.size() - 1;
780 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#currentPage()
783 public int currentPage() {
794 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pagesCount()
797 public int pagesCount() {
800 return fCheckPoints
.size();
808 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pageNumberChanged(int)
811 public void pageNumberChanged(int pageNumber
) {
814 cancelOngoingRequests();
816 if (pageNumber
< 0) {
819 int size
= fCheckPoints
.size();
820 if (pageNumber
> (size
- 1)) {
821 pageNumber
= size
- 1;
823 fCurrentPage
= pageNumber
;
832 * @see org.eclipse.linuxtools.tmf.component.TmfComponent#broadcast(org.eclipse.linuxtools.tmf.signal.TmfSignal)
835 public void broadcast(TmfSignal signal
) {
836 fIsSignalSent
= true;
837 super.broadcast(signal
);
838 fIsSignalSent
= false;
842 * Cancels any ongoing find operation
844 protected void cancelOngoingRequests() {
847 // Cancel the search thread
848 if (fFindJob
!= null) {
853 fFindCriteria
= null;
854 fCurrentFindIndex
= 0;
856 if ((fPageRequest
!= null) && !fPageRequest
.isCompleted()) {
857 fPageRequest
.cancel();
866 * Resets loader attributes
868 protected void resetLoader() {
873 fCheckPoints
.clear();
875 fCurrentFindIndex
= 0;
876 fFindCriteria
= null;
878 fInitialWindow
= INITIAL_WINDOW_OFFSET
;
879 fView
.setFrameSync(new Frame());
889 * Fills current page with sequence diagram content.
891 * @param events sequence diagram events
893 protected void fillCurrentPage(List
<ITmfSyncSequenceDiagramEvent
> events
) {
897 fEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>(events
);
899 fView
.toggleWaitCursorAsync(true);
905 final Frame frame
= new Frame();
907 if (events
.size() > 0) {
908 HashMap
<String
, Lifeline
> nodeToLifelineMap
= new HashMap
<String
, Lifeline
>();
910 frame
.setName(Messages
.TmfUml2SDSyncLoader_FrameName
);
912 for (int i
= 0; i
< events
.size(); i
++) {
914 ITmfSyncSequenceDiagramEvent sdEvent
= events
.get(i
);
916 if ((nodeToLifelineMap
.get(sdEvent
.getSender()) == null) && (!filterLifeLine(sdEvent
.getSender()))) {
917 Lifeline lifeline
= new Lifeline();
918 lifeline
.setName(sdEvent
.getSender());
919 nodeToLifelineMap
.put(sdEvent
.getSender(), lifeline
);
920 frame
.addLifeLine(lifeline
);
923 if ((nodeToLifelineMap
.get(sdEvent
.getReceiver()) == null) && (!filterLifeLine(sdEvent
.getReceiver()))) {
924 Lifeline lifeline
= new Lifeline();
925 lifeline
.setName(sdEvent
.getReceiver());
926 nodeToLifelineMap
.put(sdEvent
.getReceiver(), lifeline
);
927 frame
.addLifeLine(lifeline
);
931 int eventOccurence
= 1;
933 for (int i
= 0; i
< events
.size(); i
++) {
934 ITmfSyncSequenceDiagramEvent sdEvent
= events
.get(i
);
936 // Check message filter
937 if (filterMessage(sdEvent
)) {
941 // Set the message sender and receiver
942 Lifeline startLifeline
= nodeToLifelineMap
.get(sdEvent
.getSender());
943 Lifeline endLifeline
= nodeToLifelineMap
.get(sdEvent
.getReceiver());
945 // Check if any of the lifelines were filtered
946 if ((startLifeline
== null) || (endLifeline
== null)) {
950 int tmp
= Math
.max(startLifeline
.getEventOccurrence(), endLifeline
.getEventOccurrence());
951 eventOccurence
= Math
.max(eventOccurence
, tmp
);
953 startLifeline
.setCurrentEventOccurrence(eventOccurence
);
954 endLifeline
.setCurrentEventOccurrence(eventOccurence
);
956 TmfSyncMessage message
= new TmfSyncMessage(sdEvent
, eventOccurence
++);
958 message
.setStartLifeline(startLifeline
);
959 message
.setEndLifeline(endLifeline
);
961 message
.setTime(sdEvent
.getStartTime());
963 // add the message to the frame
964 frame
.addMessage(message
);
969 if (!fView
.getSDWidget().isDisposed()) {
970 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
977 // check if view was disposed in the meanwhile
978 if ((fView
!= null) && (!fView
.getSDWidget().isDisposed())) {
980 fView
.setFrame(fFrame
);
982 if (fCurrentTime
!= null) {
983 moveToMessageInPage();
986 if (fFindCriteria
!= null) {
990 fView
.toggleWaitCursorAsync(false);
1007 * Moves to a certain message defined by timestamp (across pages)
1009 protected void moveToMessage() {
1014 page
= getPage(fCurrentTime
);
1016 if (page
== fCurrentPage
) {
1017 moveToMessageInPage();
1020 fCurrentPage
= page
;
1028 * Moves to a certain message defined by timestamp in current page
1030 protected void moveToMessageInPage() {
1033 if (!fView
.getSDWidget().isDisposed()) {
1034 // Check for GUI thread
1035 if(Display
.getCurrent() != null) {
1036 // Already in GUI thread - execute directly
1037 TmfSyncMessage prevMessage
= null;
1038 TmfSyncMessage syncMessage
= null;
1039 boolean isExactTime
= false;
1040 for (int i
= 0; i
< fFrame
.syncMessageCount(); i
++) {
1041 if (fFrame
.getSyncMessage(i
) instanceof TmfSyncMessage
) {
1042 syncMessage
= (TmfSyncMessage
) fFrame
.getSyncMessage(i
);
1043 if (syncMessage
.getStartTime().compareTo(fCurrentTime
, false) == 0) {
1047 else if (syncMessage
.getStartTime().compareTo(fCurrentTime
, false) > 0) {
1048 if (prevMessage
!= null) {
1049 syncMessage
= prevMessage
;
1053 prevMessage
= syncMessage
;
1056 if (fIsSelect
&& isExactTime
) {
1057 fView
.getSDWidget().moveTo(syncMessage
);
1060 fView
.getSDWidget().ensureVisible(syncMessage
);
1061 fView
.getSDWidget().clearSelection();
1062 fView
.getSDWidget().redraw();
1066 // Not in GUI thread - queue action in GUI thread.
1067 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1070 moveToMessageInPage();
1082 * Moves to a certain message defined by timestamp (across pages)
1084 protected void moveToPage() {
1089 * Moves to a certain page.
1091 * @param notifyAll true to broadcast time range signal to other signal handlers else false
1093 protected void moveToPage(boolean notifyAll
) {
1095 TmfTimeRange window
= TmfTimeRange
.ETERNITY
;
1100 if (fCurrentPage
> fCheckPoints
.size()) {
1103 window
= fCheckPoints
.get(fCurrentPage
);
1108 fPageRequest
= new TmfEventRequest
<ITmfEvent
>(ITmfEvent
.class, window
, TmfDataRequest
.ALL_DATA
, 1, ITmfDataRequest
.ExecutionType
.FOREGROUND
) {
1109 private final List
<ITmfSyncSequenceDiagramEvent
> fSdEvent
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>();
1112 public void handleData(ITmfEvent event
) {
1113 super.handleData(event
);
1115 ITmfSyncSequenceDiagramEvent sdEvent
= getSequnceDiagramEvent(event
);
1117 if (sdEvent
!= null) {
1118 fSdEvent
.add(sdEvent
);
1123 public void handleSuccess() {
1124 fillCurrentPage(fSdEvent
);
1125 super.handleSuccess();
1130 fExperiment
.sendRequest(fPageRequest
);
1133 TmfTimeRange timeRange
= getSignalTimeRange(window
.getStartTime());
1134 broadcast(new TmfRangeSynchSignal(this, timeRange
, timeRange
.getStartTime()));
1139 * Gets page that contains timestamp
1141 * @param time The timestamp
1142 * @return page that contains the time
1144 protected int getPage(ITmfTimestamp time
) {
1149 size
= fCheckPoints
.size();
1150 for (page
= 0; page
< size
; page
++) {
1151 TmfTimeRange timeRange
= fCheckPoints
.get(page
);
1152 if (timeRange
.getEndTime().compareTo(time
, false) >= 0) {
1166 * Background search in trace for expression in criteria.
1168 * @param findCriteria The find criteria
1169 * @return true if background request was started else false
1171 protected boolean findInNextPages(Criteria findCriteria
) {
1174 if (fFindJob
!= null) {
1178 int nextPage
= fCurrentPage
+ 1;
1180 if ((nextPage
) >= fCheckPoints
.size()) {
1181 // we are at the end
1185 TmfTimeRange window
= new TmfTimeRange(fCheckPoints
.get(nextPage
).getStartTime().clone(), fCheckPoints
.get(fCheckPoints
.size()-1).getEndTime().clone());
1186 fFindJob
= new SearchJob(findCriteria
, window
);
1187 fFindJob
.schedule();
1188 fView
.toggleWaitCursorAsync(true);
1196 * Gets time range for time range signal.
1198 * @param startTime The start time of time range.
1199 * @return the time range
1201 protected TmfTimeRange
getSignalTimeRange(ITmfTimestamp startTime
) {
1204 TmfTimestamp initialEndOfWindow
= new TmfTimestamp(startTime
.getValue() + fInitialWindow
, startTime
.getScale(), startTime
.getPrecision());
1205 return new TmfTimeRange(startTime
, initialEndOfWindow
);
1213 * Checks if filter criteria matches the message name in given SD event.
1215 * @param sdEvent The SD event to check
1216 * @return true if match else false.
1218 protected boolean filterMessage(ITmfSyncSequenceDiagramEvent sdEvent
) {
1221 if (fFilterCriteria
!= null) {
1222 for(FilterCriteria criteria
: fFilterCriteria
) {
1223 if (criteria
.isActive() && criteria
.getCriteria().isSyncMessageSelected() ) {
1225 if(criteria
.getCriteria().matches(sdEvent
.getName())) {
1238 * Checks if filter criteria matches a lifeline name (sender or receiver) in given SD event.
1240 * @param lifeline the message receiver
1241 * @return true if match else false.
1243 protected boolean filterLifeLine(String lifeline
) {
1246 if (fFilterCriteria
!= null) {
1247 for(FilterCriteria criteria
: fFilterCriteria
) {
1248 if (criteria
.isActive() && criteria
.getCriteria().isLifeLineSelected()) {
1250 if(criteria
.getCriteria().matches(lifeline
)) {
1263 * Job to search in trace for given time range.
1265 protected class SearchJob
extends Job
{
1268 * The search event request.
1270 final protected SearchEventRequest fSearchRequest
;
1275 * @param findCriteria The search criteria
1276 * @param window Time range to search in
1278 public SearchJob(Criteria findCriteria
, TmfTimeRange window
) {
1279 super(Messages
.TmfUml2SDSyncLoader_SearchJobDescrition
);
1280 fSearchRequest
= new SearchEventRequest(window
, TmfDataRequest
.ALL_DATA
, 1, ITmfDataRequest
.ExecutionType
.FOREGROUND
, findCriteria
);
1285 * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
1288 protected IStatus
run(IProgressMonitor monitor
) {
1289 fSearchRequest
.setMonitor(monitor
);
1291 fExperiment
.sendRequest(fSearchRequest
);
1294 fSearchRequest
.waitForCompletion();
1295 } catch (InterruptedException e
) {
1296 e
.printStackTrace();
1299 IStatus status
= Status
.OK_STATUS
;
1300 if (fSearchRequest
.isFound() && (fSearchRequest
.getFoundTime() != null)) {
1301 fCurrentTime
= fSearchRequest
.getFoundTime();
1303 // Avoid double-selection. Selection will be done when calling find(criteria)
1304 // after moving to relevant page
1306 if (!fView
.getSDWidget().isDisposed()) {
1307 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1317 if (monitor
.isCanceled()) {
1318 status
= Status
.CANCEL_STATUS
;
1321 // String was not found
1322 status
= new Status(Status
.WARNING
, TmfUiPlugin
.PLUGIN_ID
, Messages
.TmfUml2SDSyncLoader_SearchNotFound
);
1324 setProperty(IProgressConstants
.KEEP_PROPERTY
, Boolean
.TRUE
);
1330 fView
.toggleWaitCursorAsync(false);
1341 * @see org.eclipse.core.runtime.jobs.Job#canceling()
1344 protected void canceling() {
1345 fSearchRequest
.cancel();
1356 * TMF event request for searching within trace.
1358 protected class SearchEventRequest
extends TmfEventRequest
<ITmfEvent
> {
1361 * The find criteria.
1363 final private Criteria fCriteria
;
1365 * A progress monitor
1367 private IProgressMonitor fMonitor
;
1369 * Flag to indicate that node was found according the criteria .
1371 private boolean fIsFound
= false;
1373 * Time stamp of found item.
1375 private ITmfTimestamp fFoundTime
= null;
1379 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1380 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1381 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1382 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1383 * @param criteria The search criteria
1385 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType execType
, Criteria criteria
) {
1386 this(range
, nbRequested
, blockSize
, execType
, criteria
, null);
1391 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1392 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1393 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1394 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1395 * @param criteria The search criteria
1396 * @param monitor progress monitor
1398 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType execType
, Criteria criteria
, IProgressMonitor monitor
) {
1399 super(ITmfEvent
.class, range
, nbRequested
, blockSize
, execType
);
1400 fCriteria
= new Criteria(criteria
);
1406 * @see org.eclipse.linuxtools.tmf.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.event.TmfData)
1409 public void handleData(ITmfEvent event
) {
1410 super.handleData(event
);
1412 if ((fMonitor
!= null) && fMonitor
.isCanceled()) {
1417 ITmfSyncSequenceDiagramEvent sdEvent
= getSequnceDiagramEvent(event
);
1419 if (sdEvent
!= null) {
1421 if (fCriteria
.isLifeLineSelected()) {
1422 if (fCriteria
.matches(sdEvent
.getSender())) {
1423 fFoundTime
= event
.getTimestamp().clone();
1428 if (fCriteria
.matches(sdEvent
.getReceiver())) {
1429 fFoundTime
= event
.getTimestamp().clone();
1435 if (fCriteria
.isSyncMessageSelected()) {
1436 if (fCriteria
.matches(sdEvent
.getName())) {
1437 fFoundTime
= event
.getTimestamp().clone();
1447 * @see org.eclipse.linuxtools.tmf.request.TmfDataRequest#handleCompleted()
1450 public void handleCompleted() {
1451 super.handleCompleted();
1455 * Set progress monitor.
1459 public void setMonitor(IProgressMonitor monitor
) {
1464 * Check if find criteria was met.
1466 * @return true if find criteria was met.
1468 public boolean isFound() {
1473 * Returns timestamp of found time.
1475 * @return timestamp of found time.
1477 public ITmfTimestamp
getFoundTime() {
1483 * Returns sequence diagram event if details in given event are available else null.
1485 * @param tmfEvent Event to parse for sequence diagram event details
1486 * @return sequence diagram event if details are available else null
1488 protected ITmfSyncSequenceDiagramEvent
getSequnceDiagramEvent(ITmfEvent tmfEvent
){
1489 //type = .*RECEIVE.* or .*SEND.*
1490 //content = sender:<sender name>:receiver:<receiver name>,signal:<signal name>
1491 String eventType
= tmfEvent
.getType().toString();
1492 if (eventType
.contains(Messages
.TmfUml2SDSyncCloader_EventTypeSend
) || eventType
.contains(Messages
.TmfUml2SDSyncCloader_EventTypeReceive
)) {
1493 Object sender
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncCloader_FieldSender
);
1494 Object receiver
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncCloader_FieldReceiver
);
1495 Object name
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncCloader_FieldSignal
);
1496 if ((sender
instanceof ITmfEventField
) && (receiver
instanceof ITmfEventField
) && (name
instanceof ITmfEventField
)) {
1497 ITmfSyncSequenceDiagramEvent sdEvent
= new TmfSyncSequenceDiagramEvent(tmfEvent
,
1498 ((ITmfEventField
) sender
).getValue().toString(),
1499 ((ITmfEventField
) receiver
).getValue().toString(),
1500 ((ITmfEventField
) name
).getValue().toString());