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
.TmfTraceSelectedSignal
;
42 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
43 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimeRange
;
44 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestamp
;
45 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
46 import org
.eclipse
.linuxtools
.tmf
.core
.uml2sd
.ITmfSyncSequenceDiagramEvent
;
47 import org
.eclipse
.linuxtools
.tmf
.core
.uml2sd
.TmfSyncSequenceDiagramEvent
;
48 import org
.eclipse
.linuxtools
.tmf
.ui
.editors
.ITmfTraceEditor
;
49 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.SDView
;
50 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Frame
;
51 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
52 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Lifeline
;
53 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.Criteria
;
54 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.FilterCriteria
;
55 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.FilterListDialog
;
56 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDAdvancedPagingProvider
;
57 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDFilterProvider
;
58 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDFindProvider
;
59 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDGraphNodeSupporter
;
60 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.load
.IUml2SDLoader
;
61 import org
.eclipse
.swt
.widgets
.Display
;
62 import org
.eclipse
.ui
.IEditorPart
;
63 import org
.eclipse
.ui
.ISelectionListener
;
64 import org
.eclipse
.ui
.IWorkbenchPart
;
65 import org
.eclipse
.ui
.IWorkbenchWindow
;
66 import org
.eclipse
.ui
.PlatformUI
;
67 import org
.eclipse
.ui
.progress
.IProgressConstants
;
71 * This class is a reference implementation of the
72 * <code>org.eclipse.linuxtools.tmf.ui.Uml2SDLoader</code> extension point. It
73 * provides a Sequence Diagram loader for a user space trace with specific trace
74 * content for sending and receiving signals between components. I also includes
75 * a default implementation for the <code>ITmfEvent</code> parsing.
78 * The class <code>TmfUml2SDSyncLoader</code> analyzes events from type
79 * <code>ITmfEvent</code> and creates events type
80 * <code>ITmfSyncSequenceDiagramEvent</code> if the <code>ITmfEvent</code>
81 * contains all relevant information. The analysis checks that the event type
82 * strings contains either string SEND or RECEIVE. If event type matches these
83 * key words, the analyzer will look for strings sender, receiver and signal in
84 * the event fields of type <code>ITmfEventField</code>. If all the data is
85 * found a sequence diagram event from can be created. Note that Sync Messages
86 * are assumed, which means start and end time are the same. <br>
88 * The parsing of the <code>ITmfEvent</code> is done in the method
89 * <code>getSequnceDiagramEvent()</code> of class
90 * <code>TmfUml2SDSyncLoader</code>. By extending the class
91 * <code>TmfUml2SDSyncLoader</code> and overwriting
92 * <code>getSequnceDiagramEvent()</code> a customized parsing algorithm can be
95 * Note that combined traces of multiple components, that contain the trace
96 * information about the same interactions are not supported in the class
97 * <code>TmfUml2SDSyncLoader</code>.
100 * @author Bernd Hufmann
102 public class TmfUml2SDSyncLoader
extends TmfComponent
implements IUml2SDLoader
, ISDFindProvider
, ISDFilterProvider
, ISDAdvancedPagingProvider
, ISelectionListener
{
104 // ------------------------------------------------------------------------
106 // ------------------------------------------------------------------------
108 * Default title name.
110 protected final static String TITLE
= Messages
.TmfUml2SDSyncLoader_ViewName
;
112 * Default block size for background request.
114 protected final static int DEFAULT_BLOCK_SIZE
= 50000;
116 * Maximum number of messages per page.
118 protected final static int MAX_NUM_OF_MSG
= 10000;
120 // ------------------------------------------------------------------------
122 // ------------------------------------------------------------------------
124 // Experiment attributes
126 * The TMF trace reference.
129 protected ITmfTrace fTrace
= 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 view and event attributes
145 * The sequence diagram view reference.
147 protected SDView fView
= null;
149 * The current sequence diagram frame reference.
151 protected Frame fFrame
= null;
153 * The list of sequence diagram events of current page.
155 protected List
<ITmfSyncSequenceDiagramEvent
> fEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>();
157 // Checkpoint and page attributes
159 * The checkpoints of the whole sequence diagram trace (i.e. start time stamp of each page)
161 protected List
<TmfTimeRange
> fCheckPoints
= new ArrayList
<TmfTimeRange
>(MAX_NUM_OF_MSG
);
163 * The current page displayed.
165 volatile protected int fCurrentPage
= 0;
167 * The current time selected.
169 protected ITmfTimestamp fCurrentTime
= null;
171 * Flag to specify that selection of message is done by selection or by signal.
173 volatile protected boolean fIsSelect
= false;
177 * The job for searching across pages.
179 protected SearchJob fFindJob
= null;
181 * List of found nodes within a page.
183 protected List
<GraphNode
> fFindResults
= new ArrayList
<GraphNode
>();
185 * The current find criteria reference
187 protected Criteria fFindCriteria
= null;
189 * The current find index within the list of found nodes (<code>fFindeResults</code> within a page.
191 volatile protected int fCurrentFindIndex
= 0;
195 * The list of active filters.
197 protected List
<FilterCriteria
> fFilterCriteria
= null;
199 // Thread synchronization
201 * The synchronization lock.
203 protected ReentrantLock fLock
= new ReentrantLock();
205 // ------------------------------------------------------------------------
207 // ------------------------------------------------------------------------
209 * Default constructor
211 public TmfUml2SDSyncLoader() {
218 * @param name Name of loader
220 public TmfUml2SDSyncLoader(String name
) {
224 // ------------------------------------------------------------------------
226 // ------------------------------------------------------------------------
229 * Returns the current time if available else null.
231 * @return the current time if available else null
234 public ITmfTimestamp
getCurrentTime() {
237 if (fCurrentTime
!= null) {
247 * Waits for the page request to be completed
249 public void waitForCompletion() {
251 ITmfEventRequest request
= fPageRequest
;
253 if (request
!= null) {
255 request
.waitForCompletion();
256 } catch (InterruptedException e
) {
263 * Signal handler for the trace selected signal.
265 * Spawns a request to index the trace (checkpoints creation) as well as it fills
268 * @param signal The trace selected signal
272 public void traceSelected(TmfTraceSelectedSignal signal
) {
274 ITmfEventRequest indexRequest
= null;
277 // Update the trace reference
278 ITmfTrace trace
= signal
.getTrace();
279 if (!trace
.equals(fTrace
)) {
285 final Job job
= new IndexingJob("Indexing " + getName() + "..."); //$NON-NLS-1$ //$NON-NLS-2$
289 indexRequest
= fIndexRequest
;
291 cancelOngoingRequests();
293 TmfTimeRange window
= TmfTimeRange
.ETERNITY
;
295 fIndexRequest
= new TmfEventRequest(ITmfEvent
.class, window
, TmfDataRequest
.ALL_DATA
, DEFAULT_BLOCK_SIZE
, ITmfDataRequest
.ExecutionType
.BACKGROUND
) {
297 private ITmfTimestamp fFirstTime
= null;
298 private ITmfTimestamp fLastTime
= null;
299 private int fNbSeqEvents
= 0;
300 private final List
<ITmfSyncSequenceDiagramEvent
> fSdEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>(MAX_NUM_OF_MSG
);
303 public void handleData(ITmfEvent event
) {
304 super.handleData(event
);
306 ITmfSyncSequenceDiagramEvent sdEvent
= getSequenceDiagramEvent(event
);
308 if (sdEvent
!= null) {
311 if (fFirstTime
== null) {
312 fFirstTime
= event
.getTimestamp();
315 fLastTime
= event
.getTimestamp();
317 if ((fNbSeqEvents
% MAX_NUM_OF_MSG
) == 0) {
320 fCheckPoints
.add(new TmfTimeRange(fFirstTime
, fLastTime
));
322 fView
.updateCoolBar();
331 if (fNbSeqEvents
> MAX_NUM_OF_MSG
) {
336 fSdEvents
.add(sdEvent
);
338 if (fNbSeqEvents
== MAX_NUM_OF_MSG
) {
339 fillCurrentPage(fSdEvents
);
345 public void handleSuccess() {
346 if ((fFirstTime
!= null) && (fLastTime
!= null)) {
350 fCheckPoints
.add(new TmfTimeRange(fFirstTime
, fLastTime
));
352 fView
.updateCoolBar();
359 if (fNbSeqEvents
<= MAX_NUM_OF_MSG
) {
360 fillCurrentPage(fSdEvents
);
363 super.handleSuccess();
367 public void handleCompleted() {
368 if (fEvents
.isEmpty()) {
369 fFrame
= new Frame();
370 fView
.setFrameSync(fFrame
);
372 super.handleCompleted();
380 if (indexRequest
!= null && !indexRequest
.isCompleted()) {
381 indexRequest
.cancel();
384 fTrace
.sendRequest(fIndexRequest
);
389 * Signal handler for the trace closed signal.
391 * @param signal The trace closed signal
395 public void traceClosed(TmfTraceClosedSignal signal
) {
396 if (signal
.getTrace() != fTrace
) {
399 ITmfEventRequest indexRequest
= null;
402 indexRequest
= fIndexRequest
;
403 fIndexRequest
= null;
405 cancelOngoingRequests();
407 if (fFilterCriteria
!= null) {
408 fFilterCriteria
.clear();
411 FilterListDialog
.deactivateSavedGlobalFilters();
416 if (indexRequest
!= null && !indexRequest
.isCompleted()) {
417 indexRequest
.cancel();
424 * Moves to the page that contains the time provided by the signal. The messages will be selected
425 * if the provided time is the time of a message.
427 * @param signal The Time synch signal.
430 public void synchToTime(TmfTimeSynchSignal signal
) {
433 if ((signal
.getSource() != this) && (fFrame
!= null) && (fCheckPoints
.size() > 0)) {
434 fCurrentTime
= signal
.getCurrentTime();
444 * Moves to the page that contains the current time provided by signal.
445 * No message will be selected however the focus will be set to the message
446 * if the provided time is the time of a message.
448 * @param signal The time range sync signal
451 public void synchToTimeRange(TmfRangeSynchSignal signal
) {
454 if ((signal
.getSource() != this) && (fFrame
!= null) && !fIsSignalSent
&& (fCheckPoints
.size() > 0)) {
455 TmfTimeRange newTimeRange
= signal
.getCurrentRange();
458 fCurrentTime
= newTimeRange
.getStartTime();
469 public void setViewer(SDView viewer
) {
474 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
475 fView
.setSDFindProvider(this);
476 fView
.setSDPagingProvider(this);
477 fView
.setSDFilterProvider(this);
481 IEditorPart editor
= fView
.getSite().getPage().getActiveEditor();
482 if (editor
instanceof ITmfTraceEditor
) {
483 ITmfTrace trace
= ((ITmfTraceEditor
) editor
).getTrace();
485 traceSelected(new TmfTraceSelectedSignal(this, trace
));
494 public String
getTitleString() {
499 public void dispose() {
501 ITmfEventRequest indexRequest
= null;
504 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
505 // During Eclipse shutdown the active workbench window is null
506 if (window
!= null) {
507 window
.getSelectionService().removePostSelectionListener(this);
510 indexRequest
= fIndexRequest
;
511 fIndexRequest
= null;
512 cancelOngoingRequests();
514 fView
.setSDFindProvider(null);
515 fView
.setSDPagingProvider(null);
516 fView
.setSDFilterProvider(null);
521 if (indexRequest
!= null && !indexRequest
.isCompleted()) {
522 indexRequest
.cancel();
527 public boolean isNodeSupported(int nodeType
) {
529 case ISDGraphNodeSupporter
.LIFELINE
:
530 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
540 public String
getNodeName(int nodeType
, String loaderClassName
) {
542 case ISDGraphNodeSupporter
.LIFELINE
:
543 return Messages
.TmfUml2SDSyncLoader_CategoryLifeline
;
544 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
545 return Messages
.TmfUml2SDSyncLoader_CategoryMessage
;
549 return ""; //$NON-NLS-1$
553 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
554 ISelection sel
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
555 if ((sel
!= null) && (sel
instanceof StructuredSelection
)) {
556 StructuredSelection stSel
= (StructuredSelection
) sel
;
557 if (stSel
.getFirstElement() instanceof TmfSyncMessage
) {
558 TmfSyncMessage syncMsg
= ((TmfSyncMessage
) stSel
.getFirstElement());
559 broadcast(new TmfTimeSynchSignal(this, syncMsg
.getStartTime()));
565 public boolean find(Criteria toSearch
) {
568 if (fFrame
== null) {
572 if ((fFindResults
== null) || (fFindCriteria
== null) || !fFindCriteria
.compareTo(toSearch
)) {
573 fFindResults
= new CopyOnWriteArrayList
<GraphNode
>();
574 fFindCriteria
= toSearch
;
575 if (fFindCriteria
.isLifeLineSelected()) {
576 for (int i
= 0; i
< fFrame
.lifeLinesCount(); i
++) {
577 if (fFindCriteria
.matches(fFrame
.getLifeline(i
).getName())) {
578 fFindResults
.add(fFrame
.getLifeline(i
));
583 ArrayList
<GraphNode
> msgs
= new ArrayList
<GraphNode
>();
584 if (fFindCriteria
.isSyncMessageSelected()) {
585 for (int i
= 0; i
< fFrame
.syncMessageCount(); i
++) {
586 if (fFindCriteria
.matches(fFrame
.getSyncMessage(i
).getName())) {
587 msgs
.add(fFrame
.getSyncMessage(i
));
592 if (!msgs
.isEmpty()) {
593 fFindResults
.addAll(msgs
);
596 @SuppressWarnings("rawtypes")
597 List selection
= fView
.getSDWidget().getSelection();
598 if ((selection
!= null) && (selection
.size() == 1)) {
599 fCurrentFindIndex
= fFindResults
.indexOf(selection
.get(0)) + 1;
601 fCurrentFindIndex
= 0;
607 if (fFindResults
.size() > fCurrentFindIndex
) {
608 GraphNode current
= fFindResults
.get(fCurrentFindIndex
);
609 fView
.getSDWidget().moveTo(current
);
613 fCurrentFindIndex
=0;
614 return findInNextPages(fFindCriteria
); // search in other page
621 public void cancel() {
622 cancelOngoingRequests();
625 @SuppressWarnings("unchecked")
627 public boolean filter(List
<?
> filters
) {
630 cancelOngoingRequests();
632 if (filters
== null) {
633 fFilterCriteria
= new ArrayList
<FilterCriteria
>();
635 List
<FilterCriteria
> list
= (List
<FilterCriteria
>)filters
;
636 fFilterCriteria
= new ArrayList
<FilterCriteria
>(list
);
639 fillCurrentPage(fEvents
);
648 public boolean hasNextPage() {
651 int size
= fCheckPoints
.size();
653 return fCurrentPage
< (size
- 1);
662 public boolean hasPrevPage() {
665 return fCurrentPage
> 0;
672 public void nextPage() {
676 if (fCurrentPage
>= (fCheckPoints
.size() - 1)) {
680 cancelOngoingRequests();
690 public void prevPage() {
694 if (fCurrentPage
<= 0) {
698 cancelOngoingRequests();
708 public void firstPage() {
712 cancelOngoingRequests();
722 public void lastPage() {
725 cancelOngoingRequests();
727 fCurrentPage
= fCheckPoints
.size() - 1;
735 public int currentPage() {
745 public int pagesCount() {
748 return fCheckPoints
.size();
755 public void pageNumberChanged(int pagenNumber
) {
756 int localPageNumber
= pagenNumber
;
760 cancelOngoingRequests();
762 if (localPageNumber
< 0) {
765 int size
= fCheckPoints
.size();
766 if (localPageNumber
> (size
- 1)) {
767 localPageNumber
= size
- 1;
769 fCurrentPage
= localPageNumber
;
777 public void broadcast(TmfSignal signal
) {
778 fIsSignalSent
= true;
779 super.broadcast(signal
);
780 fIsSignalSent
= false;
784 * Cancels any ongoing find operation
786 protected void cancelOngoingRequests() {
788 ITmfEventRequest pageRequest
= null;
790 // Cancel the search thread
791 if (fFindJob
!= null) {
796 fFindCriteria
= null;
797 fCurrentFindIndex
= 0;
799 pageRequest
= fPageRequest
;
804 if (pageRequest
!= null && !pageRequest
.isCompleted()) {
805 pageRequest
.cancel();
810 * Resets loader attributes
812 protected void resetLoader() {
817 fCheckPoints
.clear();
819 fCurrentFindIndex
= 0;
820 fFindCriteria
= null;
822 fView
.setFrameSync(new Frame());
832 * Fills current page with sequence diagram content.
834 * @param events sequence diagram events
836 protected void fillCurrentPage(List
<ITmfSyncSequenceDiagramEvent
> events
) {
840 fEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>(events
);
841 if (fView
!= null && !events
.isEmpty()) {
842 fView
.toggleWaitCursorAsync(true);
848 final Frame frame
= new Frame();
850 if (!events
.isEmpty()) {
851 Map
<String
, Lifeline
> nodeToLifelineMap
= new HashMap
<String
, Lifeline
>();
853 frame
.setName(Messages
.TmfUml2SDSyncLoader_FrameName
);
855 for (int i
= 0; i
< events
.size(); i
++) {
857 ITmfSyncSequenceDiagramEvent sdEvent
= events
.get(i
);
859 if ((nodeToLifelineMap
.get(sdEvent
.getSender()) == null) && (!filterLifeLine(sdEvent
.getSender()))) {
860 Lifeline lifeline
= new Lifeline();
861 lifeline
.setName(sdEvent
.getSender());
862 nodeToLifelineMap
.put(sdEvent
.getSender(), lifeline
);
863 frame
.addLifeLine(lifeline
);
866 if ((nodeToLifelineMap
.get(sdEvent
.getReceiver()) == null) && (!filterLifeLine(sdEvent
.getReceiver()))) {
867 Lifeline lifeline
= new Lifeline();
868 lifeline
.setName(sdEvent
.getReceiver());
869 nodeToLifelineMap
.put(sdEvent
.getReceiver(), lifeline
);
870 frame
.addLifeLine(lifeline
);
874 int eventOccurence
= 1;
876 for (int i
= 0; i
< events
.size(); i
++) {
877 ITmfSyncSequenceDiagramEvent sdEvent
= events
.get(i
);
879 // Check message filter
880 if (filterMessage(sdEvent
)) {
884 // Set the message sender and receiver
885 Lifeline startLifeline
= nodeToLifelineMap
.get(sdEvent
.getSender());
886 Lifeline endLifeline
= nodeToLifelineMap
.get(sdEvent
.getReceiver());
888 // Check if any of the lifelines were filtered
889 if ((startLifeline
== null) || (endLifeline
== null)) {
893 int tmp
= Math
.max(startLifeline
.getEventOccurrence(), endLifeline
.getEventOccurrence());
894 eventOccurence
= Math
.max(eventOccurence
, tmp
);
896 startLifeline
.setCurrentEventOccurrence(eventOccurence
);
897 endLifeline
.setCurrentEventOccurrence(eventOccurence
);
899 TmfSyncMessage message
= new TmfSyncMessage(sdEvent
, eventOccurence
++);
901 message
.setStartLifeline(startLifeline
);
902 message
.setEndLifeline(endLifeline
);
904 message
.setTime(sdEvent
.getStartTime());
906 // add the message to the frame
907 frame
.addMessage(message
);
912 if (!fView
.getSDWidget().isDisposed()) {
913 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
920 // check if view was disposed in the meanwhile
921 if ((fView
!= null) && (!fView
.getSDWidget().isDisposed())) {
923 fView
.setFrame(fFrame
);
925 if (fCurrentTime
!= null) {
926 moveToMessageInPage();
929 if (fFindCriteria
!= null) {
933 fView
.toggleWaitCursorAsync(false);
950 * Moves to a certain message defined by timestamp (across pages)
952 protected void moveToMessage() {
957 page
= getPage(fCurrentTime
);
959 if (page
== fCurrentPage
) {
960 moveToMessageInPage();
971 * Moves to a certain message defined by timestamp in current page
973 protected void moveToMessageInPage() {
976 if (!fView
.getSDWidget().isDisposed()) {
977 // Check for GUI thread
978 if(Display
.getCurrent() != null) {
979 // Already in GUI thread - execute directly
980 TmfSyncMessage prevMessage
= null;
981 TmfSyncMessage syncMessage
= null;
982 boolean isExactTime
= false;
983 for (int i
= 0; i
< fFrame
.syncMessageCount(); i
++) {
984 if (fFrame
.getSyncMessage(i
) instanceof TmfSyncMessage
) {
985 syncMessage
= (TmfSyncMessage
) fFrame
.getSyncMessage(i
);
986 if (syncMessage
.getStartTime().compareTo(fCurrentTime
, false) == 0) {
989 } else if ((syncMessage
.getStartTime().compareTo(fCurrentTime
, false) > 0) && (prevMessage
!= null)) {
990 syncMessage
= prevMessage
;
993 prevMessage
= syncMessage
;
996 if (fIsSelect
&& isExactTime
) {
997 fView
.getSDWidget().moveTo(syncMessage
);
1000 fView
.getSDWidget().ensureVisible(syncMessage
);
1001 fView
.getSDWidget().clearSelection();
1002 fView
.getSDWidget().redraw();
1006 // Not in GUI thread - queue action in GUI thread.
1007 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1010 moveToMessageInPage();
1022 * Moves to a certain message defined by timestamp (across pages)
1024 protected void moveToPage() {
1029 * Moves to a certain page.
1031 * @param notifyAll true to broadcast time range signal to other signal handlers else false
1033 protected void moveToPage(boolean notifyAll
) {
1035 TmfTimeRange window
= null;
1040 if (fCurrentPage
> fCheckPoints
.size()) {
1043 window
= fCheckPoints
.get(fCurrentPage
);
1048 if (window
== null) {
1049 window
= TmfTimeRange
.ETERNITY
;
1052 fPageRequest
= new TmfEventRequest(ITmfEvent
.class, window
, TmfDataRequest
.ALL_DATA
, 1, ITmfDataRequest
.ExecutionType
.FOREGROUND
) {
1053 private final List
<ITmfSyncSequenceDiagramEvent
> fSdEvent
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>();
1056 public void handleData(ITmfEvent event
) {
1057 super.handleData(event
);
1059 ITmfSyncSequenceDiagramEvent sdEvent
= getSequenceDiagramEvent(event
);
1061 if (sdEvent
!= null) {
1062 fSdEvent
.add(sdEvent
);
1067 public void handleSuccess() {
1068 fillCurrentPage(fSdEvent
);
1069 super.handleSuccess();
1074 fTrace
.sendRequest(fPageRequest
);
1077 TmfTimeRange timeRange
= getSignalTimeRange(window
.getStartTime());
1078 broadcast(new TmfRangeSynchSignal(this, timeRange
, timeRange
.getStartTime()));
1083 * Gets page that contains timestamp
1085 * @param time The timestamp
1086 * @return page that contains the time
1089 protected int getPage(ITmfTimestamp time
) {
1094 size
= fCheckPoints
.size();
1095 for (page
= 0; page
< size
; page
++) {
1096 TmfTimeRange timeRange
= fCheckPoints
.get(page
);
1097 if (timeRange
.getEndTime().compareTo(time
, false) >= 0) {
1111 * Background search in trace for expression in criteria.
1113 * @param findCriteria The find criteria
1114 * @return true if background request was started else false
1116 protected boolean findInNextPages(Criteria findCriteria
) {
1119 if (fFindJob
!= null) {
1123 int nextPage
= fCurrentPage
+ 1;
1125 if ((nextPage
) >= fCheckPoints
.size()) {
1126 // we are at the end
1130 TmfTimeRange window
= new TmfTimeRange(fCheckPoints
.get(nextPage
).getStartTime(), fCheckPoints
.get(fCheckPoints
.size()-1).getEndTime());
1131 fFindJob
= new SearchJob(findCriteria
, window
);
1132 fFindJob
.schedule();
1133 fView
.toggleWaitCursorAsync(true);
1141 * Gets time range for time range signal.
1143 * @param startTime The start time of time range.
1144 * @return the time range
1147 protected TmfTimeRange
getSignalTimeRange(ITmfTimestamp startTime
) {
1150 long offset
= fTrace
== null ?
0 : fTrace
.getCurrentRange().getEndTime().getDelta(fTrace
.getCurrentRange().getStartTime()).normalize(0, startTime
.getScale()).getValue();
1151 TmfTimestamp initialEndOfWindow
= new TmfTimestamp(startTime
.getValue() + offset
, startTime
.getScale(), startTime
.getPrecision());
1152 return new TmfTimeRange(startTime
, initialEndOfWindow
);
1160 * Checks if filter criteria matches the message name in given SD event.
1162 * @param sdEvent The SD event to check
1163 * @return true if match else false.
1165 protected boolean filterMessage(ITmfSyncSequenceDiagramEvent sdEvent
) {
1168 if (fFilterCriteria
!= null) {
1169 for(FilterCriteria criteria
: fFilterCriteria
) {
1170 if (criteria
.isActive() && criteria
.getCriteria().isSyncMessageSelected() && criteria
.getCriteria().matches(sdEvent
.getName())) {
1182 * Checks if filter criteria matches a lifeline name (sender or receiver) in given SD event.
1184 * @param lifeline the message receiver
1185 * @return true if match else false.
1187 protected boolean filterLifeLine(String lifeline
) {
1190 if (fFilterCriteria
!= null) {
1191 for(FilterCriteria criteria
: fFilterCriteria
) {
1192 if (criteria
.isActive() && criteria
.getCriteria().isLifeLineSelected() && criteria
.getCriteria().matches(lifeline
)) {
1204 * Job to search in trace for given time range.
1206 protected class SearchJob
extends Job
{
1209 * The search event request.
1211 final protected SearchEventRequest fSearchRequest
;
1216 * @param findCriteria The search criteria
1217 * @param window Time range to search in
1220 public SearchJob(Criteria findCriteria
, TmfTimeRange window
) {
1221 super(Messages
.TmfUml2SDSyncLoader_SearchJobDescrition
);
1222 fSearchRequest
= new SearchEventRequest(window
, TmfDataRequest
.ALL_DATA
, 1, ITmfDataRequest
.ExecutionType
.FOREGROUND
, findCriteria
);
1226 protected IStatus
run(IProgressMonitor monitor
) {
1227 fSearchRequest
.setMonitor(monitor
);
1229 fTrace
.sendRequest(fSearchRequest
);
1232 fSearchRequest
.waitForCompletion();
1233 } catch (InterruptedException e
) {
1234 Activator
.getDefault().logError("Search request interrupted!", e
); //$NON-NLS-1$
1237 IStatus status
= Status
.OK_STATUS
;
1238 if (fSearchRequest
.isFound() && (fSearchRequest
.getFoundTime() != null)) {
1239 fCurrentTime
= fSearchRequest
.getFoundTime();
1241 // Avoid double-selection. Selection will be done when calling find(criteria)
1242 // after moving to relevant page
1244 if (!fView
.getSDWidget().isDisposed()) {
1245 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1255 if (monitor
.isCanceled()) {
1256 status
= Status
.CANCEL_STATUS
;
1259 // String was not found
1260 status
= new Status(IStatus
.WARNING
, Activator
.PLUGIN_ID
, Messages
.TmfUml2SDSyncLoader_SearchNotFound
);
1262 setProperty(IProgressConstants
.KEEP_PROPERTY
, Boolean
.TRUE
);
1268 fView
.toggleWaitCursorAsync(false);
1278 protected void canceling() {
1279 fSearchRequest
.cancel();
1290 * TMF event request for searching within trace.
1292 protected class SearchEventRequest
extends TmfEventRequest
{
1295 * The find criteria.
1297 final private Criteria fCriteria
;
1299 * A progress monitor
1301 private IProgressMonitor fMonitor
;
1303 * Flag to indicate that node was found according the criteria .
1305 private boolean fIsFound
= false;
1307 * Time stamp of found item.
1309 private ITmfTimestamp fFoundTime
= null;
1313 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1314 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1315 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1316 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1317 * @param criteria The search criteria
1319 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType execType
, Criteria criteria
) {
1320 this(range
, nbRequested
, blockSize
, execType
, criteria
, null);
1325 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1326 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1327 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1328 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1329 * @param criteria The search criteria
1330 * @param monitor progress monitor
1332 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType execType
, Criteria criteria
, IProgressMonitor monitor
) {
1333 super(ITmfEvent
.class, range
, nbRequested
, blockSize
, execType
);
1334 fCriteria
= new Criteria(criteria
);
1339 public void handleData(ITmfEvent event
) {
1340 super.handleData(event
);
1342 if ((fMonitor
!= null) && fMonitor
.isCanceled()) {
1347 ITmfSyncSequenceDiagramEvent sdEvent
= getSequenceDiagramEvent(event
);
1349 if (sdEvent
!= null) {
1351 if (fCriteria
.isLifeLineSelected()) {
1352 if (fCriteria
.matches(sdEvent
.getSender())) {
1353 fFoundTime
= event
.getTimestamp();
1358 if (fCriteria
.matches(sdEvent
.getReceiver())) {
1359 fFoundTime
= event
.getTimestamp();
1365 if (fCriteria
.isSyncMessageSelected() && fCriteria
.matches(sdEvent
.getName())) {
1366 fFoundTime
= event
.getTimestamp();
1374 * Set progress monitor.
1376 * @param monitor The monitor to assign
1378 public void setMonitor(IProgressMonitor monitor
) {
1383 * Check if find criteria was met.
1385 * @return true if find criteria was met.
1387 public boolean isFound() {
1392 * Returns timestamp of found time.
1394 * @return timestamp of found time.
1397 public ITmfTimestamp
getFoundTime() {
1403 * Job class to provide progress monitor feedback.
1406 * @author Bernd Hufmann
1409 protected static class IndexingJob
extends Job
{
1412 * @param name The job name
1414 public IndexingJob(String name
) {
1419 protected IStatus
run(IProgressMonitor monitor
) {
1420 while (!monitor
.isCanceled()) {
1423 } catch (InterruptedException e
) {
1424 return Status
.OK_STATUS
;
1428 return Status
.OK_STATUS
;
1434 * Returns sequence diagram event if details in given event are available else null.
1436 * @param tmfEvent Event to parse for sequence diagram event details
1437 * @return sequence diagram event if details are available else null
1440 protected ITmfSyncSequenceDiagramEvent
getSequenceDiagramEvent(ITmfEvent tmfEvent
){
1441 //type = .*RECEIVE.* or .*SEND.*
1442 //content = sender:<sender name>:receiver:<receiver name>,signal:<signal name>
1443 String eventType
= tmfEvent
.getType().toString();
1444 if (eventType
.contains(Messages
.TmfUml2SDSyncLoader_EventTypeSend
) || eventType
.contains(Messages
.TmfUml2SDSyncLoader_EventTypeReceive
)) {
1445 Object sender
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncLoader_FieldSender
);
1446 Object receiver
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncLoader_FieldReceiver
);
1447 Object name
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncLoader_FieldSignal
);
1448 if ((sender
instanceof ITmfEventField
) && (receiver
instanceof ITmfEventField
) && (name
instanceof ITmfEventField
)) {
1449 ITmfSyncSequenceDiagramEvent sdEvent
= new TmfSyncSequenceDiagramEvent(tmfEvent
,
1450 ((ITmfEventField
) sender
).getValue().toString(),
1451 ((ITmfEventField
) receiver
).getValue().toString(),
1452 ((ITmfEventField
) name
).getValue().toString());