1 /**********************************************************************
2 * Copyright (c) 2011, 2015 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
.tracecompass
.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
.swt
.widgets
.Display
;
29 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.component
.TmfComponent
;
31 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
32 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
33 import org
.eclipse
.tracecompass
.tmf
.core
.request
.ITmfEventRequest
;
34 import org
.eclipse
.tracecompass
.tmf
.core
.request
.ITmfEventRequest
.ExecutionType
;
35 import org
.eclipse
.tracecompass
.tmf
.core
.request
.TmfEventRequest
;
36 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfWindowRangeUpdatedSignal
;
37 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignal
;
38 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
39 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSelectionRangeUpdatedSignal
;
40 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceClosedSignal
;
41 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceOpenedSignal
;
42 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
43 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
44 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
45 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
46 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
47 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
48 import org
.eclipse
.tracecompass
.tmf
.core
.uml2sd
.ITmfSyncSequenceDiagramEvent
;
49 import org
.eclipse
.tracecompass
.tmf
.core
.uml2sd
.TmfSyncSequenceDiagramEvent
;
50 import org
.eclipse
.tracecompass
.tmf
.ui
.editors
.ITmfTraceEditor
;
51 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.SDView
;
52 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.core
.Frame
;
53 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
54 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.core
.Lifeline
;
55 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.dialogs
.Criteria
;
56 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.dialogs
.FilterCriteria
;
57 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.dialogs
.FilterListDialog
;
58 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDAdvancedPagingProvider
;
59 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDFilterProvider
;
60 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDFindProvider
;
61 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDGraphNodeSupporter
;
62 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.load
.IUml2SDLoader
;
63 import org
.eclipse
.ui
.IEditorPart
;
64 import org
.eclipse
.ui
.ISelectionListener
;
65 import org
.eclipse
.ui
.IWorkbenchPart
;
66 import org
.eclipse
.ui
.IWorkbenchWindow
;
67 import org
.eclipse
.ui
.PlatformUI
;
68 import org
.eclipse
.ui
.progress
.IProgressConstants
;
72 * This class is a reference implementation of the
73 * <code>org.eclipse.tracecompass.tmf.ui.Uml2SDLoader</code> extension point. It
74 * provides a Sequence Diagram loader for a user space trace with specific trace
75 * content for sending and receiving signals between components. I also includes
76 * a default implementation for the <code>ITmfEvent</code> parsing.
79 * The class <code>TmfUml2SDSyncLoader</code> analyzes events from type
80 * <code>ITmfEvent</code> and creates events type
81 * <code>ITmfSyncSequenceDiagramEvent</code> if the <code>ITmfEvent</code>
82 * contains all relevant information. The analysis checks that the event type
83 * strings contains either string SEND or RECEIVE. If event type matches these
84 * key words, the analyzer will look for strings sender, receiver and signal in
85 * the event fields of type <code>ITmfEventField</code>. If all the data is
86 * found a sequence diagram event from can be created. Note that Sync Messages
87 * are assumed, which means start and end time are the same. <br>
89 * The parsing of the <code>ITmfEvent</code> is done in the method
90 * <code>getSequnceDiagramEvent()</code> of class
91 * <code>TmfUml2SDSyncLoader</code>. By extending the class
92 * <code>TmfUml2SDSyncLoader</code> and overwriting
93 * <code>getSequnceDiagramEvent()</code> a customized parsing algorithm can be
96 * Note that combined traces of multiple components, that contain the trace
97 * information about the same interactions are not supported in the class
98 * <code>TmfUml2SDSyncLoader</code>.
101 * @author Bernd Hufmann
103 public class TmfUml2SDSyncLoader
extends TmfComponent
implements IUml2SDLoader
, ISDFindProvider
, ISDFilterProvider
, ISDAdvancedPagingProvider
, ISelectionListener
{
105 // ------------------------------------------------------------------------
107 // ------------------------------------------------------------------------
110 * Default title name.
112 protected static final String TITLE
= Messages
.TmfUml2SDSyncLoader_ViewName
;
115 * Maximum number of messages per page.
117 protected static final int MAX_NUM_OF_MSG
= 10000;
119 private static final int INDEXING_THREAD_SLEEP_VALUE
= 100;
121 // ------------------------------------------------------------------------
123 // ------------------------------------------------------------------------
125 // Experiment attributes
127 * 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 protected volatile 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
<>();
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
<>(MAX_NUM_OF_MSG
);
163 * The current page displayed.
165 protected volatile 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 protected volatile 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
<>();
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 protected volatile 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
233 public ITmfTimestamp
getCurrentTime() {
236 if (fCurrentTime
!= null) {
246 * Waits for the page request to be completed
248 public void waitForCompletion() {
250 ITmfEventRequest request
= fPageRequest
;
252 if (request
!= null) {
254 request
.waitForCompletion();
255 } catch (InterruptedException e
) {
262 * Handler for the trace opened signal.
263 * @param signal The trace opened signal
266 public void traceOpened(TmfTraceOpenedSignal signal
) {
267 fTrace
= signal
.getTrace();
273 * Signal handler for the trace selected signal.
275 * Spawns a request to index the trace (checkpoints creation) as well as it fills
278 * @param signal The trace selected signal
281 public void traceSelected(TmfTraceSelectedSignal signal
) {
282 // Update the trace reference
283 ITmfTrace trace
= signal
.getTrace();
284 if (!trace
.equals(fTrace
)) {
291 * Method for loading the current selected trace into the view.
292 * Sub-class need to override this method to add the view specific implementation.
294 protected void loadTrace() {
295 ITmfEventRequest indexRequest
= null;
299 final Job job
= new IndexingJob("Indexing " + getName() + "..."); //$NON-NLS-1$ //$NON-NLS-2$
303 indexRequest
= fIndexRequest
;
305 cancelOngoingRequests();
307 TmfTimeRange window
= TmfTimeRange
.ETERNITY
;
309 fIndexRequest
= new TmfEventRequest(ITmfEvent
.class, window
, 0,
310 ITmfEventRequest
.ALL_DATA
, ITmfEventRequest
.ExecutionType
.BACKGROUND
) {
312 private ITmfTimestamp fFirstTime
= null;
313 private ITmfTimestamp fLastTime
= null;
314 private int fNbSeqEvents
= 0;
315 private final List
<ITmfSyncSequenceDiagramEvent
> fSdEvents
= new ArrayList
<>(MAX_NUM_OF_MSG
);
318 public void handleData(ITmfEvent event
) {
319 super.handleData(event
);
321 ITmfSyncSequenceDiagramEvent sdEvent
= getSequenceDiagramEvent(event
);
322 ITmfTimestamp firstTime
= fFirstTime
;
323 ITmfTimestamp lastTime
= fLastTime
;
325 if (sdEvent
!= null) {
328 if (firstTime
== null) {
329 firstTime
= event
.getTimestamp();
330 fFirstTime
= firstTime
;
333 lastTime
= event
.getTimestamp();
334 fLastTime
= lastTime
;
336 if ((fNbSeqEvents
% MAX_NUM_OF_MSG
) == 0) {
339 fCheckPoints
.add(new TmfTimeRange(firstTime
, lastTime
));
341 fView
.updateCoolBar();
350 if (fNbSeqEvents
> MAX_NUM_OF_MSG
) {
355 fSdEvents
.add(sdEvent
);
357 if (fNbSeqEvents
== MAX_NUM_OF_MSG
) {
358 fillCurrentPage(fSdEvents
);
364 public void handleSuccess() {
365 final ITmfTimestamp firstTime
= fFirstTime
;
366 final ITmfTimestamp lastTime
= fLastTime
;
367 if ((firstTime
!= null) && (lastTime
!= null)) {
371 fCheckPoints
.add(new TmfTimeRange(firstTime
, lastTime
));
373 fView
.updateCoolBar();
380 if (fNbSeqEvents
<= MAX_NUM_OF_MSG
) {
381 fillCurrentPage(fSdEvents
);
384 super.handleSuccess();
388 public void handleCompleted() {
389 if (fEvents
.isEmpty()) {
390 fFrame
= new Frame();
391 // make sure that view is not null when setting frame
399 if (sdView
!= null) {
400 sdView
.setFrameSync(fFrame
);
403 super.handleCompleted();
411 if (indexRequest
!= null && !indexRequest
.isCompleted()) {
412 indexRequest
.cancel();
415 fTrace
.sendRequest(fIndexRequest
);
419 * Signal handler for the trace closed signal.
421 * @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
454 * messages will be selected if the provided time is the time of a message.
457 * The selection range signal
461 public void selectionRangeUpdated(TmfSelectionRangeUpdatedSignal signal
) {
464 if ((signal
.getSource() != this) && (fFrame
!= null) && (fCheckPoints
.size() > 0)) {
465 fCurrentTime
= signal
.getBeginTime();
475 * Moves to the page that contains the current time provided by signal. No
476 * message will be selected however the focus will be set to the message if
477 * the provided time is the time of a message.
480 * The window range signal
484 public void windowRangeUpdated(TmfWindowRangeUpdatedSignal signal
) {
487 if ((signal
.getSource() != this) && (fFrame
!= null) && !fIsSignalSent
&& (fCheckPoints
.size() > 0)) {
488 TmfTimeRange newTimeRange
= signal
.getCurrentRange();
491 fCurrentTime
= newTimeRange
.getStartTime();
502 public void setViewer(SDView viewer
) {
507 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
508 fView
.setSDFindProvider(this);
509 fView
.setSDPagingProvider(this);
510 fView
.setSDFilterProvider(this);
513 IEditorPart editor
= fView
.getSite().getPage().getActiveEditor();
514 if (editor
instanceof ITmfTraceEditor
) {
515 ITmfTrace trace
= ((ITmfTraceEditor
) editor
).getTrace();
517 traceSelected(new TmfTraceSelectedSignal(this, trace
));
526 public String
getTitleString() {
531 public void dispose() {
533 ITmfEventRequest indexRequest
= null;
536 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
537 // During Eclipse shutdown the active workbench window is null
538 if (window
!= null) {
539 window
.getSelectionService().removePostSelectionListener(this);
542 indexRequest
= fIndexRequest
;
543 fIndexRequest
= null;
544 cancelOngoingRequests();
546 fView
.setSDFindProvider(null);
547 fView
.setSDPagingProvider(null);
548 fView
.setSDFilterProvider(null);
553 if (indexRequest
!= null && !indexRequest
.isCompleted()) {
554 indexRequest
.cancel();
559 public boolean isNodeSupported(int nodeType
) {
561 case ISDGraphNodeSupporter
.LIFELINE
:
562 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
572 public String
getNodeName(int nodeType
, String loaderClassName
) {
574 case ISDGraphNodeSupporter
.LIFELINE
:
575 return Messages
.TmfUml2SDSyncLoader_CategoryLifeline
;
576 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
577 return Messages
.TmfUml2SDSyncLoader_CategoryMessage
;
581 return ""; //$NON-NLS-1$
585 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
586 ISelection sel
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
587 if ((sel
!= null) && (sel
instanceof StructuredSelection
)) {
588 StructuredSelection stSel
= (StructuredSelection
) sel
;
589 if (stSel
.getFirstElement() instanceof TmfSyncMessage
) {
590 TmfSyncMessage syncMsg
= ((TmfSyncMessage
) stSel
.getFirstElement());
591 ITmfTimestamp startTime
= syncMsg
.getStartTime();
592 if (startTime
== null) {
593 startTime
= TmfTimestamp
.BIG_BANG
;
595 broadcast(new TmfSelectionRangeUpdatedSignal(this, startTime
));
601 public boolean find(Criteria toSearch
) {
604 if (fFrame
== null) {
608 if ((fFindResults
== null) || (fFindCriteria
== null) || !fFindCriteria
.compareTo(toSearch
)) {
609 fFindResults
= new CopyOnWriteArrayList
<>();
610 fFindCriteria
= toSearch
;
611 if (fFindCriteria
.isLifeLineSelected()) {
612 for (int i
= 0; i
< fFrame
.lifeLinesCount(); i
++) {
613 if (fFindCriteria
.matches(fFrame
.getLifeline(i
).getName())) {
614 fFindResults
.add(fFrame
.getLifeline(i
));
619 ArrayList
<GraphNode
> msgs
= new ArrayList
<>();
620 if (fFindCriteria
.isSyncMessageSelected()) {
621 for (int i
= 0; i
< fFrame
.syncMessageCount(); i
++) {
622 if (fFindCriteria
.matches(fFrame
.getSyncMessage(i
).getName())) {
623 msgs
.add(fFrame
.getSyncMessage(i
));
628 if (!msgs
.isEmpty()) {
629 fFindResults
.addAll(msgs
);
632 List
<GraphNode
> selection
= fView
.getSDWidget().getSelection();
633 if ((selection
!= null) && (selection
.size() == 1)) {
634 fCurrentFindIndex
= fFindResults
.indexOf(selection
.get(0)) + 1;
636 fCurrentFindIndex
= 0;
642 if (fFindResults
.size() > fCurrentFindIndex
) {
643 GraphNode current
= fFindResults
.get(fCurrentFindIndex
);
644 fView
.getSDWidget().moveTo(current
);
648 fCurrentFindIndex
=0;
649 return findInNextPages(fFindCriteria
); // search in other page
656 public void cancel() {
657 cancelOngoingRequests();
661 public boolean filter(List
<FilterCriteria
> filters
) {
664 cancelOngoingRequests();
666 if (filters
== null) {
667 fFilterCriteria
= new ArrayList
<>();
669 List
<FilterCriteria
> list
= filters
;
670 fFilterCriteria
= new ArrayList
<>(list
);
673 fillCurrentPage(fEvents
);
682 public boolean hasNextPage() {
685 int size
= fCheckPoints
.size();
687 return fCurrentPage
< (size
- 1);
696 public boolean hasPrevPage() {
699 return fCurrentPage
> 0;
706 public void nextPage() {
710 if (fCurrentPage
>= (fCheckPoints
.size() - 1)) {
714 cancelOngoingRequests();
724 public void prevPage() {
728 if (fCurrentPage
<= 0) {
732 cancelOngoingRequests();
742 public void firstPage() {
746 cancelOngoingRequests();
756 public void lastPage() {
759 cancelOngoingRequests();
761 fCurrentPage
= fCheckPoints
.size() - 1;
769 public int currentPage() {
779 public int pagesCount() {
782 return fCheckPoints
.size();
789 public void pageNumberChanged(int pagenNumber
) {
790 int localPageNumber
= pagenNumber
;
794 cancelOngoingRequests();
796 if (localPageNumber
< 0) {
799 int size
= fCheckPoints
.size();
800 if (localPageNumber
> (size
- 1)) {
801 localPageNumber
= size
- 1;
803 fCurrentPage
= localPageNumber
;
811 public void broadcast(TmfSignal signal
) {
812 fIsSignalSent
= true;
813 super.broadcast(signal
);
814 fIsSignalSent
= false;
818 * Cancels any ongoing find operation
820 protected void cancelOngoingRequests() {
822 ITmfEventRequest pageRequest
= null;
824 // Cancel the search thread
825 if (fFindJob
!= null) {
830 fFindCriteria
= null;
831 fCurrentFindIndex
= 0;
833 pageRequest
= fPageRequest
;
838 if (pageRequest
!= null && !pageRequest
.isCompleted()) {
839 pageRequest
.cancel();
844 * Resets loader attributes
846 protected void resetLoader() {
851 fCheckPoints
.clear();
853 fCurrentFindIndex
= 0;
854 fFindCriteria
= null;
856 fView
.setFrameSync(new Frame());
866 * Fills current page with sequence diagram content.
868 * @param events sequence diagram events
870 protected void fillCurrentPage(List
<ITmfSyncSequenceDiagramEvent
> events
) {
874 fEvents
= new ArrayList
<>(events
);
875 if (fView
!= null && !events
.isEmpty()) {
876 fView
.toggleWaitCursorAsync(true);
882 final Frame frame
= new Frame();
884 if (!events
.isEmpty()) {
885 Map
<String
, Lifeline
> nodeToLifelineMap
= new HashMap
<>();
887 frame
.setName(Messages
.TmfUml2SDSyncLoader_FrameName
);
889 for (int i
= 0; i
< events
.size(); i
++) {
891 ITmfSyncSequenceDiagramEvent sdEvent
= events
.get(i
);
893 if ((nodeToLifelineMap
.get(sdEvent
.getSender()) == null) && (!filterLifeLine(sdEvent
.getSender()))) {
894 Lifeline lifeline
= new Lifeline();
895 lifeline
.setName(sdEvent
.getSender());
896 nodeToLifelineMap
.put(sdEvent
.getSender(), lifeline
);
897 frame
.addLifeLine(lifeline
);
900 if ((nodeToLifelineMap
.get(sdEvent
.getReceiver()) == null) && (!filterLifeLine(sdEvent
.getReceiver()))) {
901 Lifeline lifeline
= new Lifeline();
902 lifeline
.setName(sdEvent
.getReceiver());
903 nodeToLifelineMap
.put(sdEvent
.getReceiver(), lifeline
);
904 frame
.addLifeLine(lifeline
);
908 int eventOccurence
= 1;
910 for (int i
= 0; i
< events
.size(); i
++) {
911 ITmfSyncSequenceDiagramEvent sdEvent
= events
.get(i
);
913 // Check message filter
914 if (filterMessage(sdEvent
)) {
918 // Set the message sender and receiver
919 Lifeline startLifeline
= nodeToLifelineMap
.get(sdEvent
.getSender());
920 Lifeline endLifeline
= nodeToLifelineMap
.get(sdEvent
.getReceiver());
922 // Check if any of the lifelines were filtered
923 if ((startLifeline
== null) || (endLifeline
== null)) {
927 int tmp
= Math
.max(startLifeline
.getEventOccurrence(), endLifeline
.getEventOccurrence());
928 eventOccurence
= Math
.max(eventOccurence
, tmp
);
930 startLifeline
.setCurrentEventOccurrence(eventOccurence
);
931 endLifeline
.setCurrentEventOccurrence(eventOccurence
);
933 TmfSyncMessage message
= new TmfSyncMessage(sdEvent
, eventOccurence
++);
935 message
.setStartLifeline(startLifeline
);
936 message
.setEndLifeline(endLifeline
);
938 message
.setTime(sdEvent
.getStartTime());
940 // add the message to the frame
941 frame
.addMessage(message
);
946 if (!fView
.getSDWidget().isDisposed()) {
947 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
954 // check if view was disposed in the meanwhile
955 if ((fView
!= null) && (!fView
.getSDWidget().isDisposed())) {
957 fView
.setFrame(fFrame
);
959 if (fCurrentTime
!= null) {
960 moveToMessageInPage();
963 if (fFindCriteria
!= null) {
967 fView
.toggleWaitCursorAsync(false);
984 * Moves to a certain message defined by timestamp (across pages)
986 protected void moveToMessage() {
991 page
= getPage(fCurrentTime
);
993 if (page
== fCurrentPage
) {
994 moveToMessageInPage();
1005 * Moves to a certain message defined by timestamp in current page
1007 protected void moveToMessageInPage() {
1010 if (!fView
.getSDWidget().isDisposed()) {
1011 // Check for GUI thread
1012 if(Display
.getCurrent() != null) {
1013 // Already in GUI thread - execute directly
1014 TmfSyncMessage prevMessage
= null;
1015 TmfSyncMessage syncMessage
= null;
1016 boolean isExactTime
= false;
1017 for (int i
= 0; i
< fFrame
.syncMessageCount(); i
++) {
1018 if (fFrame
.getSyncMessage(i
) instanceof TmfSyncMessage
) {
1019 syncMessage
= (TmfSyncMessage
) fFrame
.getSyncMessage(i
);
1020 if (syncMessage
.getStartTime().compareTo(fCurrentTime
) == 0) {
1023 } else if ((syncMessage
.getStartTime().compareTo(fCurrentTime
) > 0) && (prevMessage
!= null)) {
1024 syncMessage
= prevMessage
;
1027 prevMessage
= syncMessage
;
1030 if (fIsSelect
&& isExactTime
) {
1031 fView
.getSDWidget().moveTo(syncMessage
);
1034 fView
.getSDWidget().ensureVisible(syncMessage
);
1035 fView
.getSDWidget().clearSelection();
1036 fView
.getSDWidget().redraw();
1040 // Not in GUI thread - queue action in GUI thread.
1041 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1044 moveToMessageInPage();
1056 * Moves to a certain message defined by timestamp (across pages)
1058 protected void moveToPage() {
1063 * Moves to a certain page.
1065 * @param notifyAll true to broadcast time range signal to other signal handlers else false
1067 protected void moveToPage(boolean notifyAll
) {
1069 TmfTimeRange window
= null;
1074 if (fCurrentPage
> fCheckPoints
.size()) {
1077 window
= fCheckPoints
.get(fCurrentPage
);
1082 if (window
== null) {
1083 window
= TmfTimeRange
.ETERNITY
;
1086 fPageRequest
= new TmfEventRequest(ITmfEvent
.class, window
, 0,
1087 ITmfEventRequest
.ALL_DATA
, ITmfEventRequest
.ExecutionType
.FOREGROUND
) {
1088 private final List
<ITmfSyncSequenceDiagramEvent
> fSdEvent
= new ArrayList
<>();
1091 public void handleData(ITmfEvent event
) {
1092 super.handleData(event
);
1094 ITmfSyncSequenceDiagramEvent sdEvent
= getSequenceDiagramEvent(event
);
1096 if (sdEvent
!= null) {
1097 fSdEvent
.add(sdEvent
);
1102 public void handleSuccess() {
1103 fillCurrentPage(fSdEvent
);
1104 super.handleSuccess();
1109 fTrace
.sendRequest(fPageRequest
);
1112 TmfTimeRange timeRange
= getSignalTimeRange(window
.getStartTime());
1113 broadcast(new TmfWindowRangeUpdatedSignal(this, timeRange
));
1118 * Gets page that contains timestamp
1120 * @param time The timestamp
1121 * @return page that contains the time
1123 protected int getPage(ITmfTimestamp time
) {
1128 size
= fCheckPoints
.size();
1129 for (page
= 0; page
< size
; page
++) {
1130 TmfTimeRange timeRange
= fCheckPoints
.get(page
);
1131 if (timeRange
.getEndTime().compareTo(time
) >= 0) {
1145 * Background search in trace for expression in criteria.
1147 * @param findCriteria The find criteria
1148 * @return true if background request was started else false
1150 protected boolean findInNextPages(Criteria findCriteria
) {
1153 if (fFindJob
!= null) {
1157 int nextPage
= fCurrentPage
+ 1;
1159 if ((nextPage
) >= fCheckPoints
.size()) {
1160 // we are at the end
1164 TmfTimeRange window
= new TmfTimeRange(fCheckPoints
.get(nextPage
).getStartTime(), fCheckPoints
.get(fCheckPoints
.size()-1).getEndTime());
1165 fFindJob
= new SearchJob(findCriteria
, window
);
1166 fFindJob
.schedule();
1167 fView
.toggleWaitCursorAsync(true);
1175 * Gets time range for time range signal.
1177 * @param startTime The start time of time range.
1178 * @return the time range
1180 protected TmfTimeRange
getSignalTimeRange(ITmfTimestamp startTime
) {
1183 TmfTimeRange currentRange
= TmfTraceManager
.getInstance().getCurrentTraceContext().getWindowRange();
1184 long offset
= fTrace
== null ?
0 : currentRange
.getEndTime().getDelta(currentRange
.getStartTime()).normalize(0, startTime
.getScale()).getValue();
1185 TmfTimestamp initialEndOfWindow
= new TmfTimestamp(startTime
.getValue() + offset
, startTime
.getScale());
1186 return new TmfTimeRange(startTime
, initialEndOfWindow
);
1194 * Checks if filter criteria matches the message name in given SD event.
1196 * @param sdEvent The SD event to check
1197 * @return true if match else false.
1199 protected boolean filterMessage(ITmfSyncSequenceDiagramEvent sdEvent
) {
1202 if (fFilterCriteria
!= null) {
1203 for(FilterCriteria criteria
: fFilterCriteria
) {
1204 if (criteria
.isActive() && criteria
.getCriteria().isSyncMessageSelected() && criteria
.getCriteria().matches(sdEvent
.getName())) {
1216 * Checks if filter criteria matches a lifeline name (sender or receiver) in given SD event.
1218 * @param lifeline the message receiver
1219 * @return true if match else false.
1221 protected boolean filterLifeLine(String lifeline
) {
1224 if (fFilterCriteria
!= null) {
1225 for(FilterCriteria criteria
: fFilterCriteria
) {
1226 if (criteria
.isActive() && criteria
.getCriteria().isLifeLineSelected() && criteria
.getCriteria().matches(lifeline
)) {
1238 * Job to search in trace for given time range.
1240 protected class SearchJob
extends Job
{
1243 * The search event request.
1245 protected final SearchEventRequest fSearchRequest
;
1250 * @param findCriteria The search criteria
1251 * @param window Time range to search in
1253 public SearchJob(Criteria findCriteria
, TmfTimeRange window
) {
1254 super(Messages
.TmfUml2SDSyncLoader_SearchJobDescrition
);
1255 fSearchRequest
= new SearchEventRequest(window
, ITmfEventRequest
.ALL_DATA
,
1256 ITmfEventRequest
.ExecutionType
.FOREGROUND
, findCriteria
);
1260 protected IStatus
run(IProgressMonitor monitor
) {
1261 fSearchRequest
.setMonitor(monitor
);
1263 fTrace
.sendRequest(fSearchRequest
);
1266 fSearchRequest
.waitForCompletion();
1267 } catch (InterruptedException e
) {
1268 Activator
.getDefault().logError("Search request interrupted!", e
); //$NON-NLS-1$
1271 IStatus status
= Status
.OK_STATUS
;
1272 if (fSearchRequest
.isFound() && (fSearchRequest
.getFoundTime() != null)) {
1273 fCurrentTime
= fSearchRequest
.getFoundTime();
1275 // Avoid double-selection. Selection will be done when calling find(criteria)
1276 // after moving to relevant page
1278 if (!fView
.getSDWidget().isDisposed()) {
1279 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1289 if (monitor
.isCanceled()) {
1290 status
= Status
.CANCEL_STATUS
;
1293 // String was not found
1294 status
= new Status(IStatus
.WARNING
, Activator
.PLUGIN_ID
, Messages
.TmfUml2SDSyncLoader_SearchNotFound
);
1296 setProperty(IProgressConstants
.KEEP_PROPERTY
, Boolean
.TRUE
);
1302 fView
.toggleWaitCursorAsync(false);
1312 protected void canceling() {
1313 fSearchRequest
.cancel();
1324 * TMF event request for searching within trace.
1326 protected class SearchEventRequest
extends TmfEventRequest
{
1329 * The find criteria.
1331 private final Criteria fCriteria
;
1333 * A progress monitor
1335 private IProgressMonitor fMonitor
;
1337 * Flag to indicate that node was found according the criteria .
1339 private boolean fIsFound
= false;
1341 * Time stamp of found item.
1343 private ITmfTimestamp fFoundTime
= null;
1347 * @param range see {@link TmfEventRequest#TmfEventRequest(Class, TmfTimeRange, long, int, org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest.ExecutionType) TmfEventRequest}
1348 * @param nbRequested see {@link TmfEventRequest#TmfEventRequest(Class, TmfTimeRange, long, int, org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest.ExecutionType) TmfEventRequest}
1349 * @param priority {@link ExecutionType#FOREGROUND} or {@link ExecutionType#BACKGROUND}
1350 * @param criteria The search criteria
1352 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, ExecutionType priority
, Criteria criteria
) {
1353 this(range
, nbRequested
, priority
, criteria
, null);
1358 * @param range see {@link TmfEventRequest#TmfEventRequest(Class, TmfTimeRange, long, int, org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest.ExecutionType) TmfEventRequest}
1359 * @param nbRequested see {@link TmfEventRequest#TmfEventRequest(Class, TmfTimeRange, long, int, org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest.ExecutionType) TmfEventRequest}
1360 * @param priority {@link ExecutionType#FOREGROUND} or {@link ExecutionType#BACKGROUND}
1361 * @param criteria The search criteria
1362 * @param monitor progress monitor
1364 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, ExecutionType priority
, Criteria criteria
, IProgressMonitor monitor
) {
1365 super(ITmfEvent
.class, range
, 0, nbRequested
, priority
);
1366 fCriteria
= new Criteria(criteria
);
1371 public void handleData(ITmfEvent event
) {
1372 super.handleData(event
);
1374 if ((fMonitor
!= null) && fMonitor
.isCanceled()) {
1379 ITmfSyncSequenceDiagramEvent sdEvent
= getSequenceDiagramEvent(event
);
1381 if (sdEvent
!= null) {
1383 if (fCriteria
.isLifeLineSelected()) {
1384 if (fCriteria
.matches(sdEvent
.getSender())) {
1385 fFoundTime
= event
.getTimestamp();
1390 if (fCriteria
.matches(sdEvent
.getReceiver())) {
1391 fFoundTime
= event
.getTimestamp();
1397 if (fCriteria
.isSyncMessageSelected() && fCriteria
.matches(sdEvent
.getName())) {
1398 fFoundTime
= event
.getTimestamp();
1406 * Set progress monitor.
1408 * @param monitor The monitor to assign
1410 public void setMonitor(IProgressMonitor monitor
) {
1415 * Check if find criteria was met.
1417 * @return true if find criteria was met.
1419 public boolean isFound() {
1424 * Returns timestamp of found time.
1426 * @return timestamp of found time.
1428 public ITmfTimestamp
getFoundTime() {
1434 * Job class to provide progress monitor feedback.
1436 * @author Bernd Hufmann
1438 protected static class IndexingJob
extends Job
{
1441 * @param name The job name
1443 public IndexingJob(String name
) {
1448 protected IStatus
run(IProgressMonitor monitor
) {
1449 while (!monitor
.isCanceled()) {
1451 Thread
.sleep(INDEXING_THREAD_SLEEP_VALUE
);
1452 } catch (InterruptedException e
) {
1453 return Status
.OK_STATUS
;
1457 return Status
.OK_STATUS
;
1463 * Returns sequence diagram event if details in given event are available else null.
1465 * @param tmfEvent Event to parse for sequence diagram event details
1466 * @return sequence diagram event if details are available else null
1468 protected ITmfSyncSequenceDiagramEvent
getSequenceDiagramEvent(ITmfEvent tmfEvent
){
1469 //type = .*RECEIVE.* or .*SEND.*
1470 //content = sender:<sender name>:receiver:<receiver name>,signal:<signal name>
1471 String eventType
= tmfEvent
.getType().toString();
1472 if (eventType
.contains(Messages
.TmfUml2SDSyncLoader_EventTypeSend
) || eventType
.contains(Messages
.TmfUml2SDSyncLoader_EventTypeReceive
)) {
1473 Object sender
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncLoader_FieldSender
);
1474 Object receiver
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncLoader_FieldReceiver
);
1475 Object name
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncLoader_FieldSignal
);
1476 if ((sender
instanceof ITmfEventField
) && (receiver
instanceof ITmfEventField
) && (name
instanceof ITmfEventField
)) {
1477 ITmfSyncSequenceDiagramEvent sdEvent
= new TmfSyncSequenceDiagramEvent(tmfEvent
,
1478 ((ITmfEventField
) sender
).getValue().toString(),
1479 ((ITmfEventField
) receiver
).getValue().toString(),
1480 ((ITmfEventField
) name
).getValue().toString());