1 /**********************************************************************
2 * Copyright (c) 2011, 2013 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 **********************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.loader
;
15 import java
.util
.ArrayList
;
16 import java
.util
.HashMap
;
17 import java
.util
.List
;
19 import java
.util
.concurrent
.CopyOnWriteArrayList
;
20 import java
.util
.concurrent
.locks
.ReentrantLock
;
22 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
23 import org
.eclipse
.core
.runtime
.IStatus
;
24 import org
.eclipse
.core
.runtime
.Status
;
25 import org
.eclipse
.core
.runtime
.jobs
.Job
;
26 import org
.eclipse
.jface
.viewers
.ISelection
;
27 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
28 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.component
.TmfComponent
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfDataRequest
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfEventRequest
;
34 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfDataRequest
;
35 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfEventRequest
;
36 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfRangeSynchSignal
;
37 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignal
;
38 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
39 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimeSynchSignal
;
40 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceClosedSignal
;
41 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceOpenedSignal
;
42 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
43 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
44 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimeRange
;
45 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestamp
;
46 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
47 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTraceManager
;
48 import org
.eclipse
.linuxtools
.tmf
.core
.uml2sd
.ITmfSyncSequenceDiagramEvent
;
49 import org
.eclipse
.linuxtools
.tmf
.core
.uml2sd
.TmfSyncSequenceDiagramEvent
;
50 import org
.eclipse
.linuxtools
.tmf
.ui
.editors
.ITmfTraceEditor
;
51 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.SDView
;
52 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Frame
;
53 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
54 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Lifeline
;
55 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.Criteria
;
56 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.FilterCriteria
;
57 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.FilterListDialog
;
58 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDAdvancedPagingProvider
;
59 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDFilterProvider
;
60 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDFindProvider
;
61 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDGraphNodeSupporter
;
62 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.load
.IUml2SDLoader
;
63 import org
.eclipse
.swt
.widgets
.Display
;
64 import org
.eclipse
.ui
.IEditorPart
;
65 import org
.eclipse
.ui
.ISelectionListener
;
66 import org
.eclipse
.ui
.IWorkbenchPart
;
67 import org
.eclipse
.ui
.IWorkbenchWindow
;
68 import org
.eclipse
.ui
.PlatformUI
;
69 import org
.eclipse
.ui
.progress
.IProgressConstants
;
73 * This class is a reference implementation of the
74 * <code>org.eclipse.linuxtools.tmf.ui.Uml2SDLoader</code> extension point. It
75 * provides a Sequence Diagram loader for a user space trace with specific trace
76 * content for sending and receiving signals between components. I also includes
77 * a default implementation for the <code>ITmfEvent</code> parsing.
80 * The class <code>TmfUml2SDSyncLoader</code> analyzes events from type
81 * <code>ITmfEvent</code> and creates events type
82 * <code>ITmfSyncSequenceDiagramEvent</code> if the <code>ITmfEvent</code>
83 * contains all relevant information. The analysis checks that the event type
84 * strings contains either string SEND or RECEIVE. If event type matches these
85 * key words, the analyzer will look for strings sender, receiver and signal in
86 * the event fields of type <code>ITmfEventField</code>. If all the data is
87 * found a sequence diagram event from can be created. Note that Sync Messages
88 * are assumed, which means start and end time are the same. <br>
90 * The parsing of the <code>ITmfEvent</code> is done in the method
91 * <code>getSequnceDiagramEvent()</code> of class
92 * <code>TmfUml2SDSyncLoader</code>. By extending the class
93 * <code>TmfUml2SDSyncLoader</code> and overwriting
94 * <code>getSequnceDiagramEvent()</code> a customized parsing algorithm can be
97 * Note that combined traces of multiple components, that contain the trace
98 * information about the same interactions are not supported in the class
99 * <code>TmfUml2SDSyncLoader</code>.
102 * @author Bernd Hufmann
104 public class TmfUml2SDSyncLoader
extends TmfComponent
implements IUml2SDLoader
, ISDFindProvider
, ISDFilterProvider
, ISDAdvancedPagingProvider
, ISelectionListener
{
106 // ------------------------------------------------------------------------
108 // ------------------------------------------------------------------------
111 * Default title name.
113 protected static final String TITLE
= Messages
.TmfUml2SDSyncLoader_ViewName
;
116 * Maximum number of messages per page.
118 protected static final int MAX_NUM_OF_MSG
= 10000;
120 private static final int INDEXING_THREAD_SLEEP_VALUE
= 100;
122 // ------------------------------------------------------------------------
124 // ------------------------------------------------------------------------
126 // Experiment attributes
128 * The TMF trace reference.
131 protected ITmfTrace fTrace
= null;
133 * The current indexing event request.
135 protected ITmfEventRequest fIndexRequest
= null;
137 * The current request to fill a page.
139 protected ITmfEventRequest fPageRequest
= null;
141 * Flag whether the time range signal was sent by this loader class or not
143 protected volatile boolean fIsSignalSent
= false;
145 // The view and event attributes
147 * The sequence diagram view reference.
149 protected SDView fView
= null;
151 * The current sequence diagram frame reference.
153 protected Frame fFrame
= null;
155 * The list of sequence diagram events of current page.
157 protected List
<ITmfSyncSequenceDiagramEvent
> fEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>();
159 // Checkpoint and page attributes
161 * The checkpoints of the whole sequence diagram trace (i.e. start time stamp of each page)
163 protected List
<TmfTimeRange
> fCheckPoints
= new ArrayList
<TmfTimeRange
>(MAX_NUM_OF_MSG
);
165 * The current page displayed.
167 protected volatile int fCurrentPage
= 0;
169 * The current time selected.
171 protected ITmfTimestamp fCurrentTime
= null;
173 * Flag to specify that selection of message is done by selection or by signal.
175 protected volatile boolean fIsSelect
= false;
179 * The job for searching across pages.
181 protected SearchJob fFindJob
= null;
183 * List of found nodes within a page.
185 protected List
<GraphNode
> fFindResults
= new ArrayList
<GraphNode
>();
187 * The current find criteria reference
189 protected Criteria fFindCriteria
= null;
191 * The current find index within the list of found nodes (<code>fFindeResults</code> within a page.
193 protected volatile int fCurrentFindIndex
= 0;
197 * The list of active filters.
199 protected List
<FilterCriteria
> fFilterCriteria
= null;
201 // Thread synchronization
203 * The synchronization lock.
205 protected ReentrantLock fLock
= new ReentrantLock();
207 // ------------------------------------------------------------------------
209 // ------------------------------------------------------------------------
211 * Default constructor
213 public TmfUml2SDSyncLoader() {
220 * @param name Name of loader
222 public TmfUml2SDSyncLoader(String name
) {
226 // ------------------------------------------------------------------------
228 // ------------------------------------------------------------------------
231 * Returns the current time if available else null.
233 * @return the current time if available else null
236 public ITmfTimestamp
getCurrentTime() {
239 if (fCurrentTime
!= null) {
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 * Handler for the trace opened signal.
266 * @param signal The trace opened signal
270 public void traceOpened(TmfTraceOpenedSignal signal
) {
271 fTrace
= signal
.getTrace();
277 * Signal handler for the trace selected signal.
279 * Spawns a request to index the trace (checkpoints creation) as well as it fills
282 * @param signal The trace selected signal
286 public void traceSelected(TmfTraceSelectedSignal signal
) {
287 // Update the trace reference
288 ITmfTrace trace
= signal
.getTrace();
289 if (!trace
.equals(fTrace
)) {
296 * Method for loading the current selected trace into the view.
297 * Sub-class need to override this method to add the view specific implementation.
300 protected void loadTrace() {
301 ITmfEventRequest indexRequest
= null;
305 final Job job
= new IndexingJob("Indexing " + getName() + "..."); //$NON-NLS-1$ //$NON-NLS-2$
309 indexRequest
= fIndexRequest
;
311 cancelOngoingRequests();
313 TmfTimeRange window
= TmfTimeRange
.ETERNITY
;
315 fIndexRequest
= new TmfEventRequest(ITmfEvent
.class, window
, 0, TmfDataRequest
.ALL_DATA
, ITmfDataRequest
.ExecutionType
.BACKGROUND
) {
317 private ITmfTimestamp fFirstTime
= null;
318 private ITmfTimestamp fLastTime
= null;
319 private int fNbSeqEvents
= 0;
320 private final List
<ITmfSyncSequenceDiagramEvent
> fSdEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>(MAX_NUM_OF_MSG
);
323 public void handleData(ITmfEvent event
) {
324 super.handleData(event
);
326 ITmfSyncSequenceDiagramEvent sdEvent
= getSequenceDiagramEvent(event
);
328 if (sdEvent
!= null) {
331 if (fFirstTime
== null) {
332 fFirstTime
= event
.getTimestamp();
335 fLastTime
= event
.getTimestamp();
337 if ((fNbSeqEvents
% MAX_NUM_OF_MSG
) == 0) {
340 fCheckPoints
.add(new TmfTimeRange(fFirstTime
, fLastTime
));
342 fView
.updateCoolBar();
351 if (fNbSeqEvents
> MAX_NUM_OF_MSG
) {
356 fSdEvents
.add(sdEvent
);
358 if (fNbSeqEvents
== MAX_NUM_OF_MSG
) {
359 fillCurrentPage(fSdEvents
);
365 public void handleSuccess() {
366 if ((fFirstTime
!= null) && (fLastTime
!= null)) {
370 fCheckPoints
.add(new TmfTimeRange(fFirstTime
, fLastTime
));
372 fView
.updateCoolBar();
379 if (fNbSeqEvents
<= MAX_NUM_OF_MSG
) {
380 fillCurrentPage(fSdEvents
);
383 super.handleSuccess();
387 public void handleCompleted() {
388 if (fEvents
.isEmpty()) {
389 fFrame
= new Frame();
390 // make sure that view is not null when setting frame
398 if (sdView
!= null) {
399 sdView
.setFrameSync(fFrame
);
402 super.handleCompleted();
410 if (indexRequest
!= null && !indexRequest
.isCompleted()) {
411 indexRequest
.cancel();
414 fTrace
.sendRequest(fIndexRequest
);
418 * Signal handler for the trace closed signal.
420 * @param signal The trace closed signal
424 public void traceClosed(TmfTraceClosedSignal signal
) {
425 if (signal
.getTrace() != fTrace
) {
428 ITmfEventRequest indexRequest
= null;
431 indexRequest
= fIndexRequest
;
432 fIndexRequest
= null;
434 cancelOngoingRequests();
436 if (fFilterCriteria
!= null) {
437 fFilterCriteria
.clear();
440 FilterListDialog
.deactivateSavedGlobalFilters();
445 if (indexRequest
!= null && !indexRequest
.isCompleted()) {
446 indexRequest
.cancel();
453 * Moves to the page that contains the time provided by the signal. The messages will be selected
454 * if the provided time is the time of a message.
456 * @param signal The Time synch signal.
459 public void synchToTime(TmfTimeSynchSignal signal
) {
462 if ((signal
.getSource() != this) && (fFrame
!= null) && (fCheckPoints
.size() > 0)) {
463 fCurrentTime
= signal
.getCurrentTime();
473 * Moves to the page that contains the current time provided by signal.
474 * No message will be selected however the focus will be set to the message
475 * if the provided time is the time of a message.
477 * @param signal The time range sync signal
480 public void synchToTimeRange(TmfRangeSynchSignal signal
) {
483 if ((signal
.getSource() != this) && (fFrame
!= null) && !fIsSignalSent
&& (fCheckPoints
.size() > 0)) {
484 TmfTimeRange newTimeRange
= signal
.getCurrentRange();
487 fCurrentTime
= newTimeRange
.getStartTime();
498 public void setViewer(SDView viewer
) {
503 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
504 fView
.setSDFindProvider(this);
505 fView
.setSDPagingProvider(this);
506 fView
.setSDFilterProvider(this);
509 IEditorPart editor
= fView
.getSite().getPage().getActiveEditor();
510 if (editor
instanceof ITmfTraceEditor
) {
511 ITmfTrace trace
= ((ITmfTraceEditor
) editor
).getTrace();
513 traceSelected(new TmfTraceSelectedSignal(this, trace
));
522 public String
getTitleString() {
527 public void dispose() {
529 ITmfEventRequest indexRequest
= null;
532 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
533 // During Eclipse shutdown the active workbench window is null
534 if (window
!= null) {
535 window
.getSelectionService().removePostSelectionListener(this);
538 indexRequest
= fIndexRequest
;
539 fIndexRequest
= null;
540 cancelOngoingRequests();
542 fView
.setSDFindProvider(null);
543 fView
.setSDPagingProvider(null);
544 fView
.setSDFilterProvider(null);
549 if (indexRequest
!= null && !indexRequest
.isCompleted()) {
550 indexRequest
.cancel();
555 public boolean isNodeSupported(int nodeType
) {
557 case ISDGraphNodeSupporter
.LIFELINE
:
558 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
568 public String
getNodeName(int nodeType
, String loaderClassName
) {
570 case ISDGraphNodeSupporter
.LIFELINE
:
571 return Messages
.TmfUml2SDSyncLoader_CategoryLifeline
;
572 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
573 return Messages
.TmfUml2SDSyncLoader_CategoryMessage
;
577 return ""; //$NON-NLS-1$
581 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
582 ISelection sel
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
583 if ((sel
!= null) && (sel
instanceof StructuredSelection
)) {
584 StructuredSelection stSel
= (StructuredSelection
) sel
;
585 if (stSel
.getFirstElement() instanceof TmfSyncMessage
) {
586 TmfSyncMessage syncMsg
= ((TmfSyncMessage
) stSel
.getFirstElement());
587 broadcast(new TmfTimeSynchSignal(this, syncMsg
.getStartTime()));
593 public boolean find(Criteria toSearch
) {
596 if (fFrame
== null) {
600 if ((fFindResults
== null) || (fFindCriteria
== null) || !fFindCriteria
.compareTo(toSearch
)) {
601 fFindResults
= new CopyOnWriteArrayList
<GraphNode
>();
602 fFindCriteria
= toSearch
;
603 if (fFindCriteria
.isLifeLineSelected()) {
604 for (int i
= 0; i
< fFrame
.lifeLinesCount(); i
++) {
605 if (fFindCriteria
.matches(fFrame
.getLifeline(i
).getName())) {
606 fFindResults
.add(fFrame
.getLifeline(i
));
611 ArrayList
<GraphNode
> msgs
= new ArrayList
<GraphNode
>();
612 if (fFindCriteria
.isSyncMessageSelected()) {
613 for (int i
= 0; i
< fFrame
.syncMessageCount(); i
++) {
614 if (fFindCriteria
.matches(fFrame
.getSyncMessage(i
).getName())) {
615 msgs
.add(fFrame
.getSyncMessage(i
));
620 if (!msgs
.isEmpty()) {
621 fFindResults
.addAll(msgs
);
624 @SuppressWarnings("rawtypes")
625 List selection
= fView
.getSDWidget().getSelection();
626 if ((selection
!= null) && (selection
.size() == 1)) {
627 fCurrentFindIndex
= fFindResults
.indexOf(selection
.get(0)) + 1;
629 fCurrentFindIndex
= 0;
635 if (fFindResults
.size() > fCurrentFindIndex
) {
636 GraphNode current
= fFindResults
.get(fCurrentFindIndex
);
637 fView
.getSDWidget().moveTo(current
);
641 fCurrentFindIndex
=0;
642 return findInNextPages(fFindCriteria
); // search in other page
649 public void cancel() {
650 cancelOngoingRequests();
653 @SuppressWarnings("unchecked")
655 public boolean filter(List
<?
> filters
) {
658 cancelOngoingRequests();
660 if (filters
== null) {
661 fFilterCriteria
= new ArrayList
<FilterCriteria
>();
663 List
<FilterCriteria
> list
= (List
<FilterCriteria
>)filters
;
664 fFilterCriteria
= new ArrayList
<FilterCriteria
>(list
);
667 fillCurrentPage(fEvents
);
676 public boolean hasNextPage() {
679 int size
= fCheckPoints
.size();
681 return fCurrentPage
< (size
- 1);
690 public boolean hasPrevPage() {
693 return fCurrentPage
> 0;
700 public void nextPage() {
704 if (fCurrentPage
>= (fCheckPoints
.size() - 1)) {
708 cancelOngoingRequests();
718 public void prevPage() {
722 if (fCurrentPage
<= 0) {
726 cancelOngoingRequests();
736 public void firstPage() {
740 cancelOngoingRequests();
750 public void lastPage() {
753 cancelOngoingRequests();
755 fCurrentPage
= fCheckPoints
.size() - 1;
763 public int currentPage() {
773 public int pagesCount() {
776 return fCheckPoints
.size();
783 public void pageNumberChanged(int pagenNumber
) {
784 int localPageNumber
= pagenNumber
;
788 cancelOngoingRequests();
790 if (localPageNumber
< 0) {
793 int size
= fCheckPoints
.size();
794 if (localPageNumber
> (size
- 1)) {
795 localPageNumber
= size
- 1;
797 fCurrentPage
= localPageNumber
;
805 public void broadcast(TmfSignal signal
) {
806 fIsSignalSent
= true;
807 super.broadcast(signal
);
808 fIsSignalSent
= false;
812 * Cancels any ongoing find operation
814 protected void cancelOngoingRequests() {
816 ITmfEventRequest pageRequest
= null;
818 // Cancel the search thread
819 if (fFindJob
!= null) {
824 fFindCriteria
= null;
825 fCurrentFindIndex
= 0;
827 pageRequest
= fPageRequest
;
832 if (pageRequest
!= null && !pageRequest
.isCompleted()) {
833 pageRequest
.cancel();
838 * Resets loader attributes
840 protected void resetLoader() {
845 fCheckPoints
.clear();
847 fCurrentFindIndex
= 0;
848 fFindCriteria
= null;
850 fView
.setFrameSync(new Frame());
860 * Fills current page with sequence diagram content.
862 * @param events sequence diagram events
864 protected void fillCurrentPage(List
<ITmfSyncSequenceDiagramEvent
> events
) {
868 fEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>(events
);
869 if (fView
!= null && !events
.isEmpty()) {
870 fView
.toggleWaitCursorAsync(true);
876 final Frame frame
= new Frame();
878 if (!events
.isEmpty()) {
879 Map
<String
, Lifeline
> nodeToLifelineMap
= new HashMap
<String
, Lifeline
>();
881 frame
.setName(Messages
.TmfUml2SDSyncLoader_FrameName
);
883 for (int i
= 0; i
< events
.size(); i
++) {
885 ITmfSyncSequenceDiagramEvent sdEvent
= events
.get(i
);
887 if ((nodeToLifelineMap
.get(sdEvent
.getSender()) == null) && (!filterLifeLine(sdEvent
.getSender()))) {
888 Lifeline lifeline
= new Lifeline();
889 lifeline
.setName(sdEvent
.getSender());
890 nodeToLifelineMap
.put(sdEvent
.getSender(), lifeline
);
891 frame
.addLifeLine(lifeline
);
894 if ((nodeToLifelineMap
.get(sdEvent
.getReceiver()) == null) && (!filterLifeLine(sdEvent
.getReceiver()))) {
895 Lifeline lifeline
= new Lifeline();
896 lifeline
.setName(sdEvent
.getReceiver());
897 nodeToLifelineMap
.put(sdEvent
.getReceiver(), lifeline
);
898 frame
.addLifeLine(lifeline
);
902 int eventOccurence
= 1;
904 for (int i
= 0; i
< events
.size(); i
++) {
905 ITmfSyncSequenceDiagramEvent sdEvent
= events
.get(i
);
907 // Check message filter
908 if (filterMessage(sdEvent
)) {
912 // Set the message sender and receiver
913 Lifeline startLifeline
= nodeToLifelineMap
.get(sdEvent
.getSender());
914 Lifeline endLifeline
= nodeToLifelineMap
.get(sdEvent
.getReceiver());
916 // Check if any of the lifelines were filtered
917 if ((startLifeline
== null) || (endLifeline
== null)) {
921 int tmp
= Math
.max(startLifeline
.getEventOccurrence(), endLifeline
.getEventOccurrence());
922 eventOccurence
= Math
.max(eventOccurence
, tmp
);
924 startLifeline
.setCurrentEventOccurrence(eventOccurence
);
925 endLifeline
.setCurrentEventOccurrence(eventOccurence
);
927 TmfSyncMessage message
= new TmfSyncMessage(sdEvent
, eventOccurence
++);
929 message
.setStartLifeline(startLifeline
);
930 message
.setEndLifeline(endLifeline
);
932 message
.setTime(sdEvent
.getStartTime());
934 // add the message to the frame
935 frame
.addMessage(message
);
940 if (!fView
.getSDWidget().isDisposed()) {
941 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
948 // check if view was disposed in the meanwhile
949 if ((fView
!= null) && (!fView
.getSDWidget().isDisposed())) {
951 fView
.setFrame(fFrame
);
953 if (fCurrentTime
!= null) {
954 moveToMessageInPage();
957 if (fFindCriteria
!= null) {
961 fView
.toggleWaitCursorAsync(false);
978 * Moves to a certain message defined by timestamp (across pages)
980 protected void moveToMessage() {
985 page
= getPage(fCurrentTime
);
987 if (page
== fCurrentPage
) {
988 moveToMessageInPage();
999 * Moves to a certain message defined by timestamp in current page
1001 protected void moveToMessageInPage() {
1004 if (!fView
.getSDWidget().isDisposed()) {
1005 // Check for GUI thread
1006 if(Display
.getCurrent() != null) {
1007 // Already in GUI thread - execute directly
1008 TmfSyncMessage prevMessage
= null;
1009 TmfSyncMessage syncMessage
= null;
1010 boolean isExactTime
= false;
1011 for (int i
= 0; i
< fFrame
.syncMessageCount(); i
++) {
1012 if (fFrame
.getSyncMessage(i
) instanceof TmfSyncMessage
) {
1013 syncMessage
= (TmfSyncMessage
) fFrame
.getSyncMessage(i
);
1014 if (syncMessage
.getStartTime().compareTo(fCurrentTime
, false) == 0) {
1017 } else if ((syncMessage
.getStartTime().compareTo(fCurrentTime
, false) > 0) && (prevMessage
!= null)) {
1018 syncMessage
= prevMessage
;
1021 prevMessage
= syncMessage
;
1024 if (fIsSelect
&& isExactTime
) {
1025 fView
.getSDWidget().moveTo(syncMessage
);
1028 fView
.getSDWidget().ensureVisible(syncMessage
);
1029 fView
.getSDWidget().clearSelection();
1030 fView
.getSDWidget().redraw();
1034 // Not in GUI thread - queue action in GUI thread.
1035 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1038 moveToMessageInPage();
1050 * Moves to a certain message defined by timestamp (across pages)
1052 protected void moveToPage() {
1057 * Moves to a certain page.
1059 * @param notifyAll true to broadcast time range signal to other signal handlers else false
1061 protected void moveToPage(boolean notifyAll
) {
1063 TmfTimeRange window
= null;
1068 if (fCurrentPage
> fCheckPoints
.size()) {
1071 window
= fCheckPoints
.get(fCurrentPage
);
1076 if (window
== null) {
1077 window
= TmfTimeRange
.ETERNITY
;
1080 fPageRequest
= new TmfEventRequest(ITmfEvent
.class, window
, 0, TmfDataRequest
.ALL_DATA
, ITmfDataRequest
.ExecutionType
.FOREGROUND
) {
1081 private final List
<ITmfSyncSequenceDiagramEvent
> fSdEvent
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>();
1084 public void handleData(ITmfEvent event
) {
1085 super.handleData(event
);
1087 ITmfSyncSequenceDiagramEvent sdEvent
= getSequenceDiagramEvent(event
);
1089 if (sdEvent
!= null) {
1090 fSdEvent
.add(sdEvent
);
1095 public void handleSuccess() {
1096 fillCurrentPage(fSdEvent
);
1097 super.handleSuccess();
1102 fTrace
.sendRequest(fPageRequest
);
1105 TmfTimeRange timeRange
= getSignalTimeRange(window
.getStartTime());
1106 broadcast(new TmfRangeSynchSignal(this, timeRange
, timeRange
.getStartTime()));
1111 * Gets page that contains timestamp
1113 * @param time The timestamp
1114 * @return page that contains the time
1117 protected int getPage(ITmfTimestamp time
) {
1122 size
= fCheckPoints
.size();
1123 for (page
= 0; page
< size
; page
++) {
1124 TmfTimeRange timeRange
= fCheckPoints
.get(page
);
1125 if (timeRange
.getEndTime().compareTo(time
, false) >= 0) {
1139 * Background search in trace for expression in criteria.
1141 * @param findCriteria The find criteria
1142 * @return true if background request was started else false
1144 protected boolean findInNextPages(Criteria findCriteria
) {
1147 if (fFindJob
!= null) {
1151 int nextPage
= fCurrentPage
+ 1;
1153 if ((nextPage
) >= fCheckPoints
.size()) {
1154 // we are at the end
1158 TmfTimeRange window
= new TmfTimeRange(fCheckPoints
.get(nextPage
).getStartTime(), fCheckPoints
.get(fCheckPoints
.size()-1).getEndTime());
1159 fFindJob
= new SearchJob(findCriteria
, window
);
1160 fFindJob
.schedule();
1161 fView
.toggleWaitCursorAsync(true);
1169 * Gets time range for time range signal.
1171 * @param startTime The start time of time range.
1172 * @return the time range
1175 protected TmfTimeRange
getSignalTimeRange(ITmfTimestamp startTime
) {
1178 TmfTimeRange currentRange
= TmfTraceManager
.getInstance().getCurrentRange();
1179 long offset
= fTrace
== null ?
0 : currentRange
.getEndTime().getDelta(currentRange
.getStartTime()).normalize(0, startTime
.getScale()).getValue();
1180 TmfTimestamp initialEndOfWindow
= new TmfTimestamp(startTime
.getValue() + offset
, startTime
.getScale(), startTime
.getPrecision());
1181 return new TmfTimeRange(startTime
, initialEndOfWindow
);
1189 * Checks if filter criteria matches the message name in given SD event.
1191 * @param sdEvent The SD event to check
1192 * @return true if match else false.
1194 protected boolean filterMessage(ITmfSyncSequenceDiagramEvent sdEvent
) {
1197 if (fFilterCriteria
!= null) {
1198 for(FilterCriteria criteria
: fFilterCriteria
) {
1199 if (criteria
.isActive() && criteria
.getCriteria().isSyncMessageSelected() && criteria
.getCriteria().matches(sdEvent
.getName())) {
1211 * Checks if filter criteria matches a lifeline name (sender or receiver) in given SD event.
1213 * @param lifeline the message receiver
1214 * @return true if match else false.
1216 protected boolean filterLifeLine(String lifeline
) {
1219 if (fFilterCriteria
!= null) {
1220 for(FilterCriteria criteria
: fFilterCriteria
) {
1221 if (criteria
.isActive() && criteria
.getCriteria().isLifeLineSelected() && criteria
.getCriteria().matches(lifeline
)) {
1233 * Job to search in trace for given time range.
1235 protected class SearchJob
extends Job
{
1238 * The search event request.
1240 protected final SearchEventRequest fSearchRequest
;
1245 * @param findCriteria The search criteria
1246 * @param window Time range to search in
1249 public SearchJob(Criteria findCriteria
, TmfTimeRange window
) {
1250 super(Messages
.TmfUml2SDSyncLoader_SearchJobDescrition
);
1251 fSearchRequest
= new SearchEventRequest(window
, TmfDataRequest
.ALL_DATA
, ITmfDataRequest
.ExecutionType
.FOREGROUND
, findCriteria
);
1255 protected IStatus
run(IProgressMonitor monitor
) {
1256 fSearchRequest
.setMonitor(monitor
);
1258 fTrace
.sendRequest(fSearchRequest
);
1261 fSearchRequest
.waitForCompletion();
1262 } catch (InterruptedException e
) {
1263 Activator
.getDefault().logError("Search request interrupted!", e
); //$NON-NLS-1$
1266 IStatus status
= Status
.OK_STATUS
;
1267 if (fSearchRequest
.isFound() && (fSearchRequest
.getFoundTime() != null)) {
1268 fCurrentTime
= fSearchRequest
.getFoundTime();
1270 // Avoid double-selection. Selection will be done when calling find(criteria)
1271 // after moving to relevant page
1273 if (!fView
.getSDWidget().isDisposed()) {
1274 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1284 if (monitor
.isCanceled()) {
1285 status
= Status
.CANCEL_STATUS
;
1288 // String was not found
1289 status
= new Status(IStatus
.WARNING
, Activator
.PLUGIN_ID
, Messages
.TmfUml2SDSyncLoader_SearchNotFound
);
1291 setProperty(IProgressConstants
.KEEP_PROPERTY
, Boolean
.TRUE
);
1297 fView
.toggleWaitCursorAsync(false);
1307 protected void canceling() {
1308 fSearchRequest
.cancel();
1319 * TMF event request for searching within trace.
1321 protected class SearchEventRequest
extends TmfEventRequest
{
1324 * The find criteria.
1326 private final Criteria fCriteria
;
1328 * A progress monitor
1330 private IProgressMonitor fMonitor
;
1332 * Flag to indicate that node was found according the criteria .
1334 private boolean fIsFound
= false;
1336 * Time stamp of found item.
1338 private ITmfTimestamp fFoundTime
= null;
1342 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1343 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1344 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1345 * @param criteria The search criteria
1347 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, ExecutionType execType
, Criteria criteria
) {
1348 this(range
, nbRequested
, execType
, criteria
, null);
1353 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1354 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1355 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1356 * @param criteria The search criteria
1357 * @param monitor progress monitor
1359 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, ExecutionType execType
, Criteria criteria
, IProgressMonitor monitor
) {
1360 super(ITmfEvent
.class, range
, 0, nbRequested
, execType
);
1361 fCriteria
= new Criteria(criteria
);
1366 public void handleData(ITmfEvent event
) {
1367 super.handleData(event
);
1369 if ((fMonitor
!= null) && fMonitor
.isCanceled()) {
1374 ITmfSyncSequenceDiagramEvent sdEvent
= getSequenceDiagramEvent(event
);
1376 if (sdEvent
!= null) {
1378 if (fCriteria
.isLifeLineSelected()) {
1379 if (fCriteria
.matches(sdEvent
.getSender())) {
1380 fFoundTime
= event
.getTimestamp();
1385 if (fCriteria
.matches(sdEvent
.getReceiver())) {
1386 fFoundTime
= event
.getTimestamp();
1392 if (fCriteria
.isSyncMessageSelected() && fCriteria
.matches(sdEvent
.getName())) {
1393 fFoundTime
= event
.getTimestamp();
1401 * Set progress monitor.
1403 * @param monitor The monitor to assign
1405 public void setMonitor(IProgressMonitor monitor
) {
1410 * Check if find criteria was met.
1412 * @return true if find criteria was met.
1414 public boolean isFound() {
1419 * Returns timestamp of found time.
1421 * @return timestamp of found time.
1424 public ITmfTimestamp
getFoundTime() {
1430 * Job class to provide progress monitor feedback.
1433 * @author Bernd Hufmann
1436 protected static class IndexingJob
extends Job
{
1439 * @param name The job name
1441 public IndexingJob(String name
) {
1446 protected IStatus
run(IProgressMonitor monitor
) {
1447 while (!monitor
.isCanceled()) {
1449 Thread
.sleep(INDEXING_THREAD_SLEEP_VALUE
);
1450 } catch (InterruptedException e
) {
1451 return Status
.OK_STATUS
;
1455 return Status
.OK_STATUS
;
1461 * Returns sequence diagram event if details in given event are available else null.
1463 * @param tmfEvent Event to parse for sequence diagram event details
1464 * @return sequence diagram event if details are available else null
1467 protected ITmfSyncSequenceDiagramEvent
getSequenceDiagramEvent(ITmfEvent tmfEvent
){
1468 //type = .*RECEIVE.* or .*SEND.*
1469 //content = sender:<sender name>:receiver:<receiver name>,signal:<signal name>
1470 String eventType
= tmfEvent
.getType().toString();
1471 if (eventType
.contains(Messages
.TmfUml2SDSyncLoader_EventTypeSend
) || eventType
.contains(Messages
.TmfUml2SDSyncLoader_EventTypeReceive
)) {
1472 Object sender
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncLoader_FieldSender
);
1473 Object receiver
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncLoader_FieldReceiver
);
1474 Object name
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncLoader_FieldSignal
);
1475 if ((sender
instanceof ITmfEventField
) && (receiver
instanceof ITmfEventField
) && (name
instanceof ITmfEventField
)) {
1476 ITmfSyncSequenceDiagramEvent sdEvent
= new TmfSyncSequenceDiagramEvent(tmfEvent
,
1477 ((ITmfEventField
) sender
).getValue().toString(),
1478 ((ITmfEventField
) receiver
).getValue().toString(),
1479 ((ITmfEventField
) name
).getValue().toString());