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
;
18 import java
.util
.concurrent
.CopyOnWriteArrayList
;
19 import java
.util
.concurrent
.locks
.ReentrantLock
;
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
;
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.
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>
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
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>.
96 * @author Bernd Hufmann
98 public class TmfUml2SDSyncLoader
extends TmfComponent
implements IUml2SDLoader
, ISDFindProvider
, ISDFilterProvider
, ISDAdvancedPagingProvider
, ISelectionListener
{
100 // ------------------------------------------------------------------------
102 // ------------------------------------------------------------------------
104 * Default title name.
106 protected final static String TITLE
= Messages
.TmfUml2SDSyncLoader_ViewName
;
108 * Default block size for background request.
110 protected final static int DEFAULT_BLOCK_SIZE
= 50000;
112 * Maximum number of messages per page.
114 protected final static int MAX_NUM_OF_MSG
= 10000;
116 * Initial time range window.
118 protected final static long INITIAL_WINDOW_OFFSET
= (1L * 100 * 1000 * 1000); // .1sec
120 // ------------------------------------------------------------------------
122 // ------------------------------------------------------------------------
124 // Experiment attributes
126 * The TMF experiment reference.
128 protected TmfExperiment
<ITmfEvent
> fExperiment
= null;
130 * The current indexing event request.
132 protected ITmfEventRequest
<ITmfEvent
> fIndexRequest
= null;
134 * The current request to fill a page.
136 protected ITmfEventRequest
<ITmfEvent
> fPageRequest
= null;
138 * Flag whether the time range signal was sent by this loader class or not
140 volatile protected boolean fIsSignalSent
= false;
142 * The initial request window size.
144 volatile protected long fInitialWindow
= INITIAL_WINDOW_OFFSET
;
146 // The view and event attributes
148 * The sequence diagram view reference.
150 protected SDView fView
= null;
152 * The current sequence diagram frame reference.
154 protected Frame fFrame
= null;
156 * The list of sequence diagram events of current page.
158 protected List
<ITmfSyncSequenceDiagramEvent
> fEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>();
160 // Checkpoint and page attributes
162 * The checkpoints of the whole sequence diagram trace (i.e. start time stamp of each page)
164 protected List
<TmfTimeRange
> fCheckPoints
= new ArrayList
<TmfTimeRange
>(MAX_NUM_OF_MSG
);
166 * The current page displayed.
168 volatile protected int fCurrentPage
= 0;
170 * The current time selected.
172 protected ITmfTimestamp fCurrentTime
= null;
174 * Flag to specify that selection of message is done by selection or by signal.
176 volatile protected boolean fIsSelect
= false;
180 * The job for searching across pages.
182 protected SearchJob fFindJob
= null;
184 * List of found nodes within a page.
186 protected List
<GraphNode
> fFindResults
= new ArrayList
<GraphNode
>();
188 * The current find criteria reference
190 protected Criteria fFindCriteria
= null;
192 * The current find index within the list of found nodes (<code>fFindeResults</code> within a page.
194 volatile protected int fCurrentFindIndex
= 0;
198 * The list of active filters.
200 protected List
<FilterCriteria
> fFilterCriteria
= null;
202 // Thread synchronization
204 * The synchronization lock.
206 protected ReentrantLock fLock
= new ReentrantLock();
208 // ------------------------------------------------------------------------
210 // ------------------------------------------------------------------------
212 * Default constructor
214 public TmfUml2SDSyncLoader() {
221 * @param name Name of loader
223 public TmfUml2SDSyncLoader(String name
) {
227 // ------------------------------------------------------------------------
229 // ------------------------------------------------------------------------
231 * Returns the current time if available else null.
233 * @return the current time if available else null
235 public ITmfTimestamp
getCurrentTime() {
238 if (fCurrentTime
!= null) {
239 return fCurrentTime
.clone();
248 * Waits for the page request to be completed
250 public void waitForCompletion() {
252 ITmfEventRequest
<ITmfEvent
> request
= fPageRequest
;
254 if (request
!= null) {
256 request
.waitForCompletion();
257 } catch (InterruptedException e
) {
264 * Signal handler for the experiment selected signal.
266 * Spawns a request to index the experiment (checkpoints creation) as well as it fills
269 * @param signal The experiment selected signal
272 public void experimentSelected(TmfExperimentSelectedSignal
<ITmfEvent
> signal
) {
274 final Job job
= new IndexingJob("Indexing " + getName() + "..."); //$NON-NLS-1$ //$NON-NLS-2$
280 // Update the trace reference
281 TmfExperiment
<ITmfEvent
> exp
= (TmfExperiment
<ITmfEvent
>) signal
.getExperiment();
282 if (!exp
.equals(fExperiment
)) {
286 TmfTimeRange window
= TmfTimeRange
.ETERNITY
;
288 fIndexRequest
= new TmfEventRequest
<ITmfEvent
>(ITmfEvent
.class, window
, TmfDataRequest
.ALL_DATA
, DEFAULT_BLOCK_SIZE
, ITmfDataRequest
.ExecutionType
.BACKGROUND
) {
290 private ITmfTimestamp fFirstTime
= null;
291 private ITmfTimestamp fLastTime
= null;
292 private int fNbSeqEvents
= 0;
293 private final List
<ITmfSyncSequenceDiagramEvent
> fSdEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>(MAX_NUM_OF_MSG
);
297 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
300 public void handleData(ITmfEvent event
) {
301 super.handleData(event
);
303 ITmfSyncSequenceDiagramEvent sdEvent
= getSequnceDiagramEvent(event
);
305 if (sdEvent
!= null) {
308 if (fFirstTime
== null) {
309 fFirstTime
= event
.getTimestamp().clone();
312 fLastTime
= event
.getTimestamp().clone();
314 if ((fNbSeqEvents
% MAX_NUM_OF_MSG
) == 0) {
317 fCheckPoints
.add(new TmfTimeRange(fFirstTime
, fLastTime
));
319 fView
.updateCoolBar();
328 if (fNbSeqEvents
> MAX_NUM_OF_MSG
) {
333 fSdEvents
.add(sdEvent
);
335 if (fNbSeqEvents
== MAX_NUM_OF_MSG
) {
336 fillCurrentPage(fSdEvents
);
343 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleSuccess()
346 public void handleSuccess() {
347 if ((fFirstTime
!= null) && (fLastTime
!= null)) {
351 fCheckPoints
.add(new TmfTimeRange(fFirstTime
, fLastTime
));
353 fView
.updateCoolBar();
360 if (fNbSeqEvents
<= MAX_NUM_OF_MSG
) {
361 fillCurrentPage(fSdEvents
);
364 super.handleSuccess();
369 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleCompleted()
372 public void handleCompleted() {
373 if (fEvents
.isEmpty()) {
374 fFrame
= new Frame();
375 fView
.setFrameSync(fFrame
);
377 super.handleCompleted();
382 fExperiment
.sendRequest(fIndexRequest
);
390 * Signal handler for the experiment disposed signal.
392 * @param signal The experiment disposed signal
395 public void experimentDisposed(TmfExperimentDisposedSignal
<ITmfEvent
> signal
) {
396 if (signal
.getExperiment() != TmfExperiment
.getCurrentExperiment()) {
401 if ((fIndexRequest
!= null) && !fIndexRequest
.isCompleted()) {
402 fIndexRequest
.cancel();
403 fIndexRequest
= null;
406 cancelOngoingRequests();
408 if (fFilterCriteria
!= null) {
409 fFilterCriteria
.clear();
412 FilterListDialog
.deactivateSavedGlobalFilters();
421 * Moves to the page that contains the time provided by the signal. The messages will be selected
422 * if the provided time is the time of a message.
424 * @param signal The Time synch signal.
427 public void synchToTime(TmfTimeSynchSignal signal
) {
430 if ((signal
.getSource() != this) && (fFrame
!= null)) {
432 fCurrentTime
= signal
.getCurrentTime();
442 * Moves to the page that contains the current time provided by signal.
443 * No message will be selected however the focus will be set to the message
444 * if the provided time is the time of a message.
446 * @param signal The time range sync signal
449 public void synchToTimeRange(TmfRangeSynchSignal signal
) {
452 if ((signal
.getSource() != this) && (fFrame
!= null) && !fIsSignalSent
) {
453 TmfTimeRange newTimeRange
= signal
.getCurrentRange();
454 ITmfTimestamp delta
= newTimeRange
.getEndTime().getDelta(newTimeRange
.getStartTime());
455 fInitialWindow
= delta
.getValue();
458 fCurrentTime
= newTimeRange
.getStartTime();
470 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#setViewer(org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView)
473 public void setViewer(SDView viewer
) {
478 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
479 fView
.setSDFindProvider(this);
480 fView
.setSDPagingProvider(this);
481 fView
.setSDFilterProvider(this);
485 fExperiment
= (TmfExperiment
<ITmfEvent
>) TmfExperiment
.getCurrentExperiment();
486 if (fExperiment
!= null) {
487 experimentSelected(new TmfExperimentSelectedSignal
<ITmfEvent
>(this, fExperiment
));
496 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#getTitleString()
499 public String
getTitleString() {
505 * @see org.eclipse.linuxtools.tmf.component.TmfComponent#dispose()
508 public void dispose() {
512 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().removePostSelectionListener(this);
513 fView
.setSDFindProvider(null);
514 fView
.setSDPagingProvider(null);
515 fView
.setSDFilterProvider(null);
524 * @see org.eclipse.hyades.uml2sd.ui.actions.provider.ISDGraphNodeSupporter#isNodeSupported(int)
527 public boolean isNodeSupported(int nodeType
) {
529 case ISDGraphNodeSupporter
.LIFELINE
:
530 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
541 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter#getNodeName(int, java.lang.String)
544 public String
getNodeName(int nodeType
, String loaderClassName
) {
546 case ISDGraphNodeSupporter
.LIFELINE
:
547 return Messages
.TmfUml2SDSyncLoader_CategoryLifeline
;
548 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
549 return Messages
.TmfUml2SDSyncLoader_CategoryMessage
;
553 return ""; //$NON-NLS-1$
558 * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
561 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
562 ISelection sel
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
563 if ((sel
!= null) && (sel
instanceof StructuredSelection
)) {
564 StructuredSelection stSel
= (StructuredSelection
) sel
;
565 if (stSel
.getFirstElement() instanceof TmfSyncMessage
) {
566 TmfSyncMessage syncMsg
= ((TmfSyncMessage
) stSel
.getFirstElement());
567 broadcast(new TmfTimeSynchSignal(this, syncMsg
.getStartTime()));
575 * org.eclipse.hyades.uml2sd.ui.actions.provider.ISDFindProvider#find(org.eclipse.hyades.uml2sd.ui.actions.widgets.Criteria)
578 public boolean find(Criteria toSearch
) {
581 if (fFrame
== null) {
585 if ((fFindResults
== null) || (fFindCriteria
== null) || !fFindCriteria
.compareTo(toSearch
)) {
586 fFindResults
= new CopyOnWriteArrayList
<GraphNode
>();
587 fFindCriteria
= toSearch
;
588 if (fFindCriteria
.isLifeLineSelected()) {
589 for (int i
= 0; i
< fFrame
.lifeLinesCount(); i
++) {
590 if (fFindCriteria
.matches(fFrame
.getLifeline(i
).getName())) {
591 fFindResults
.add(fFrame
.getLifeline(i
));
596 ArrayList
<GraphNode
> msgs
= new ArrayList
<GraphNode
>();
597 if (fFindCriteria
.isSyncMessageSelected()) {
598 for (int i
= 0; i
< fFrame
.syncMessageCount(); i
++) {
599 if (fFindCriteria
.matches(fFrame
.getSyncMessage(i
).getName())) {
600 msgs
.add(fFrame
.getSyncMessage(i
));
605 if (!msgs
.isEmpty()) {
606 fFindResults
.addAll(msgs
);
609 @SuppressWarnings("rawtypes")
610 List selection
= fView
.getSDWidget().getSelection();
611 if ((selection
!= null) && (selection
.size() == 1)) {
612 fCurrentFindIndex
= fFindResults
.indexOf(selection
.get(0)) + 1;
614 fCurrentFindIndex
= 0;
620 if (fFindResults
.size() > fCurrentFindIndex
) {
621 GraphNode current
= fFindResults
.get(fCurrentFindIndex
);
622 fView
.getSDWidget().moveTo(current
);
626 fCurrentFindIndex
=0;
627 return findInNextPages(fFindCriteria
); // search in other page
635 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFindProvider#cancel()
638 public void cancel() {
639 cancelOngoingRequests();
644 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFilterProvider#filter(java.util.List)
646 @SuppressWarnings("unchecked")
648 public boolean filter(List
<?
> filters
) {
651 cancelOngoingRequests();
653 List
<FilterCriteria
> list
= (List
<FilterCriteria
>)filters
;
654 fFilterCriteria
= new ArrayList
<FilterCriteria
>(list
);
656 fillCurrentPage(fEvents
);
666 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasNextPage()
669 public boolean hasNextPage() {
672 int size
= fCheckPoints
.size();
674 return fCurrentPage
< (size
- 1);
684 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasPrevPage()
687 public boolean hasPrevPage() {
690 return fCurrentPage
> 0;
698 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#nextPage()
701 public void nextPage() {
705 if (fCurrentPage
>= (fCheckPoints
.size() - 1)) {
709 cancelOngoingRequests();
720 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#prevPage()
723 public void prevPage() {
727 if (fCurrentPage
<= 0) {
731 cancelOngoingRequests();
742 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#firstPage()
745 public void firstPage() {
749 cancelOngoingRequests();
760 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#lastPage()
763 public void lastPage() {
766 cancelOngoingRequests();
768 fCurrentPage
= fCheckPoints
.size() - 1;
777 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#currentPage()
780 public int currentPage() {
791 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pagesCount()
794 public int pagesCount() {
797 return fCheckPoints
.size();
805 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pageNumberChanged(int)
808 public void pageNumberChanged(int pagenNumber
) {
809 int localPageNumber
= pagenNumber
;
813 cancelOngoingRequests();
815 if (localPageNumber
< 0) {
818 int size
= fCheckPoints
.size();
819 if (localPageNumber
> (size
- 1)) {
820 localPageNumber
= size
- 1;
822 fCurrentPage
= localPageNumber
;
831 * @see org.eclipse.linuxtools.tmf.component.TmfComponent#broadcast(org.eclipse.linuxtools.tmf.signal.TmfSignal)
834 public void broadcast(TmfSignal signal
) {
835 fIsSignalSent
= true;
836 super.broadcast(signal
);
837 fIsSignalSent
= false;
841 * Cancels any ongoing find operation
843 protected void cancelOngoingRequests() {
846 // Cancel the search thread
847 if (fFindJob
!= null) {
852 fFindCriteria
= null;
853 fCurrentFindIndex
= 0;
855 if ((fPageRequest
!= null) && !fPageRequest
.isCompleted()) {
856 fPageRequest
.cancel();
865 * Resets loader attributes
867 protected void resetLoader() {
872 fCheckPoints
.clear();
874 fCurrentFindIndex
= 0;
875 fFindCriteria
= null;
877 fInitialWindow
= INITIAL_WINDOW_OFFSET
;
878 fView
.setFrameSync(new Frame());
888 * Fills current page with sequence diagram content.
890 * @param events sequence diagram events
892 protected void fillCurrentPage(List
<ITmfSyncSequenceDiagramEvent
> events
) {
896 fEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>(events
);
898 fView
.toggleWaitCursorAsync(true);
904 final Frame frame
= new Frame();
906 if (!events
.isEmpty()) {
907 Map
<String
, Lifeline
> nodeToLifelineMap
= new HashMap
<String
, Lifeline
>();
909 frame
.setName(Messages
.TmfUml2SDSyncLoader_FrameName
);
911 for (int i
= 0; i
< events
.size(); i
++) {
913 ITmfSyncSequenceDiagramEvent sdEvent
= events
.get(i
);
915 if ((nodeToLifelineMap
.get(sdEvent
.getSender()) == null) && (!filterLifeLine(sdEvent
.getSender()))) {
916 Lifeline lifeline
= new Lifeline();
917 lifeline
.setName(sdEvent
.getSender());
918 nodeToLifelineMap
.put(sdEvent
.getSender(), lifeline
);
919 frame
.addLifeLine(lifeline
);
922 if ((nodeToLifelineMap
.get(sdEvent
.getReceiver()) == null) && (!filterLifeLine(sdEvent
.getReceiver()))) {
923 Lifeline lifeline
= new Lifeline();
924 lifeline
.setName(sdEvent
.getReceiver());
925 nodeToLifelineMap
.put(sdEvent
.getReceiver(), lifeline
);
926 frame
.addLifeLine(lifeline
);
930 int eventOccurence
= 1;
932 for (int i
= 0; i
< events
.size(); i
++) {
933 ITmfSyncSequenceDiagramEvent sdEvent
= events
.get(i
);
935 // Check message filter
936 if (filterMessage(sdEvent
)) {
940 // Set the message sender and receiver
941 Lifeline startLifeline
= nodeToLifelineMap
.get(sdEvent
.getSender());
942 Lifeline endLifeline
= nodeToLifelineMap
.get(sdEvent
.getReceiver());
944 // Check if any of the lifelines were filtered
945 if ((startLifeline
== null) || (endLifeline
== null)) {
949 int tmp
= Math
.max(startLifeline
.getEventOccurrence(), endLifeline
.getEventOccurrence());
950 eventOccurence
= Math
.max(eventOccurence
, tmp
);
952 startLifeline
.setCurrentEventOccurrence(eventOccurence
);
953 endLifeline
.setCurrentEventOccurrence(eventOccurence
);
955 TmfSyncMessage message
= new TmfSyncMessage(sdEvent
, eventOccurence
++);
957 message
.setStartLifeline(startLifeline
);
958 message
.setEndLifeline(endLifeline
);
960 message
.setTime(sdEvent
.getStartTime());
962 // add the message to the frame
963 frame
.addMessage(message
);
968 if (!fView
.getSDWidget().isDisposed()) {
969 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
976 // check if view was disposed in the meanwhile
977 if ((fView
!= null) && (!fView
.getSDWidget().isDisposed())) {
979 fView
.setFrame(fFrame
);
981 if (fCurrentTime
!= null) {
982 moveToMessageInPage();
985 if (fFindCriteria
!= null) {
989 fView
.toggleWaitCursorAsync(false);
1006 * Moves to a certain message defined by timestamp (across pages)
1008 protected void moveToMessage() {
1013 page
= getPage(fCurrentTime
);
1015 if (page
== fCurrentPage
) {
1016 moveToMessageInPage();
1019 fCurrentPage
= page
;
1027 * Moves to a certain message defined by timestamp in current page
1029 protected void moveToMessageInPage() {
1032 if (!fView
.getSDWidget().isDisposed()) {
1033 // Check for GUI thread
1034 if(Display
.getCurrent() != null) {
1035 // Already in GUI thread - execute directly
1036 TmfSyncMessage prevMessage
= null;
1037 TmfSyncMessage syncMessage
= null;
1038 boolean isExactTime
= false;
1039 for (int i
= 0; i
< fFrame
.syncMessageCount(); i
++) {
1040 if (fFrame
.getSyncMessage(i
) instanceof TmfSyncMessage
) {
1041 syncMessage
= (TmfSyncMessage
) fFrame
.getSyncMessage(i
);
1042 if (syncMessage
.getStartTime().compareTo(fCurrentTime
, false) == 0) {
1045 } else if ((syncMessage
.getStartTime().compareTo(fCurrentTime
, false) > 0) && (prevMessage
!= null)) {
1046 syncMessage
= prevMessage
;
1049 prevMessage
= syncMessage
;
1052 if (fIsSelect
&& isExactTime
) {
1053 fView
.getSDWidget().moveTo(syncMessage
);
1056 fView
.getSDWidget().ensureVisible(syncMessage
);
1057 fView
.getSDWidget().clearSelection();
1058 fView
.getSDWidget().redraw();
1062 // Not in GUI thread - queue action in GUI thread.
1063 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1066 moveToMessageInPage();
1078 * Moves to a certain message defined by timestamp (across pages)
1080 protected void moveToPage() {
1085 * Moves to a certain page.
1087 * @param notifyAll true to broadcast time range signal to other signal handlers else false
1089 protected void moveToPage(boolean notifyAll
) {
1091 TmfTimeRange window
= null;
1096 if (fCurrentPage
> fCheckPoints
.size()) {
1099 window
= fCheckPoints
.get(fCurrentPage
);
1104 if (window
== null) {
1105 window
= TmfTimeRange
.ETERNITY
;
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() && criteria
.getCriteria().matches(sdEvent
.getName())) {
1235 * Checks if filter criteria matches a lifeline name (sender or receiver) in given SD event.
1237 * @param lifeline the message receiver
1238 * @return true if match else false.
1240 protected boolean filterLifeLine(String lifeline
) {
1243 if (fFilterCriteria
!= null) {
1244 for(FilterCriteria criteria
: fFilterCriteria
) {
1245 if (criteria
.isActive() && criteria
.getCriteria().isLifeLineSelected() && criteria
.getCriteria().matches(lifeline
)) {
1257 * Job to search in trace for given time range.
1259 protected class SearchJob
extends Job
{
1262 * The search event request.
1264 final protected SearchEventRequest fSearchRequest
;
1269 * @param findCriteria The search criteria
1270 * @param window Time range to search in
1272 public SearchJob(Criteria findCriteria
, TmfTimeRange window
) {
1273 super(Messages
.TmfUml2SDSyncLoader_SearchJobDescrition
);
1274 fSearchRequest
= new SearchEventRequest(window
, TmfDataRequest
.ALL_DATA
, 1, ITmfDataRequest
.ExecutionType
.FOREGROUND
, findCriteria
);
1279 * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
1282 protected IStatus
run(IProgressMonitor monitor
) {
1283 fSearchRequest
.setMonitor(monitor
);
1285 fExperiment
.sendRequest(fSearchRequest
);
1288 fSearchRequest
.waitForCompletion();
1289 } catch (InterruptedException e
) {
1290 Activator
.getDefault().logError("Search request interrupted!", e
); //$NON-NLS-1$
1293 IStatus status
= Status
.OK_STATUS
;
1294 if (fSearchRequest
.isFound() && (fSearchRequest
.getFoundTime() != null)) {
1295 fCurrentTime
= fSearchRequest
.getFoundTime();
1297 // Avoid double-selection. Selection will be done when calling find(criteria)
1298 // after moving to relevant page
1300 if (!fView
.getSDWidget().isDisposed()) {
1301 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1311 if (monitor
.isCanceled()) {
1312 status
= Status
.CANCEL_STATUS
;
1315 // String was not found
1316 status
= new Status(IStatus
.WARNING
, Activator
.PLUGIN_ID
, Messages
.TmfUml2SDSyncLoader_SearchNotFound
);
1318 setProperty(IProgressConstants
.KEEP_PROPERTY
, Boolean
.TRUE
);
1324 fView
.toggleWaitCursorAsync(false);
1335 * @see org.eclipse.core.runtime.jobs.Job#canceling()
1338 protected void canceling() {
1339 fSearchRequest
.cancel();
1350 * TMF event request for searching within trace.
1352 protected class SearchEventRequest
extends TmfEventRequest
<ITmfEvent
> {
1355 * The find criteria.
1357 final private Criteria fCriteria
;
1359 * A progress monitor
1361 private IProgressMonitor fMonitor
;
1363 * Flag to indicate that node was found according the criteria .
1365 private boolean fIsFound
= false;
1367 * Time stamp of found item.
1369 private ITmfTimestamp fFoundTime
= null;
1373 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1374 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1375 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1376 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1377 * @param criteria The search criteria
1379 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType execType
, Criteria criteria
) {
1380 this(range
, nbRequested
, blockSize
, execType
, criteria
, null);
1385 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1386 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1387 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1388 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1389 * @param criteria The search criteria
1390 * @param monitor progress monitor
1392 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType execType
, Criteria criteria
, IProgressMonitor monitor
) {
1393 super(ITmfEvent
.class, range
, nbRequested
, blockSize
, execType
);
1394 fCriteria
= new Criteria(criteria
);
1400 * @see org.eclipse.linuxtools.tmf.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.event.TmfData)
1403 public void handleData(ITmfEvent event
) {
1404 super.handleData(event
);
1406 if ((fMonitor
!= null) && fMonitor
.isCanceled()) {
1411 ITmfSyncSequenceDiagramEvent sdEvent
= getSequnceDiagramEvent(event
);
1413 if (sdEvent
!= null) {
1415 if (fCriteria
.isLifeLineSelected()) {
1416 if (fCriteria
.matches(sdEvent
.getSender())) {
1417 fFoundTime
= event
.getTimestamp().clone();
1422 if (fCriteria
.matches(sdEvent
.getReceiver())) {
1423 fFoundTime
= event
.getTimestamp().clone();
1429 if (fCriteria
.isSyncMessageSelected() && fCriteria
.matches(sdEvent
.getName())) {
1430 fFoundTime
= event
.getTimestamp().clone();
1438 * Set progress monitor.
1440 * @param monitor The monitor to assign
1442 public void setMonitor(IProgressMonitor monitor
) {
1447 * Check if find criteria was met.
1449 * @return true if find criteria was met.
1451 public boolean isFound() {
1456 * Returns timestamp of found time.
1458 * @return timestamp of found time.
1460 public ITmfTimestamp
getFoundTime() {
1466 * Job class to provide progress monitor feedback.
1469 * @author Bernd Hufmann
1472 protected static class IndexingJob
extends Job
{
1474 public IndexingJob(String name
) {
1479 protected IStatus
run(IProgressMonitor monitor
) {
1480 while (!monitor
.isCanceled()) {
1483 } catch (InterruptedException e
) {
1484 return Status
.OK_STATUS
;
1488 return Status
.OK_STATUS
;
1494 * Returns sequence diagram event if details in given event are available else null.
1496 * @param tmfEvent Event to parse for sequence diagram event details
1497 * @return sequence diagram event if details are available else null
1499 protected ITmfSyncSequenceDiagramEvent
getSequnceDiagramEvent(ITmfEvent tmfEvent
){
1500 //type = .*RECEIVE.* or .*SEND.*
1501 //content = sender:<sender name>:receiver:<receiver name>,signal:<signal name>
1502 String eventType
= tmfEvent
.getType().toString();
1503 if (eventType
.contains(Messages
.TmfUml2SDSyncCloader_EventTypeSend
) || eventType
.contains(Messages
.TmfUml2SDSyncCloader_EventTypeReceive
)) {
1504 Object sender
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncCloader_FieldSender
);
1505 Object receiver
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncCloader_FieldReceiver
);
1506 Object name
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncCloader_FieldSignal
);
1507 if ((sender
instanceof ITmfEventField
) && (receiver
instanceof ITmfEventField
) && (name
instanceof ITmfEventField
)) {
1508 ITmfSyncSequenceDiagramEvent sdEvent
= new TmfSyncSequenceDiagramEvent(tmfEvent
,
1509 ((ITmfEventField
) sender
).getValue().toString(),
1510 ((ITmfEventField
) receiver
).getValue().toString(),
1511 ((ITmfEventField
) name
).getValue().toString());