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
.IWorkbenchWindow
;
63 import org
.eclipse
.ui
.PlatformUI
;
64 import org
.eclipse
.ui
.progress
.IProgressConstants
;
68 * This class is a reference implementation of the
69 * <code>org.eclipse.linuxtools.tmf.ui.Uml2SDLoader</code> extension point. It
70 * provides a Sequence Diagram loader for a user space trace with specific trace
71 * content for sending and receiving signals between components. I also includes
72 * a default implementation for the <code>ITmfEvent</code> parsing.
75 * The class <code>TmfUml2SDSyncLoader</code> analyzes events from type
76 * <code>ITmfEvent</code> and creates events type
77 * <code>ITmfSyncSequenceDiagramEvent</code> if the <code>ITmfEvent</code>
78 * contains all relevant information. The analysis checks that the event type
79 * strings contains either string SEND or RECEIVE. If event type matches these
80 * key words, the analyzer will look for strings sender, receiver and signal in
81 * the event fields of type <code>ITmfEventField</code>. If all the data is
82 * found a sequence diagram event from can be created. Note that Sync Messages
83 * are assumed, which means start and end time are the same. <br>
85 * The parsing of the <code>ITmfEvent</code> is done in the method
86 * <code>getSequnceDiagramEvent()</code> of class
87 * <code>TmfUml2SDSyncLoader</code>. By extending the class
88 * <code>TmfUml2SDSyncLoader</code> and overwriting
89 * <code>getSequnceDiagramEvent()</code> a customized parsing algorithm can be
92 * Note that combined traces of multiple components, that contain the trace
93 * information about the same interactions are not supported in the class
94 * <code>TmfUml2SDSyncLoader</code>.
97 * @author Bernd Hufmann
99 public class TmfUml2SDSyncLoader
extends TmfComponent
implements IUml2SDLoader
, ISDFindProvider
, ISDFilterProvider
, ISDAdvancedPagingProvider
, ISelectionListener
{
101 // ------------------------------------------------------------------------
103 // ------------------------------------------------------------------------
105 * Default title name.
107 protected final static String TITLE
= Messages
.TmfUml2SDSyncLoader_ViewName
;
109 * Default block size for background request.
111 protected final static int DEFAULT_BLOCK_SIZE
= 50000;
113 * Maximum number of messages per page.
115 protected final static int MAX_NUM_OF_MSG
= 10000;
117 * Initial time range window.
119 protected final static long INITIAL_WINDOW_OFFSET
= (1L * 100 * 1000 * 1000); // .1sec
121 // ------------------------------------------------------------------------
123 // ------------------------------------------------------------------------
125 // Experiment attributes
127 * The TMF experiment reference.
129 protected TmfExperiment fExperiment
= null;
131 * The current indexing event request.
133 protected ITmfEventRequest fIndexRequest
= null;
135 * The current request to fill a page.
137 protected ITmfEventRequest fPageRequest
= null;
139 * Flag whether the time range signal was sent by this loader class or not
141 volatile protected boolean fIsSignalSent
= false;
143 * The initial request window size.
145 volatile protected long fInitialWindow
= INITIAL_WINDOW_OFFSET
;
147 // The view and event attributes
149 * The sequence diagram view reference.
151 protected SDView fView
= null;
153 * The current sequence diagram frame reference.
155 protected Frame fFrame
= null;
157 * The list of sequence diagram events of current page.
159 protected List
<ITmfSyncSequenceDiagramEvent
> fEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>();
161 // Checkpoint and page attributes
163 * The checkpoints of the whole sequence diagram trace (i.e. start time stamp of each page)
165 protected List
<TmfTimeRange
> fCheckPoints
= new ArrayList
<TmfTimeRange
>(MAX_NUM_OF_MSG
);
167 * The current page displayed.
169 volatile protected int fCurrentPage
= 0;
171 * The current time selected.
173 protected ITmfTimestamp fCurrentTime
= null;
175 * Flag to specify that selection of message is done by selection or by signal.
177 volatile protected boolean fIsSelect
= false;
181 * The job for searching across pages.
183 protected SearchJob fFindJob
= null;
185 * List of found nodes within a page.
187 protected List
<GraphNode
> fFindResults
= new ArrayList
<GraphNode
>();
189 * The current find criteria reference
191 protected Criteria fFindCriteria
= null;
193 * The current find index within the list of found nodes (<code>fFindeResults</code> within a page.
195 volatile protected int fCurrentFindIndex
= 0;
199 * The list of active filters.
201 protected List
<FilterCriteria
> fFilterCriteria
= null;
203 // Thread synchronization
205 * The synchronization lock.
207 protected ReentrantLock fLock
= new ReentrantLock();
209 // ------------------------------------------------------------------------
211 // ------------------------------------------------------------------------
213 * Default constructor
215 public TmfUml2SDSyncLoader() {
222 * @param name Name of loader
224 public TmfUml2SDSyncLoader(String name
) {
228 // ------------------------------------------------------------------------
230 // ------------------------------------------------------------------------
232 * Returns the current time if available else null.
234 * @return the current time if available else null
236 public ITmfTimestamp
getCurrentTime() {
239 if (fCurrentTime
!= null) {
240 return fCurrentTime
.clone();
249 * Waits for the page request to be completed
251 public void waitForCompletion() {
253 ITmfEventRequest request
= fPageRequest
;
255 if (request
!= null) {
257 request
.waitForCompletion();
258 } catch (InterruptedException e
) {
265 * Signal handler for the experiment selected signal.
267 * Spawns a request to index the experiment (checkpoints creation) as well as it fills
270 * @param signal The experiment selected signal
273 public void experimentSelected(TmfExperimentSelectedSignal signal
) {
275 final Job job
= new IndexingJob("Indexing " + getName() + "..."); //$NON-NLS-1$ //$NON-NLS-2$
281 // Update the trace reference
282 TmfExperiment exp
= signal
.getExperiment();
283 if (!exp
.equals(fExperiment
)) {
287 TmfTimeRange window
= TmfTimeRange
.ETERNITY
;
289 fIndexRequest
= new TmfEventRequest(ITmfEvent
.class, window
, TmfDataRequest
.ALL_DATA
, DEFAULT_BLOCK_SIZE
, ITmfDataRequest
.ExecutionType
.BACKGROUND
) {
291 private ITmfTimestamp fFirstTime
= null;
292 private ITmfTimestamp fLastTime
= null;
293 private int fNbSeqEvents
= 0;
294 private final List
<ITmfSyncSequenceDiagramEvent
> fSdEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>(MAX_NUM_OF_MSG
);
298 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
301 public void handleData(ITmfEvent event
) {
302 super.handleData(event
);
304 ITmfSyncSequenceDiagramEvent sdEvent
= getSequnceDiagramEvent(event
);
306 if (sdEvent
!= null) {
309 if (fFirstTime
== null) {
310 fFirstTime
= event
.getTimestamp().clone();
313 fLastTime
= event
.getTimestamp().clone();
315 if ((fNbSeqEvents
% MAX_NUM_OF_MSG
) == 0) {
318 fCheckPoints
.add(new TmfTimeRange(fFirstTime
, fLastTime
));
320 fView
.updateCoolBar();
329 if (fNbSeqEvents
> MAX_NUM_OF_MSG
) {
334 fSdEvents
.add(sdEvent
);
336 if (fNbSeqEvents
== MAX_NUM_OF_MSG
) {
337 fillCurrentPage(fSdEvents
);
344 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleSuccess()
347 public void handleSuccess() {
348 if ((fFirstTime
!= null) && (fLastTime
!= null)) {
352 fCheckPoints
.add(new TmfTimeRange(fFirstTime
, fLastTime
));
354 fView
.updateCoolBar();
361 if (fNbSeqEvents
<= MAX_NUM_OF_MSG
) {
362 fillCurrentPage(fSdEvents
);
365 super.handleSuccess();
370 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleCompleted()
373 public void handleCompleted() {
374 if (fEvents
.isEmpty()) {
375 fFrame
= new Frame();
376 fView
.setFrameSync(fFrame
);
378 super.handleCompleted();
383 fExperiment
.sendRequest(fIndexRequest
);
391 * Signal handler for the experiment disposed signal.
393 * @param signal The experiment disposed signal
396 public void experimentDisposed(TmfExperimentDisposedSignal signal
) {
397 if (signal
.getExperiment() != TmfExperiment
.getCurrentExperiment()) {
402 if ((fIndexRequest
!= null) && !fIndexRequest
.isCompleted()) {
403 fIndexRequest
.cancel();
404 fIndexRequest
= null;
407 cancelOngoingRequests();
409 if (fFilterCriteria
!= null) {
410 fFilterCriteria
.clear();
413 FilterListDialog
.deactivateSavedGlobalFilters();
422 * Moves to the page that contains the time provided by the signal. The messages will be selected
423 * if the provided time is the time of a message.
425 * @param signal The Time synch signal.
428 public void synchToTime(TmfTimeSynchSignal signal
) {
431 if ((signal
.getSource() != this) && (fFrame
!= null)) {
433 fCurrentTime
= signal
.getCurrentTime();
443 * Moves to the page that contains the current time provided by signal.
444 * No message will be selected however the focus will be set to the message
445 * if the provided time is the time of a message.
447 * @param signal The time range sync signal
450 public void synchToTimeRange(TmfRangeSynchSignal signal
) {
453 if ((signal
.getSource() != this) && (fFrame
!= null) && !fIsSignalSent
) {
454 TmfTimeRange newTimeRange
= signal
.getCurrentRange();
455 ITmfTimestamp delta
= newTimeRange
.getEndTime().getDelta(newTimeRange
.getStartTime());
456 fInitialWindow
= delta
.getValue();
459 fCurrentTime
= newTimeRange
.getStartTime();
471 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#setViewer(org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView)
474 public void setViewer(SDView viewer
) {
479 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
480 fView
.setSDFindProvider(this);
481 fView
.setSDPagingProvider(this);
482 fView
.setSDFilterProvider(this);
486 fExperiment
= TmfExperiment
.getCurrentExperiment();
487 if (fExperiment
!= null) {
488 experimentSelected(new TmfExperimentSelectedSignal(this, fExperiment
));
497 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#getTitleString()
500 public String
getTitleString() {
506 * @see org.eclipse.linuxtools.tmf.component.TmfComponent#dispose()
509 public void dispose() {
513 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
514 // During Eclipse shutdown the active workbench window is null
515 if (window
!= null) {
516 window
.getSelectionService().removePostSelectionListener(this);
518 fView
.setSDFindProvider(null);
519 fView
.setSDPagingProvider(null);
520 fView
.setSDFilterProvider(null);
529 * @see org.eclipse.hyades.uml2sd.ui.actions.provider.ISDGraphNodeSupporter#isNodeSupported(int)
532 public boolean isNodeSupported(int nodeType
) {
534 case ISDGraphNodeSupporter
.LIFELINE
:
535 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
546 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter#getNodeName(int, java.lang.String)
549 public String
getNodeName(int nodeType
, String loaderClassName
) {
551 case ISDGraphNodeSupporter
.LIFELINE
:
552 return Messages
.TmfUml2SDSyncLoader_CategoryLifeline
;
553 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
554 return Messages
.TmfUml2SDSyncLoader_CategoryMessage
;
558 return ""; //$NON-NLS-1$
563 * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
566 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
567 ISelection sel
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
568 if ((sel
!= null) && (sel
instanceof StructuredSelection
)) {
569 StructuredSelection stSel
= (StructuredSelection
) sel
;
570 if (stSel
.getFirstElement() instanceof TmfSyncMessage
) {
571 TmfSyncMessage syncMsg
= ((TmfSyncMessage
) stSel
.getFirstElement());
572 broadcast(new TmfTimeSynchSignal(this, syncMsg
.getStartTime()));
580 * org.eclipse.hyades.uml2sd.ui.actions.provider.ISDFindProvider#find(org.eclipse.hyades.uml2sd.ui.actions.widgets.Criteria)
583 public boolean find(Criteria toSearch
) {
586 if (fFrame
== null) {
590 if ((fFindResults
== null) || (fFindCriteria
== null) || !fFindCriteria
.compareTo(toSearch
)) {
591 fFindResults
= new CopyOnWriteArrayList
<GraphNode
>();
592 fFindCriteria
= toSearch
;
593 if (fFindCriteria
.isLifeLineSelected()) {
594 for (int i
= 0; i
< fFrame
.lifeLinesCount(); i
++) {
595 if (fFindCriteria
.matches(fFrame
.getLifeline(i
).getName())) {
596 fFindResults
.add(fFrame
.getLifeline(i
));
601 ArrayList
<GraphNode
> msgs
= new ArrayList
<GraphNode
>();
602 if (fFindCriteria
.isSyncMessageSelected()) {
603 for (int i
= 0; i
< fFrame
.syncMessageCount(); i
++) {
604 if (fFindCriteria
.matches(fFrame
.getSyncMessage(i
).getName())) {
605 msgs
.add(fFrame
.getSyncMessage(i
));
610 if (!msgs
.isEmpty()) {
611 fFindResults
.addAll(msgs
);
614 @SuppressWarnings("rawtypes")
615 List selection
= fView
.getSDWidget().getSelection();
616 if ((selection
!= null) && (selection
.size() == 1)) {
617 fCurrentFindIndex
= fFindResults
.indexOf(selection
.get(0)) + 1;
619 fCurrentFindIndex
= 0;
625 if (fFindResults
.size() > fCurrentFindIndex
) {
626 GraphNode current
= fFindResults
.get(fCurrentFindIndex
);
627 fView
.getSDWidget().moveTo(current
);
631 fCurrentFindIndex
=0;
632 return findInNextPages(fFindCriteria
); // search in other page
640 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFindProvider#cancel()
643 public void cancel() {
644 cancelOngoingRequests();
649 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFilterProvider#filter(java.util.List)
651 @SuppressWarnings("unchecked")
653 public boolean filter(List
<?
> filters
) {
656 cancelOngoingRequests();
658 List
<FilterCriteria
> list
= (List
<FilterCriteria
>)filters
;
659 fFilterCriteria
= new ArrayList
<FilterCriteria
>(list
);
661 fillCurrentPage(fEvents
);
671 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasNextPage()
674 public boolean hasNextPage() {
677 int size
= fCheckPoints
.size();
679 return fCurrentPage
< (size
- 1);
689 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasPrevPage()
692 public boolean hasPrevPage() {
695 return fCurrentPage
> 0;
703 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#nextPage()
706 public void nextPage() {
710 if (fCurrentPage
>= (fCheckPoints
.size() - 1)) {
714 cancelOngoingRequests();
725 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#prevPage()
728 public void prevPage() {
732 if (fCurrentPage
<= 0) {
736 cancelOngoingRequests();
747 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#firstPage()
750 public void firstPage() {
754 cancelOngoingRequests();
765 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#lastPage()
768 public void lastPage() {
771 cancelOngoingRequests();
773 fCurrentPage
= fCheckPoints
.size() - 1;
782 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#currentPage()
785 public int currentPage() {
796 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pagesCount()
799 public int pagesCount() {
802 return fCheckPoints
.size();
810 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pageNumberChanged(int)
813 public void pageNumberChanged(int pagenNumber
) {
814 int localPageNumber
= pagenNumber
;
818 cancelOngoingRequests();
820 if (localPageNumber
< 0) {
823 int size
= fCheckPoints
.size();
824 if (localPageNumber
> (size
- 1)) {
825 localPageNumber
= size
- 1;
827 fCurrentPage
= localPageNumber
;
836 * @see org.eclipse.linuxtools.tmf.component.TmfComponent#broadcast(org.eclipse.linuxtools.tmf.signal.TmfSignal)
839 public void broadcast(TmfSignal signal
) {
840 fIsSignalSent
= true;
841 super.broadcast(signal
);
842 fIsSignalSent
= false;
846 * Cancels any ongoing find operation
848 protected void cancelOngoingRequests() {
851 // Cancel the search thread
852 if (fFindJob
!= null) {
857 fFindCriteria
= null;
858 fCurrentFindIndex
= 0;
860 if ((fPageRequest
!= null) && !fPageRequest
.isCompleted()) {
861 fPageRequest
.cancel();
870 * Resets loader attributes
872 protected void resetLoader() {
877 fCheckPoints
.clear();
879 fCurrentFindIndex
= 0;
880 fFindCriteria
= null;
882 fInitialWindow
= INITIAL_WINDOW_OFFSET
;
883 fView
.setFrameSync(new Frame());
893 * Fills current page with sequence diagram content.
895 * @param events sequence diagram events
897 protected void fillCurrentPage(List
<ITmfSyncSequenceDiagramEvent
> events
) {
901 fEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>(events
);
903 fView
.toggleWaitCursorAsync(true);
909 final Frame frame
= new Frame();
911 if (!events
.isEmpty()) {
912 Map
<String
, Lifeline
> nodeToLifelineMap
= new HashMap
<String
, Lifeline
>();
914 frame
.setName(Messages
.TmfUml2SDSyncLoader_FrameName
);
916 for (int i
= 0; i
< events
.size(); i
++) {
918 ITmfSyncSequenceDiagramEvent sdEvent
= events
.get(i
);
920 if ((nodeToLifelineMap
.get(sdEvent
.getSender()) == null) && (!filterLifeLine(sdEvent
.getSender()))) {
921 Lifeline lifeline
= new Lifeline();
922 lifeline
.setName(sdEvent
.getSender());
923 nodeToLifelineMap
.put(sdEvent
.getSender(), lifeline
);
924 frame
.addLifeLine(lifeline
);
927 if ((nodeToLifelineMap
.get(sdEvent
.getReceiver()) == null) && (!filterLifeLine(sdEvent
.getReceiver()))) {
928 Lifeline lifeline
= new Lifeline();
929 lifeline
.setName(sdEvent
.getReceiver());
930 nodeToLifelineMap
.put(sdEvent
.getReceiver(), lifeline
);
931 frame
.addLifeLine(lifeline
);
935 int eventOccurence
= 1;
937 for (int i
= 0; i
< events
.size(); i
++) {
938 ITmfSyncSequenceDiagramEvent sdEvent
= events
.get(i
);
940 // Check message filter
941 if (filterMessage(sdEvent
)) {
945 // Set the message sender and receiver
946 Lifeline startLifeline
= nodeToLifelineMap
.get(sdEvent
.getSender());
947 Lifeline endLifeline
= nodeToLifelineMap
.get(sdEvent
.getReceiver());
949 // Check if any of the lifelines were filtered
950 if ((startLifeline
== null) || (endLifeline
== null)) {
954 int tmp
= Math
.max(startLifeline
.getEventOccurrence(), endLifeline
.getEventOccurrence());
955 eventOccurence
= Math
.max(eventOccurence
, tmp
);
957 startLifeline
.setCurrentEventOccurrence(eventOccurence
);
958 endLifeline
.setCurrentEventOccurrence(eventOccurence
);
960 TmfSyncMessage message
= new TmfSyncMessage(sdEvent
, eventOccurence
++);
962 message
.setStartLifeline(startLifeline
);
963 message
.setEndLifeline(endLifeline
);
965 message
.setTime(sdEvent
.getStartTime());
967 // add the message to the frame
968 frame
.addMessage(message
);
973 if (!fView
.getSDWidget().isDisposed()) {
974 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
981 // check if view was disposed in the meanwhile
982 if ((fView
!= null) && (!fView
.getSDWidget().isDisposed())) {
984 fView
.setFrame(fFrame
);
986 if (fCurrentTime
!= null) {
987 moveToMessageInPage();
990 if (fFindCriteria
!= null) {
994 fView
.toggleWaitCursorAsync(false);
1011 * Moves to a certain message defined by timestamp (across pages)
1013 protected void moveToMessage() {
1018 page
= getPage(fCurrentTime
);
1020 if (page
== fCurrentPage
) {
1021 moveToMessageInPage();
1024 fCurrentPage
= page
;
1032 * Moves to a certain message defined by timestamp in current page
1034 protected void moveToMessageInPage() {
1037 if (!fView
.getSDWidget().isDisposed()) {
1038 // Check for GUI thread
1039 if(Display
.getCurrent() != null) {
1040 // Already in GUI thread - execute directly
1041 TmfSyncMessage prevMessage
= null;
1042 TmfSyncMessage syncMessage
= null;
1043 boolean isExactTime
= false;
1044 for (int i
= 0; i
< fFrame
.syncMessageCount(); i
++) {
1045 if (fFrame
.getSyncMessage(i
) instanceof TmfSyncMessage
) {
1046 syncMessage
= (TmfSyncMessage
) fFrame
.getSyncMessage(i
);
1047 if (syncMessage
.getStartTime().compareTo(fCurrentTime
, false) == 0) {
1050 } else if ((syncMessage
.getStartTime().compareTo(fCurrentTime
, false) > 0) && (prevMessage
!= null)) {
1051 syncMessage
= prevMessage
;
1054 prevMessage
= syncMessage
;
1057 if (fIsSelect
&& isExactTime
) {
1058 fView
.getSDWidget().moveTo(syncMessage
);
1061 fView
.getSDWidget().ensureVisible(syncMessage
);
1062 fView
.getSDWidget().clearSelection();
1063 fView
.getSDWidget().redraw();
1067 // Not in GUI thread - queue action in GUI thread.
1068 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1071 moveToMessageInPage();
1083 * Moves to a certain message defined by timestamp (across pages)
1085 protected void moveToPage() {
1090 * Moves to a certain page.
1092 * @param notifyAll true to broadcast time range signal to other signal handlers else false
1094 protected void moveToPage(boolean notifyAll
) {
1096 TmfTimeRange window
= null;
1101 if (fCurrentPage
> fCheckPoints
.size()) {
1104 window
= fCheckPoints
.get(fCurrentPage
);
1109 if (window
== null) {
1110 window
= TmfTimeRange
.ETERNITY
;
1113 fPageRequest
= new TmfEventRequest(ITmfEvent
.class, window
, TmfDataRequest
.ALL_DATA
, 1, ITmfDataRequest
.ExecutionType
.FOREGROUND
) {
1114 private final List
<ITmfSyncSequenceDiagramEvent
> fSdEvent
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>();
1117 public void handleData(ITmfEvent event
) {
1118 super.handleData(event
);
1120 ITmfSyncSequenceDiagramEvent sdEvent
= getSequnceDiagramEvent(event
);
1122 if (sdEvent
!= null) {
1123 fSdEvent
.add(sdEvent
);
1128 public void handleSuccess() {
1129 fillCurrentPage(fSdEvent
);
1130 super.handleSuccess();
1135 fExperiment
.sendRequest(fPageRequest
);
1138 TmfTimeRange timeRange
= getSignalTimeRange(window
.getStartTime());
1139 broadcast(new TmfRangeSynchSignal(this, timeRange
, timeRange
.getStartTime()));
1144 * Gets page that contains timestamp
1146 * @param time The timestamp
1147 * @return page that contains the time
1149 protected int getPage(ITmfTimestamp time
) {
1154 size
= fCheckPoints
.size();
1155 for (page
= 0; page
< size
; page
++) {
1156 TmfTimeRange timeRange
= fCheckPoints
.get(page
);
1157 if (timeRange
.getEndTime().compareTo(time
, false) >= 0) {
1171 * Background search in trace for expression in criteria.
1173 * @param findCriteria The find criteria
1174 * @return true if background request was started else false
1176 protected boolean findInNextPages(Criteria findCriteria
) {
1179 if (fFindJob
!= null) {
1183 int nextPage
= fCurrentPage
+ 1;
1185 if ((nextPage
) >= fCheckPoints
.size()) {
1186 // we are at the end
1190 TmfTimeRange window
= new TmfTimeRange(fCheckPoints
.get(nextPage
).getStartTime().clone(), fCheckPoints
.get(fCheckPoints
.size()-1).getEndTime().clone());
1191 fFindJob
= new SearchJob(findCriteria
, window
);
1192 fFindJob
.schedule();
1193 fView
.toggleWaitCursorAsync(true);
1201 * Gets time range for time range signal.
1203 * @param startTime The start time of time range.
1204 * @return the time range
1206 protected TmfTimeRange
getSignalTimeRange(ITmfTimestamp startTime
) {
1209 TmfTimestamp initialEndOfWindow
= new TmfTimestamp(startTime
.getValue() + fInitialWindow
, startTime
.getScale(), startTime
.getPrecision());
1210 return new TmfTimeRange(startTime
, initialEndOfWindow
);
1218 * Checks if filter criteria matches the message name in given SD event.
1220 * @param sdEvent The SD event to check
1221 * @return true if match else false.
1223 protected boolean filterMessage(ITmfSyncSequenceDiagramEvent sdEvent
) {
1226 if (fFilterCriteria
!= null) {
1227 for(FilterCriteria criteria
: fFilterCriteria
) {
1228 if (criteria
.isActive() && criteria
.getCriteria().isSyncMessageSelected() && criteria
.getCriteria().matches(sdEvent
.getName())) {
1240 * Checks if filter criteria matches a lifeline name (sender or receiver) in given SD event.
1242 * @param lifeline the message receiver
1243 * @return true if match else false.
1245 protected boolean filterLifeLine(String lifeline
) {
1248 if (fFilterCriteria
!= null) {
1249 for(FilterCriteria criteria
: fFilterCriteria
) {
1250 if (criteria
.isActive() && criteria
.getCriteria().isLifeLineSelected() && criteria
.getCriteria().matches(lifeline
)) {
1262 * Job to search in trace for given time range.
1264 protected class SearchJob
extends Job
{
1267 * The search event request.
1269 final protected SearchEventRequest fSearchRequest
;
1274 * @param findCriteria The search criteria
1275 * @param window Time range to search in
1277 public SearchJob(Criteria findCriteria
, TmfTimeRange window
) {
1278 super(Messages
.TmfUml2SDSyncLoader_SearchJobDescrition
);
1279 fSearchRequest
= new SearchEventRequest(window
, TmfDataRequest
.ALL_DATA
, 1, ITmfDataRequest
.ExecutionType
.FOREGROUND
, findCriteria
);
1284 * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
1287 protected IStatus
run(IProgressMonitor monitor
) {
1288 fSearchRequest
.setMonitor(monitor
);
1290 fExperiment
.sendRequest(fSearchRequest
);
1293 fSearchRequest
.waitForCompletion();
1294 } catch (InterruptedException e
) {
1295 Activator
.getDefault().logError("Search request interrupted!", e
); //$NON-NLS-1$
1298 IStatus status
= Status
.OK_STATUS
;
1299 if (fSearchRequest
.isFound() && (fSearchRequest
.getFoundTime() != null)) {
1300 fCurrentTime
= fSearchRequest
.getFoundTime();
1302 // Avoid double-selection. Selection will be done when calling find(criteria)
1303 // after moving to relevant page
1305 if (!fView
.getSDWidget().isDisposed()) {
1306 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1316 if (monitor
.isCanceled()) {
1317 status
= Status
.CANCEL_STATUS
;
1320 // String was not found
1321 status
= new Status(IStatus
.WARNING
, Activator
.PLUGIN_ID
, Messages
.TmfUml2SDSyncLoader_SearchNotFound
);
1323 setProperty(IProgressConstants
.KEEP_PROPERTY
, Boolean
.TRUE
);
1329 fView
.toggleWaitCursorAsync(false);
1340 * @see org.eclipse.core.runtime.jobs.Job#canceling()
1343 protected void canceling() {
1344 fSearchRequest
.cancel();
1355 * TMF event request for searching within trace.
1357 protected class SearchEventRequest
extends TmfEventRequest
{
1360 * The find criteria.
1362 final private Criteria fCriteria
;
1364 * A progress monitor
1366 private IProgressMonitor fMonitor
;
1368 * Flag to indicate that node was found according the criteria .
1370 private boolean fIsFound
= false;
1372 * Time stamp of found item.
1374 private ITmfTimestamp fFoundTime
= null;
1378 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1379 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1380 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1381 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1382 * @param criteria The search criteria
1384 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType execType
, Criteria criteria
) {
1385 this(range
, nbRequested
, blockSize
, execType
, criteria
, null);
1390 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1391 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1392 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1393 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1394 * @param criteria The search criteria
1395 * @param monitor progress monitor
1397 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType execType
, Criteria criteria
, IProgressMonitor monitor
) {
1398 super(ITmfEvent
.class, range
, nbRequested
, blockSize
, execType
);
1399 fCriteria
= new Criteria(criteria
);
1405 * @see org.eclipse.linuxtools.tmf.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.event.TmfData)
1408 public void handleData(ITmfEvent event
) {
1409 super.handleData(event
);
1411 if ((fMonitor
!= null) && fMonitor
.isCanceled()) {
1416 ITmfSyncSequenceDiagramEvent sdEvent
= getSequnceDiagramEvent(event
);
1418 if (sdEvent
!= null) {
1420 if (fCriteria
.isLifeLineSelected()) {
1421 if (fCriteria
.matches(sdEvent
.getSender())) {
1422 fFoundTime
= event
.getTimestamp().clone();
1427 if (fCriteria
.matches(sdEvent
.getReceiver())) {
1428 fFoundTime
= event
.getTimestamp().clone();
1434 if (fCriteria
.isSyncMessageSelected() && fCriteria
.matches(sdEvent
.getName())) {
1435 fFoundTime
= event
.getTimestamp().clone();
1443 * Set progress monitor.
1445 * @param monitor The monitor to assign
1447 public void setMonitor(IProgressMonitor monitor
) {
1452 * Check if find criteria was met.
1454 * @return true if find criteria was met.
1456 public boolean isFound() {
1461 * Returns timestamp of found time.
1463 * @return timestamp of found time.
1465 public ITmfTimestamp
getFoundTime() {
1471 * Job class to provide progress monitor feedback.
1474 * @author Bernd Hufmann
1477 protected static class IndexingJob
extends Job
{
1479 public IndexingJob(String name
) {
1484 protected IStatus
run(IProgressMonitor monitor
) {
1485 while (!monitor
.isCanceled()) {
1488 } catch (InterruptedException e
) {
1489 return Status
.OK_STATUS
;
1493 return Status
.OK_STATUS
;
1499 * Returns sequence diagram event if details in given event are available else null.
1501 * @param tmfEvent Event to parse for sequence diagram event details
1502 * @return sequence diagram event if details are available else null
1504 protected ITmfSyncSequenceDiagramEvent
getSequnceDiagramEvent(ITmfEvent tmfEvent
){
1505 //type = .*RECEIVE.* or .*SEND.*
1506 //content = sender:<sender name>:receiver:<receiver name>,signal:<signal name>
1507 String eventType
= tmfEvent
.getType().toString();
1508 if (eventType
.contains(Messages
.TmfUml2SDSyncCloader_EventTypeSend
) || eventType
.contains(Messages
.TmfUml2SDSyncCloader_EventTypeReceive
)) {
1509 Object sender
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncCloader_FieldSender
);
1510 Object receiver
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncCloader_FieldReceiver
);
1511 Object name
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncCloader_FieldSignal
);
1512 if ((sender
instanceof ITmfEventField
) && (receiver
instanceof ITmfEventField
) && (name
instanceof ITmfEventField
)) {
1513 ITmfSyncSequenceDiagramEvent sdEvent
= new TmfSyncSequenceDiagramEvent(tmfEvent
,
1514 ((ITmfEventField
) sender
).getValue().toString(),
1515 ((ITmfEventField
) receiver
).getValue().toString(),
1516 ((ITmfEventField
) name
).getValue().toString());