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 <code>org.eclipse.linuxtools.tmf.ui.Uml2SDLoader</code> extension point. It provides
68 * a Sequence Diagram loader for a user space trace with specific trace content for sending and
69 * receiving signals between components. I also includes a default implementation for the <code>ITmfEvent</code> parsing.
72 * The class <code>TmfUml2SDSyncLoader</code> analyzes events from type <code>ITmfEvent</code> and creates events type
73 * <code>ITmfSyncSequenceDiagramEvent</code> if the <code>ITmfEvent</code> contains all relevant information.
74 * The analysis checks that the event type strings contains either string SEND or RECEIVE. If event type matches these key
75 * words, the analyzer will look for strings sender, receiver and signal in the event fields of type <code>ITmfEventField</code>.
76 * If all the data is found a sequence diagram event from can be created. Note that Sync Messages are assumed, which
77 * means start and end time are the same. <br>
79 * The parsing of the <code>ITmfEvent</code> is done in the method <code>getSequnceDiagramEvent()</code> of class
80 * <code>TmfUml2SDSyncLoader</code>. By extending the class <code>TmfUml2SDSyncLoader</code> and overwriting
81 * <code>getSequnceDiagramEvent()</code> a customized parsing algorithm can be implemented.<br>
83 * Note that combined traces of multiple components, that contain the trace information about the same interactions are not
84 * supported in the class <code>TmfUml2SDSyncLoader</code>.
87 * @author Bernd Hufmann
89 public class TmfUml2SDSyncLoader
extends TmfComponent
implements IUml2SDLoader
, ISDFindProvider
, ISDFilterProvider
, ISDAdvancedPagingProvider
, ISelectionListener
{
91 // ------------------------------------------------------------------------
93 // ------------------------------------------------------------------------
97 protected final static String TITLE
= Messages
.TmfUml2SDSyncLoader_ViewName
;
99 * Default block size for background request.
101 protected final static int DEFAULT_BLOCK_SIZE
= 50000;
103 * Maximum number of messages per page.
105 protected final static int MAX_NUM_OF_MSG
= 10000;
107 * Initial time range window.
109 protected final static long INITIAL_WINDOW_OFFSET
= (1L * 100 * 1000 * 1000); // .1sec
111 // ------------------------------------------------------------------------
113 // ------------------------------------------------------------------------
115 // Experiment attributes
117 * The TMF experiment reference.
119 protected TmfExperiment
<ITmfEvent
> fExperiment
= null;
121 * The current indexing event request.
123 protected ITmfEventRequest
<ITmfEvent
> fIndexRequest
= null;
125 * The current request to fill a page.
127 protected ITmfEventRequest
<ITmfEvent
> fPageRequest
= null;
129 * Flag whether the time range signal was sent by this loader class or not
131 volatile protected boolean fIsSignalSent
= false;
133 * The initial request window size.
135 volatile protected long fInitialWindow
= INITIAL_WINDOW_OFFSET
;
137 // The view and event attributes
139 * The sequence diagram view reference.
141 protected SDView fView
= null;
143 * The current sequence diagram frame reference.
145 protected Frame fFrame
= null;
147 * The list of sequence diagram events of current page.
149 protected List
<ITmfSyncSequenceDiagramEvent
> fEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>();
151 // Checkpoint and page attributes
153 * The checkpoints of the whole sequence diagram trace (i.e. start time stamp of each page)
155 protected List
<TmfTimeRange
> fCheckPoints
= new ArrayList
<TmfTimeRange
>(MAX_NUM_OF_MSG
);
157 * The current page displayed.
159 volatile protected int fCurrentPage
= 0;
161 * The current time selected.
163 protected ITmfTimestamp fCurrentTime
= null;
165 * Flag to specify that selection of message is done by selection or by signal.
167 volatile protected boolean fIsSelect
= false;
171 * The job for searching across pages.
173 protected SearchJob fFindJob
= null;
175 * List of found nodes within a page.
177 protected List
<GraphNode
> fFindResults
= new ArrayList
<GraphNode
>();
179 * The current find criteria reference
181 protected Criteria fFindCriteria
= null;
183 * The current find index within the list of found nodes (<code>fFindeResults</code> within a page.
185 volatile protected int fCurrentFindIndex
= 0;
189 * The list of active filters.
191 protected List
<FilterCriteria
> fFilterCriteria
= null;
193 // Thread synchronization
195 * The synchronization lock.
197 protected ReentrantLock fLock
= new ReentrantLock();
199 // ------------------------------------------------------------------------
201 // ------------------------------------------------------------------------
203 * Default constructor
205 public TmfUml2SDSyncLoader() {
212 * @param name Name of loader
214 public TmfUml2SDSyncLoader(String name
) {
218 // ------------------------------------------------------------------------
220 // ------------------------------------------------------------------------
222 * Returns the current time if available else null.
224 * @return the current time if available else null
226 public ITmfTimestamp
getCurrentTime() {
229 if (fCurrentTime
!= null) {
230 return fCurrentTime
.clone();
239 * Waits for the page request to be completed
241 public void waitForCompletion() {
243 ITmfEventRequest
<ITmfEvent
> request
= fPageRequest
;
247 request
.waitForCompletion();
248 } catch (InterruptedException e
) {
254 * Signal handler for the experiment selected signal.
256 * Spawns a request to index the experiment (checkpoints creation) as well as it fills
259 * @param signal The experiment selected signal
261 @SuppressWarnings("unchecked")
263 public void experimentSelected(TmfExperimentSelectedSignal
<ITmfEvent
> signal
) {
265 final Job job
= new IndexingJob("Indexing " + getName() + "..."); //$NON-NLS-1$ //$NON-NLS-2$
271 // Update the trace reference
272 TmfExperiment
<ITmfEvent
> exp
= (TmfExperiment
<ITmfEvent
>) signal
.getExperiment();
273 if (!exp
.equals(fExperiment
)) {
277 TmfTimeRange window
= TmfTimeRange
.ETERNITY
;
279 fIndexRequest
= new TmfEventRequest
<ITmfEvent
>(ITmfEvent
.class, window
, TmfDataRequest
.ALL_DATA
, DEFAULT_BLOCK_SIZE
, ITmfDataRequest
.ExecutionType
.BACKGROUND
) {
281 private ITmfTimestamp fFirstTime
= null;
282 private ITmfTimestamp fLastTime
= null;
283 private int fNbSeqEvents
= 0;
284 private final List
<ITmfSyncSequenceDiagramEvent
> fSdEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>(MAX_NUM_OF_MSG
);
288 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
291 public void handleData(ITmfEvent event
) {
292 super.handleData(event
);
294 ITmfSyncSequenceDiagramEvent sdEvent
= getSequnceDiagramEvent(event
);
296 if (sdEvent
!= null) {
299 if (fFirstTime
== null) {
300 fFirstTime
= event
.getTimestamp().clone();
303 fLastTime
= event
.getTimestamp().clone();
305 if ((fNbSeqEvents
% MAX_NUM_OF_MSG
) == 0) {
308 fCheckPoints
.add(new TmfTimeRange(fFirstTime
, fLastTime
));
310 fView
.updateCoolBar();
319 if (fNbSeqEvents
> MAX_NUM_OF_MSG
) {
324 fSdEvents
.add(sdEvent
);
326 if (fNbSeqEvents
== MAX_NUM_OF_MSG
) {
327 fillCurrentPage(fSdEvents
);
334 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleSuccess()
337 public void handleSuccess() {
338 if ((fFirstTime
!= null) && (fLastTime
!= null)) {
342 fCheckPoints
.add(new TmfTimeRange(fFirstTime
, fLastTime
));
344 fView
.updateCoolBar();
351 if (fNbSeqEvents
<= MAX_NUM_OF_MSG
) {
352 fillCurrentPage(fSdEvents
);
355 super.handleSuccess();
360 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleCompleted()
363 public void handleCompleted() {
364 if (fEvents
.isEmpty()) {
365 fFrame
= new Frame();
366 fView
.setFrameSync(fFrame
);
368 super.handleCompleted();
373 fExperiment
.sendRequest(fIndexRequest
);
381 * Signal handler for the experiment disposed signal.
383 * @param signal The experiment disposed signal
386 public void experimentDisposed(TmfExperimentDisposedSignal
<ITmfEvent
> signal
) {
387 if (signal
.getExperiment() != TmfExperiment
.getCurrentExperiment()) {
392 if ((fIndexRequest
!= null) && !fIndexRequest
.isCompleted()) {
393 fIndexRequest
.cancel();
394 fIndexRequest
= null;
397 cancelOngoingRequests();
399 if (fFilterCriteria
!= null) {
400 fFilterCriteria
.clear();
403 FilterListDialog
.deactivateSavedGlobalFilters();
412 * Moves to the page that contains the time provided by the signal. The messages will be selected
413 * if the provided time is the time of a message.
415 * @param signal The Time synch signal.
418 public void synchToTime(TmfTimeSynchSignal signal
) {
421 if ((signal
.getSource() != this) && (fFrame
!= null)) {
423 fCurrentTime
= signal
.getCurrentTime();
433 * Moves to the page that contains the current time provided by signal.
434 * No message will be selected however the focus will be set to the message
435 * if the provided time is the time of a message.
437 * @param signal The time range sync signal
440 public void synchToTimeRange(TmfRangeSynchSignal signal
) {
443 if ((signal
.getSource() != this) && (fFrame
!= null) && !fIsSignalSent
) {
444 TmfTimeRange newTimeRange
= signal
.getCurrentRange();
445 ITmfTimestamp delta
= newTimeRange
.getEndTime().getDelta(newTimeRange
.getStartTime());
446 fInitialWindow
= delta
.getValue();
449 fCurrentTime
= newTimeRange
.getStartTime();
461 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#setViewer(org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView)
463 @SuppressWarnings("unchecked")
465 public void setViewer(SDView viewer
) {
470 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
471 fView
.setSDFindProvider(this);
472 fView
.setSDPagingProvider(this);
473 fView
.setSDFilterProvider(this);
477 fExperiment
= (TmfExperiment
<ITmfEvent
>) TmfExperiment
.getCurrentExperiment();
478 if (fExperiment
!= null) {
479 experimentSelected(new TmfExperimentSelectedSignal
<ITmfEvent
>(this, fExperiment
));
488 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#getTitleString()
491 public String
getTitleString() {
497 * @see org.eclipse.linuxtools.tmf.component.TmfComponent#dispose()
500 public void dispose() {
504 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().removePostSelectionListener(this);
505 fView
.setSDFindProvider(null);
506 fView
.setSDPagingProvider(null);
507 fView
.setSDFilterProvider(null);
516 * @see org.eclipse.hyades.uml2sd.ui.actions.provider.ISDGraphNodeSupporter#isNodeSupported(int)
519 public boolean isNodeSupported(int nodeType
) {
521 case ISDGraphNodeSupporter
.LIFELINE
:
522 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
533 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter#getNodeName(int, java.lang.String)
536 public String
getNodeName(int nodeType
, String loaderClassName
) {
538 case ISDGraphNodeSupporter
.LIFELINE
:
539 return Messages
.TmfUml2SDSyncLoader_CategoryLifeline
;
540 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
541 return Messages
.TmfUml2SDSyncLoader_CategoryMessage
;
543 return ""; //$NON-NLS-1$
548 * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
551 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
552 ISelection sel
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
553 if ((sel
!= null) && (sel
instanceof StructuredSelection
)) {
554 StructuredSelection stSel
= (StructuredSelection
) sel
;
555 if (stSel
.getFirstElement() instanceof TmfSyncMessage
) {
556 TmfSyncMessage syncMsg
= ((TmfSyncMessage
) stSel
.getFirstElement());
557 broadcast(new TmfTimeSynchSignal(this, syncMsg
.getStartTime()));
565 * org.eclipse.hyades.uml2sd.ui.actions.provider.ISDFindProvider#find(org.eclipse.hyades.uml2sd.ui.actions.widgets.Criteria)
568 public boolean find(Criteria toSearch
) {
571 if (fFrame
== null) {
575 if ((fFindResults
== null) || (fFindCriteria
== null) || !fFindCriteria
.compareTo(toSearch
)) {
576 fFindResults
= new CopyOnWriteArrayList
<GraphNode
>();
577 fFindCriteria
= toSearch
;
578 if (fFindCriteria
.isLifeLineSelected()) {
579 for (int i
= 0; i
< fFrame
.lifeLinesCount(); i
++) {
580 if (fFindCriteria
.matches(fFrame
.getLifeline(i
).getName())) {
581 fFindResults
.add(fFrame
.getLifeline(i
));
586 ArrayList
<GraphNode
> msgs
= new ArrayList
<GraphNode
>();
587 if (fFindCriteria
.isSyncMessageSelected()) {
588 for (int i
= 0; i
< fFrame
.syncMessageCount(); i
++) {
589 if (fFindCriteria
.matches(fFrame
.getSyncMessage(i
).getName())) {
590 msgs
.add(fFrame
.getSyncMessage(i
));
595 if (!msgs
.isEmpty()) {
596 fFindResults
.addAll(msgs
);
599 @SuppressWarnings("rawtypes")
600 List selection
= fView
.getSDWidget().getSelection();
601 if ((selection
!= null) && (selection
.size() == 1)) {
602 fCurrentFindIndex
= fFindResults
.indexOf(selection
.get(0)) + 1;
604 fCurrentFindIndex
= 0;
610 if (fFindResults
.size() > fCurrentFindIndex
) {
611 GraphNode current
= fFindResults
.get(fCurrentFindIndex
);
612 fView
.getSDWidget().moveTo(current
);
616 fCurrentFindIndex
=0;
617 return findInNextPages(fFindCriteria
); // search in other page
626 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFindProvider#cancel()
629 public void cancel() {
630 cancelOngoingRequests();
635 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFilterProvider#filter(java.util.List)
637 @SuppressWarnings("unchecked")
639 public boolean filter(List
<?
> filters
) {
642 cancelOngoingRequests();
644 List
<FilterCriteria
> list
= (List
<FilterCriteria
>)filters
;
645 fFilterCriteria
= new ArrayList
<FilterCriteria
>(list
);
647 fillCurrentPage(fEvents
);
657 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasNextPage()
660 public boolean hasNextPage() {
663 int size
= fCheckPoints
.size();
665 return fCurrentPage
< (size
- 1);
675 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasPrevPage()
678 public boolean hasPrevPage() {
681 return fCurrentPage
> 0;
689 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#nextPage()
692 public void nextPage() {
696 if (fCurrentPage
>= (fCheckPoints
.size() - 1)) {
700 cancelOngoingRequests();
711 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#prevPage()
714 public void prevPage() {
718 if (fCurrentPage
<= 0) {
722 cancelOngoingRequests();
733 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#firstPage()
736 public void firstPage() {
740 cancelOngoingRequests();
751 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#lastPage()
754 public void lastPage() {
757 cancelOngoingRequests();
759 fCurrentPage
= fCheckPoints
.size() - 1;
768 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#currentPage()
771 public int currentPage() {
782 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pagesCount()
785 public int pagesCount() {
788 return fCheckPoints
.size();
796 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pageNumberChanged(int)
799 public void pageNumberChanged(int pagenNumber
) {
800 int localPageNumber
= pagenNumber
;
804 cancelOngoingRequests();
806 if (localPageNumber
< 0) {
809 int size
= fCheckPoints
.size();
810 if (localPageNumber
> (size
- 1)) {
811 localPageNumber
= size
- 1;
813 fCurrentPage
= localPageNumber
;
822 * @see org.eclipse.linuxtools.tmf.component.TmfComponent#broadcast(org.eclipse.linuxtools.tmf.signal.TmfSignal)
825 public void broadcast(TmfSignal signal
) {
826 fIsSignalSent
= true;
827 super.broadcast(signal
);
828 fIsSignalSent
= false;
832 * Cancels any ongoing find operation
834 protected void cancelOngoingRequests() {
837 // Cancel the search thread
838 if (fFindJob
!= null) {
843 fFindCriteria
= null;
844 fCurrentFindIndex
= 0;
846 if ((fPageRequest
!= null) && !fPageRequest
.isCompleted()) {
847 fPageRequest
.cancel();
856 * Resets loader attributes
858 protected void resetLoader() {
863 fCheckPoints
.clear();
865 fCurrentFindIndex
= 0;
866 fFindCriteria
= null;
868 fInitialWindow
= INITIAL_WINDOW_OFFSET
;
869 fView
.setFrameSync(new Frame());
879 * Fills current page with sequence diagram content.
881 * @param events sequence diagram events
883 protected void fillCurrentPage(List
<ITmfSyncSequenceDiagramEvent
> events
) {
887 fEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>(events
);
889 fView
.toggleWaitCursorAsync(true);
895 final Frame frame
= new Frame();
897 if (!events
.isEmpty()) {
898 Map
<String
, Lifeline
> nodeToLifelineMap
= new HashMap
<String
, Lifeline
>();
900 frame
.setName(Messages
.TmfUml2SDSyncLoader_FrameName
);
902 for (int i
= 0; i
< events
.size(); i
++) {
904 ITmfSyncSequenceDiagramEvent sdEvent
= events
.get(i
);
906 if ((nodeToLifelineMap
.get(sdEvent
.getSender()) == null) && (!filterLifeLine(sdEvent
.getSender()))) {
907 Lifeline lifeline
= new Lifeline();
908 lifeline
.setName(sdEvent
.getSender());
909 nodeToLifelineMap
.put(sdEvent
.getSender(), lifeline
);
910 frame
.addLifeLine(lifeline
);
913 if ((nodeToLifelineMap
.get(sdEvent
.getReceiver()) == null) && (!filterLifeLine(sdEvent
.getReceiver()))) {
914 Lifeline lifeline
= new Lifeline();
915 lifeline
.setName(sdEvent
.getReceiver());
916 nodeToLifelineMap
.put(sdEvent
.getReceiver(), lifeline
);
917 frame
.addLifeLine(lifeline
);
921 int eventOccurence
= 1;
923 for (int i
= 0; i
< events
.size(); i
++) {
924 ITmfSyncSequenceDiagramEvent sdEvent
= events
.get(i
);
926 // Check message filter
927 if (filterMessage(sdEvent
)) {
931 // Set the message sender and receiver
932 Lifeline startLifeline
= nodeToLifelineMap
.get(sdEvent
.getSender());
933 Lifeline endLifeline
= nodeToLifelineMap
.get(sdEvent
.getReceiver());
935 // Check if any of the lifelines were filtered
936 if ((startLifeline
== null) || (endLifeline
== null)) {
940 int tmp
= Math
.max(startLifeline
.getEventOccurrence(), endLifeline
.getEventOccurrence());
941 eventOccurence
= Math
.max(eventOccurence
, tmp
);
943 startLifeline
.setCurrentEventOccurrence(eventOccurence
);
944 endLifeline
.setCurrentEventOccurrence(eventOccurence
);
946 TmfSyncMessage message
= new TmfSyncMessage(sdEvent
, eventOccurence
++);
948 message
.setStartLifeline(startLifeline
);
949 message
.setEndLifeline(endLifeline
);
951 message
.setTime(sdEvent
.getStartTime());
953 // add the message to the frame
954 frame
.addMessage(message
);
959 if (!fView
.getSDWidget().isDisposed()) {
960 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
967 // check if view was disposed in the meanwhile
968 if ((fView
!= null) && (!fView
.getSDWidget().isDisposed())) {
970 fView
.setFrame(fFrame
);
972 if (fCurrentTime
!= null) {
973 moveToMessageInPage();
976 if (fFindCriteria
!= null) {
980 fView
.toggleWaitCursorAsync(false);
997 * Moves to a certain message defined by timestamp (across pages)
999 protected void moveToMessage() {
1004 page
= getPage(fCurrentTime
);
1006 if (page
== fCurrentPage
) {
1007 moveToMessageInPage();
1010 fCurrentPage
= page
;
1018 * Moves to a certain message defined by timestamp in current page
1020 protected void moveToMessageInPage() {
1023 if (!fView
.getSDWidget().isDisposed()) {
1024 // Check for GUI thread
1025 if(Display
.getCurrent() != null) {
1026 // Already in GUI thread - execute directly
1027 TmfSyncMessage prevMessage
= null;
1028 TmfSyncMessage syncMessage
= null;
1029 boolean isExactTime
= false;
1030 for (int i
= 0; i
< fFrame
.syncMessageCount(); i
++) {
1031 if (fFrame
.getSyncMessage(i
) instanceof TmfSyncMessage
) {
1032 syncMessage
= (TmfSyncMessage
) fFrame
.getSyncMessage(i
);
1033 if (syncMessage
.getStartTime().compareTo(fCurrentTime
, false) == 0) {
1036 } else if ((syncMessage
.getStartTime().compareTo(fCurrentTime
, false) > 0) && (prevMessage
!= null)) {
1037 syncMessage
= prevMessage
;
1040 prevMessage
= syncMessage
;
1043 if (fIsSelect
&& isExactTime
) {
1044 fView
.getSDWidget().moveTo(syncMessage
);
1047 fView
.getSDWidget().ensureVisible(syncMessage
);
1048 fView
.getSDWidget().clearSelection();
1049 fView
.getSDWidget().redraw();
1053 // Not in GUI thread - queue action in GUI thread.
1054 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1057 moveToMessageInPage();
1069 * Moves to a certain message defined by timestamp (across pages)
1071 protected void moveToPage() {
1076 * Moves to a certain page.
1078 * @param notifyAll true to broadcast time range signal to other signal handlers else false
1080 protected void moveToPage(boolean notifyAll
) {
1082 TmfTimeRange window
= null;
1087 if (fCurrentPage
> fCheckPoints
.size()) {
1090 window
= fCheckPoints
.get(fCurrentPage
);
1095 if (window
== null) {
1096 window
= TmfTimeRange
.ETERNITY
;
1099 fPageRequest
= new TmfEventRequest
<ITmfEvent
>(ITmfEvent
.class, window
, TmfDataRequest
.ALL_DATA
, 1, ITmfDataRequest
.ExecutionType
.FOREGROUND
) {
1100 private final List
<ITmfSyncSequenceDiagramEvent
> fSdEvent
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>();
1103 public void handleData(ITmfEvent event
) {
1104 super.handleData(event
);
1106 ITmfSyncSequenceDiagramEvent sdEvent
= getSequnceDiagramEvent(event
);
1108 if (sdEvent
!= null) {
1109 fSdEvent
.add(sdEvent
);
1114 public void handleSuccess() {
1115 fillCurrentPage(fSdEvent
);
1116 super.handleSuccess();
1121 fExperiment
.sendRequest(fPageRequest
);
1124 TmfTimeRange timeRange
= getSignalTimeRange(window
.getStartTime());
1125 broadcast(new TmfRangeSynchSignal(this, timeRange
, timeRange
.getStartTime()));
1130 * Gets page that contains timestamp
1132 * @param time The timestamp
1133 * @return page that contains the time
1135 protected int getPage(ITmfTimestamp time
) {
1140 size
= fCheckPoints
.size();
1141 for (page
= 0; page
< size
; page
++) {
1142 TmfTimeRange timeRange
= fCheckPoints
.get(page
);
1143 if (timeRange
.getEndTime().compareTo(time
, false) >= 0) {
1157 * Background search in trace for expression in criteria.
1159 * @param findCriteria The find criteria
1160 * @return true if background request was started else false
1162 protected boolean findInNextPages(Criteria findCriteria
) {
1165 if (fFindJob
!= null) {
1169 int nextPage
= fCurrentPage
+ 1;
1171 if ((nextPage
) >= fCheckPoints
.size()) {
1172 // we are at the end
1176 TmfTimeRange window
= new TmfTimeRange(fCheckPoints
.get(nextPage
).getStartTime().clone(), fCheckPoints
.get(fCheckPoints
.size()-1).getEndTime().clone());
1177 fFindJob
= new SearchJob(findCriteria
, window
);
1178 fFindJob
.schedule();
1179 fView
.toggleWaitCursorAsync(true);
1187 * Gets time range for time range signal.
1189 * @param startTime The start time of time range.
1190 * @return the time range
1192 protected TmfTimeRange
getSignalTimeRange(ITmfTimestamp startTime
) {
1195 TmfTimestamp initialEndOfWindow
= new TmfTimestamp(startTime
.getValue() + fInitialWindow
, startTime
.getScale(), startTime
.getPrecision());
1196 return new TmfTimeRange(startTime
, initialEndOfWindow
);
1204 * Checks if filter criteria matches the message name in given SD event.
1206 * @param sdEvent The SD event to check
1207 * @return true if match else false.
1209 protected boolean filterMessage(ITmfSyncSequenceDiagramEvent sdEvent
) {
1212 if (fFilterCriteria
!= null) {
1213 for(FilterCriteria criteria
: fFilterCriteria
) {
1214 if (criteria
.isActive() && criteria
.getCriteria().isSyncMessageSelected() && criteria
.getCriteria().matches(sdEvent
.getName())) {
1226 * Checks if filter criteria matches a lifeline name (sender or receiver) in given SD event.
1228 * @param lifeline the message receiver
1229 * @return true if match else false.
1231 protected boolean filterLifeLine(String lifeline
) {
1234 if (fFilterCriteria
!= null) {
1235 for(FilterCriteria criteria
: fFilterCriteria
) {
1236 if (criteria
.isActive() && criteria
.getCriteria().isLifeLineSelected() && criteria
.getCriteria().matches(lifeline
)) {
1248 * Job to search in trace for given time range.
1250 protected class SearchJob
extends Job
{
1253 * The search event request.
1255 final protected SearchEventRequest fSearchRequest
;
1260 * @param findCriteria The search criteria
1261 * @param window Time range to search in
1263 public SearchJob(Criteria findCriteria
, TmfTimeRange window
) {
1264 super(Messages
.TmfUml2SDSyncLoader_SearchJobDescrition
);
1265 fSearchRequest
= new SearchEventRequest(window
, TmfDataRequest
.ALL_DATA
, 1, ITmfDataRequest
.ExecutionType
.FOREGROUND
, findCriteria
);
1270 * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
1273 protected IStatus
run(IProgressMonitor monitor
) {
1274 fSearchRequest
.setMonitor(monitor
);
1276 fExperiment
.sendRequest(fSearchRequest
);
1279 fSearchRequest
.waitForCompletion();
1280 } catch (InterruptedException e
) {
1281 Activator
.getDefault().logError("Search request interrupted!", e
); //$NON-NLS-1$
1284 IStatus status
= Status
.OK_STATUS
;
1285 if (fSearchRequest
.isFound() && (fSearchRequest
.getFoundTime() != null)) {
1286 fCurrentTime
= fSearchRequest
.getFoundTime();
1288 // Avoid double-selection. Selection will be done when calling find(criteria)
1289 // after moving to relevant page
1291 if (!fView
.getSDWidget().isDisposed()) {
1292 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1302 if (monitor
.isCanceled()) {
1303 status
= Status
.CANCEL_STATUS
;
1306 // String was not found
1307 status
= new Status(Status
.WARNING
, Activator
.PLUGIN_ID
, Messages
.TmfUml2SDSyncLoader_SearchNotFound
);
1309 setProperty(IProgressConstants
.KEEP_PROPERTY
, Boolean
.TRUE
);
1315 fView
.toggleWaitCursorAsync(false);
1326 * @see org.eclipse.core.runtime.jobs.Job#canceling()
1329 protected void canceling() {
1330 fSearchRequest
.cancel();
1341 * TMF event request for searching within trace.
1343 protected class SearchEventRequest
extends TmfEventRequest
<ITmfEvent
> {
1346 * The find criteria.
1348 final private Criteria fCriteria
;
1350 * A progress monitor
1352 private IProgressMonitor fMonitor
;
1354 * Flag to indicate that node was found according the criteria .
1356 private boolean fIsFound
= false;
1358 * Time stamp of found item.
1360 private ITmfTimestamp fFoundTime
= null;
1364 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1365 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1366 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1367 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1368 * @param criteria The search criteria
1370 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType execType
, Criteria criteria
) {
1371 this(range
, nbRequested
, blockSize
, execType
, criteria
, null);
1376 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1377 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1378 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1379 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1380 * @param criteria The search criteria
1381 * @param monitor progress monitor
1383 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType execType
, Criteria criteria
, IProgressMonitor monitor
) {
1384 super(ITmfEvent
.class, range
, nbRequested
, blockSize
, execType
);
1385 fCriteria
= new Criteria(criteria
);
1391 * @see org.eclipse.linuxtools.tmf.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.event.TmfData)
1394 public void handleData(ITmfEvent event
) {
1395 super.handleData(event
);
1397 if ((fMonitor
!= null) && fMonitor
.isCanceled()) {
1402 ITmfSyncSequenceDiagramEvent sdEvent
= getSequnceDiagramEvent(event
);
1404 if (sdEvent
!= null) {
1406 if (fCriteria
.isLifeLineSelected()) {
1407 if (fCriteria
.matches(sdEvent
.getSender())) {
1408 fFoundTime
= event
.getTimestamp().clone();
1413 if (fCriteria
.matches(sdEvent
.getReceiver())) {
1414 fFoundTime
= event
.getTimestamp().clone();
1420 if (fCriteria
.isSyncMessageSelected() && fCriteria
.matches(sdEvent
.getName())) {
1421 fFoundTime
= event
.getTimestamp().clone();
1429 * Set progress monitor.
1433 public void setMonitor(IProgressMonitor monitor
) {
1438 * Check if find criteria was met.
1440 * @return true if find criteria was met.
1442 public boolean isFound() {
1447 * Returns timestamp of found time.
1449 * @return timestamp of found time.
1451 public ITmfTimestamp
getFoundTime() {
1457 * Job class to provide progress monitor feedback.
1460 * @author Bernd Hufmann
1463 protected static class IndexingJob
extends Job
{
1465 public IndexingJob(String name
) {
1470 protected IStatus
run(IProgressMonitor monitor
) {
1471 while (!monitor
.isCanceled()) {
1474 } catch (InterruptedException e
) {
1475 return Status
.OK_STATUS
;
1479 return Status
.OK_STATUS
;
1485 * Returns sequence diagram event if details in given event are available else null.
1487 * @param tmfEvent Event to parse for sequence diagram event details
1488 * @return sequence diagram event if details are available else null
1490 protected ITmfSyncSequenceDiagramEvent
getSequnceDiagramEvent(ITmfEvent tmfEvent
){
1491 //type = .*RECEIVE.* or .*SEND.*
1492 //content = sender:<sender name>:receiver:<receiver name>,signal:<signal name>
1493 String eventType
= tmfEvent
.getType().toString();
1494 if (eventType
.contains(Messages
.TmfUml2SDSyncCloader_EventTypeSend
) || eventType
.contains(Messages
.TmfUml2SDSyncCloader_EventTypeReceive
)) {
1495 Object sender
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncCloader_FieldSender
);
1496 Object receiver
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncCloader_FieldReceiver
);
1497 Object name
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncCloader_FieldSignal
);
1498 if ((sender
instanceof ITmfEventField
) && (receiver
instanceof ITmfEventField
) && (name
instanceof ITmfEventField
)) {
1499 ITmfSyncSequenceDiagramEvent sdEvent
= new TmfSyncSequenceDiagramEvent(tmfEvent
,
1500 ((ITmfEventField
) sender
).getValue().toString(),
1501 ((ITmfEventField
) receiver
).getValue().toString(),
1502 ((ITmfEventField
) name
).getValue().toString());