1 /**********************************************************************
2 * Copyright (c) 2011, 2012 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.loader
;
14 import java
.util
.ArrayList
;
15 import java
.util
.HashMap
;
16 import java
.util
.List
;
18 import java
.util
.concurrent
.CopyOnWriteArrayList
;
19 import java
.util
.concurrent
.locks
.ReentrantLock
;
21 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
22 import org
.eclipse
.core
.runtime
.IStatus
;
23 import org
.eclipse
.core
.runtime
.Status
;
24 import org
.eclipse
.core
.runtime
.jobs
.Job
;
25 import org
.eclipse
.jface
.viewers
.ISelection
;
26 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
27 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.component
.TmfComponent
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfDataRequest
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfEventRequest
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfDataRequest
;
34 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfEventRequest
;
35 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfRangeSynchSignal
;
36 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignal
;
37 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
38 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimeSynchSignal
;
39 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceClosedSignal
;
40 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
41 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
42 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimeRange
;
43 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestamp
;
44 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
45 import org
.eclipse
.linuxtools
.tmf
.core
.uml2sd
.ITmfSyncSequenceDiagramEvent
;
46 import org
.eclipse
.linuxtools
.tmf
.core
.uml2sd
.TmfSyncSequenceDiagramEvent
;
47 import org
.eclipse
.linuxtools
.tmf
.ui
.editors
.ITmfTraceEditor
;
48 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.SDView
;
49 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Frame
;
50 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
51 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Lifeline
;
52 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.Criteria
;
53 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.FilterCriteria
;
54 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.FilterListDialog
;
55 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDAdvancedPagingProvider
;
56 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDFilterProvider
;
57 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDFindProvider
;
58 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDGraphNodeSupporter
;
59 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.load
.IUml2SDLoader
;
60 import org
.eclipse
.swt
.widgets
.Display
;
61 import org
.eclipse
.ui
.IEditorPart
;
62 import org
.eclipse
.ui
.ISelectionListener
;
63 import org
.eclipse
.ui
.IWorkbenchPart
;
64 import org
.eclipse
.ui
.IWorkbenchWindow
;
65 import org
.eclipse
.ui
.PlatformUI
;
66 import org
.eclipse
.ui
.progress
.IProgressConstants
;
70 * This class is a reference implementation of the
71 * <code>org.eclipse.linuxtools.tmf.ui.Uml2SDLoader</code> extension point. It
72 * provides a Sequence Diagram loader for a user space trace with specific trace
73 * content for sending and receiving signals between components. I also includes
74 * a default implementation for the <code>ITmfEvent</code> parsing.
77 * The class <code>TmfUml2SDSyncLoader</code> analyzes events from type
78 * <code>ITmfEvent</code> and creates events type
79 * <code>ITmfSyncSequenceDiagramEvent</code> if the <code>ITmfEvent</code>
80 * contains all relevant information. The analysis checks that the event type
81 * strings contains either string SEND or RECEIVE. If event type matches these
82 * key words, the analyzer will look for strings sender, receiver and signal in
83 * the event fields of type <code>ITmfEventField</code>. If all the data is
84 * found a sequence diagram event from can be created. Note that Sync Messages
85 * are assumed, which means start and end time are the same. <br>
87 * The parsing of the <code>ITmfEvent</code> is done in the method
88 * <code>getSequnceDiagramEvent()</code> of class
89 * <code>TmfUml2SDSyncLoader</code>. By extending the class
90 * <code>TmfUml2SDSyncLoader</code> and overwriting
91 * <code>getSequnceDiagramEvent()</code> a customized parsing algorithm can be
94 * Note that combined traces of multiple components, that contain the trace
95 * information about the same interactions are not supported in the class
96 * <code>TmfUml2SDSyncLoader</code>.
99 * @author Bernd Hufmann
101 public class TmfUml2SDSyncLoader
extends TmfComponent
implements IUml2SDLoader
, ISDFindProvider
, ISDFilterProvider
, ISDAdvancedPagingProvider
, ISelectionListener
{
103 // ------------------------------------------------------------------------
105 // ------------------------------------------------------------------------
107 * Default title name.
109 protected final static String TITLE
= Messages
.TmfUml2SDSyncLoader_ViewName
;
111 * Default block size for background request.
113 protected final static int DEFAULT_BLOCK_SIZE
= 50000;
115 * Maximum number of messages per page.
117 protected final static int MAX_NUM_OF_MSG
= 10000;
119 // ------------------------------------------------------------------------
121 // ------------------------------------------------------------------------
123 // Experiment attributes
125 * The TMF trace reference.
128 protected ITmfTrace fTrace
= null;
130 * The current indexing event request.
132 protected ITmfEventRequest fIndexRequest
= null;
134 * The current request to fill a page.
136 protected ITmfEventRequest fPageRequest
= null;
138 * Flag whether the time range signal was sent by this loader class or not
140 volatile protected boolean fIsSignalSent
= false;
142 // The view and event attributes
144 * The sequence diagram view reference.
146 protected SDView fView
= null;
148 * The current sequence diagram frame reference.
150 protected Frame fFrame
= null;
152 * The list of sequence diagram events of current page.
154 protected List
<ITmfSyncSequenceDiagramEvent
> fEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>();
156 // Checkpoint and page attributes
158 * The checkpoints of the whole sequence diagram trace (i.e. start time stamp of each page)
160 protected List
<TmfTimeRange
> fCheckPoints
= new ArrayList
<TmfTimeRange
>(MAX_NUM_OF_MSG
);
162 * The current page displayed.
164 volatile protected int fCurrentPage
= 0;
166 * The current time selected.
168 protected ITmfTimestamp fCurrentTime
= null;
170 * Flag to specify that selection of message is done by selection or by signal.
172 volatile protected boolean fIsSelect
= false;
176 * The job for searching across pages.
178 protected SearchJob fFindJob
= null;
180 * List of found nodes within a page.
182 protected List
<GraphNode
> fFindResults
= new ArrayList
<GraphNode
>();
184 * The current find criteria reference
186 protected Criteria fFindCriteria
= null;
188 * The current find index within the list of found nodes (<code>fFindeResults</code> within a page.
190 volatile protected int fCurrentFindIndex
= 0;
194 * The list of active filters.
196 protected List
<FilterCriteria
> fFilterCriteria
= null;
198 // Thread synchronization
200 * The synchronization lock.
202 protected ReentrantLock fLock
= new ReentrantLock();
204 // ------------------------------------------------------------------------
206 // ------------------------------------------------------------------------
208 * Default constructor
210 public TmfUml2SDSyncLoader() {
217 * @param name Name of loader
219 public TmfUml2SDSyncLoader(String name
) {
223 // ------------------------------------------------------------------------
225 // ------------------------------------------------------------------------
228 * Returns the current time if available else null.
230 * @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 * Signal handler for the trace selected signal.
264 * Spawns a request to index the trace (checkpoints creation) as well as it fills
267 * @param signal The trace selected signal
271 public void traceSelected(TmfTraceSelectedSignal signal
) {
273 ITmfEventRequest indexRequest
= null;
276 // Update the trace reference
277 ITmfTrace trace
= signal
.getTrace();
278 if (!trace
.equals(fTrace
)) {
284 final Job job
= new IndexingJob("Indexing " + getName() + "..."); //$NON-NLS-1$ //$NON-NLS-2$
288 indexRequest
= fIndexRequest
;
290 cancelOngoingRequests();
292 TmfTimeRange window
= TmfTimeRange
.ETERNITY
;
294 fIndexRequest
= new TmfEventRequest(ITmfEvent
.class, window
, TmfDataRequest
.ALL_DATA
, DEFAULT_BLOCK_SIZE
, ITmfDataRequest
.ExecutionType
.BACKGROUND
) {
296 private ITmfTimestamp fFirstTime
= null;
297 private ITmfTimestamp fLastTime
= null;
298 private int fNbSeqEvents
= 0;
299 private final List
<ITmfSyncSequenceDiagramEvent
> fSdEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>(MAX_NUM_OF_MSG
);
303 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
306 public void handleData(ITmfEvent event
) {
307 super.handleData(event
);
309 ITmfSyncSequenceDiagramEvent sdEvent
= getSequenceDiagramEvent(event
);
311 if (sdEvent
!= null) {
314 if (fFirstTime
== null) {
315 fFirstTime
= event
.getTimestamp();
318 fLastTime
= event
.getTimestamp();
320 if ((fNbSeqEvents
% MAX_NUM_OF_MSG
) == 0) {
323 fCheckPoints
.add(new TmfTimeRange(fFirstTime
, fLastTime
));
325 fView
.updateCoolBar();
334 if (fNbSeqEvents
> MAX_NUM_OF_MSG
) {
339 fSdEvents
.add(sdEvent
);
341 if (fNbSeqEvents
== MAX_NUM_OF_MSG
) {
342 fillCurrentPage(fSdEvents
);
349 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleSuccess()
352 public void handleSuccess() {
353 if ((fFirstTime
!= null) && (fLastTime
!= null)) {
357 fCheckPoints
.add(new TmfTimeRange(fFirstTime
, fLastTime
));
359 fView
.updateCoolBar();
366 if (fNbSeqEvents
<= MAX_NUM_OF_MSG
) {
367 fillCurrentPage(fSdEvents
);
370 super.handleSuccess();
375 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleCompleted()
378 public void handleCompleted() {
379 if (fEvents
.isEmpty()) {
380 fFrame
= new Frame();
381 fView
.setFrameSync(fFrame
);
383 super.handleCompleted();
391 if (indexRequest
!= null && !indexRequest
.isCompleted()) {
392 indexRequest
.cancel();
395 fTrace
.sendRequest(fIndexRequest
);
400 * Signal handler for the trace closed signal.
402 * @param signal The trace closed signal
406 public void traceClosed(TmfTraceClosedSignal signal
) {
407 if (signal
.getTrace() != fTrace
) {
410 ITmfEventRequest indexRequest
= null;
413 indexRequest
= fIndexRequest
;
414 fIndexRequest
= null;
416 cancelOngoingRequests();
418 if (fFilterCriteria
!= null) {
419 fFilterCriteria
.clear();
422 FilterListDialog
.deactivateSavedGlobalFilters();
427 if (indexRequest
!= null && !indexRequest
.isCompleted()) {
428 indexRequest
.cancel();
435 * Moves to the page that contains the time provided by the signal. The messages will be selected
436 * if the provided time is the time of a message.
438 * @param signal The Time synch signal.
441 public void synchToTime(TmfTimeSynchSignal signal
) {
444 if ((signal
.getSource() != this) && (fFrame
!= null) && (fCheckPoints
.size() > 0)) {
445 fCurrentTime
= signal
.getCurrentTime();
455 * Moves to the page that contains the current time provided by signal.
456 * No message will be selected however the focus will be set to the message
457 * if the provided time is the time of a message.
459 * @param signal The time range sync signal
462 public void synchToTimeRange(TmfRangeSynchSignal signal
) {
465 if ((signal
.getSource() != this) && (fFrame
!= null) && !fIsSignalSent
&& (fCheckPoints
.size() > 0)) {
466 TmfTimeRange newTimeRange
= signal
.getCurrentRange();
469 fCurrentTime
= newTimeRange
.getStartTime();
481 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#setViewer(org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView)
484 public void setViewer(SDView viewer
) {
489 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
490 fView
.setSDFindProvider(this);
491 fView
.setSDPagingProvider(this);
492 fView
.setSDFilterProvider(this);
496 IEditorPart editor
= fView
.getSite().getPage().getActiveEditor();
497 if (editor
instanceof ITmfTraceEditor
) {
498 ITmfTrace trace
= ((ITmfTraceEditor
) editor
).getTrace();
500 traceSelected(new TmfTraceSelectedSignal(this, trace
));
510 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#getTitleString()
513 public String
getTitleString() {
519 * @see org.eclipse.linuxtools.tmf.component.TmfComponent#dispose()
522 public void dispose() {
524 ITmfEventRequest indexRequest
= null;
527 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
528 // During Eclipse shutdown the active workbench window is null
529 if (window
!= null) {
530 window
.getSelectionService().removePostSelectionListener(this);
533 indexRequest
= fIndexRequest
;
534 fIndexRequest
= null;
535 cancelOngoingRequests();
537 fView
.setSDFindProvider(null);
538 fView
.setSDPagingProvider(null);
539 fView
.setSDFilterProvider(null);
544 if (indexRequest
!= null && !indexRequest
.isCompleted()) {
545 indexRequest
.cancel();
551 * @see org.eclipse.hyades.uml2sd.ui.actions.provider.ISDGraphNodeSupporter#isNodeSupported(int)
554 public boolean isNodeSupported(int nodeType
) {
556 case ISDGraphNodeSupporter
.LIFELINE
:
557 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
568 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter#getNodeName(int, java.lang.String)
571 public String
getNodeName(int nodeType
, String loaderClassName
) {
573 case ISDGraphNodeSupporter
.LIFELINE
:
574 return Messages
.TmfUml2SDSyncLoader_CategoryLifeline
;
575 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
576 return Messages
.TmfUml2SDSyncLoader_CategoryMessage
;
580 return ""; //$NON-NLS-1$
585 * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
588 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
589 ISelection sel
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
590 if ((sel
!= null) && (sel
instanceof StructuredSelection
)) {
591 StructuredSelection stSel
= (StructuredSelection
) sel
;
592 if (stSel
.getFirstElement() instanceof TmfSyncMessage
) {
593 TmfSyncMessage syncMsg
= ((TmfSyncMessage
) stSel
.getFirstElement());
594 broadcast(new TmfTimeSynchSignal(this, syncMsg
.getStartTime()));
602 * org.eclipse.hyades.uml2sd.ui.actions.provider.ISDFindProvider#find(org.eclipse.hyades.uml2sd.ui.actions.widgets.Criteria)
605 public boolean find(Criteria toSearch
) {
608 if (fFrame
== null) {
612 if ((fFindResults
== null) || (fFindCriteria
== null) || !fFindCriteria
.compareTo(toSearch
)) {
613 fFindResults
= new CopyOnWriteArrayList
<GraphNode
>();
614 fFindCriteria
= toSearch
;
615 if (fFindCriteria
.isLifeLineSelected()) {
616 for (int i
= 0; i
< fFrame
.lifeLinesCount(); i
++) {
617 if (fFindCriteria
.matches(fFrame
.getLifeline(i
).getName())) {
618 fFindResults
.add(fFrame
.getLifeline(i
));
623 ArrayList
<GraphNode
> msgs
= new ArrayList
<GraphNode
>();
624 if (fFindCriteria
.isSyncMessageSelected()) {
625 for (int i
= 0; i
< fFrame
.syncMessageCount(); i
++) {
626 if (fFindCriteria
.matches(fFrame
.getSyncMessage(i
).getName())) {
627 msgs
.add(fFrame
.getSyncMessage(i
));
632 if (!msgs
.isEmpty()) {
633 fFindResults
.addAll(msgs
);
636 @SuppressWarnings("rawtypes")
637 List selection
= fView
.getSDWidget().getSelection();
638 if ((selection
!= null) && (selection
.size() == 1)) {
639 fCurrentFindIndex
= fFindResults
.indexOf(selection
.get(0)) + 1;
641 fCurrentFindIndex
= 0;
647 if (fFindResults
.size() > fCurrentFindIndex
) {
648 GraphNode current
= fFindResults
.get(fCurrentFindIndex
);
649 fView
.getSDWidget().moveTo(current
);
653 fCurrentFindIndex
=0;
654 return findInNextPages(fFindCriteria
); // search in other page
662 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFindProvider#cancel()
665 public void cancel() {
666 cancelOngoingRequests();
671 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFilterProvider#filter(java.util.List)
673 @SuppressWarnings("unchecked")
675 public boolean filter(List
<?
> filters
) {
678 cancelOngoingRequests();
680 if (filters
== null) {
681 fFilterCriteria
= new ArrayList
<FilterCriteria
>();
683 List
<FilterCriteria
> list
= (List
<FilterCriteria
>)filters
;
684 fFilterCriteria
= new ArrayList
<FilterCriteria
>(list
);
687 fillCurrentPage(fEvents
);
697 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasNextPage()
700 public boolean hasNextPage() {
703 int size
= fCheckPoints
.size();
705 return fCurrentPage
< (size
- 1);
715 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasPrevPage()
718 public boolean hasPrevPage() {
721 return fCurrentPage
> 0;
729 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#nextPage()
732 public void nextPage() {
736 if (fCurrentPage
>= (fCheckPoints
.size() - 1)) {
740 cancelOngoingRequests();
751 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#prevPage()
754 public void prevPage() {
758 if (fCurrentPage
<= 0) {
762 cancelOngoingRequests();
773 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#firstPage()
776 public void firstPage() {
780 cancelOngoingRequests();
791 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#lastPage()
794 public void lastPage() {
797 cancelOngoingRequests();
799 fCurrentPage
= fCheckPoints
.size() - 1;
808 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#currentPage()
811 public int currentPage() {
822 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pagesCount()
825 public int pagesCount() {
828 return fCheckPoints
.size();
836 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pageNumberChanged(int)
839 public void pageNumberChanged(int pagenNumber
) {
840 int localPageNumber
= pagenNumber
;
844 cancelOngoingRequests();
846 if (localPageNumber
< 0) {
849 int size
= fCheckPoints
.size();
850 if (localPageNumber
> (size
- 1)) {
851 localPageNumber
= size
- 1;
853 fCurrentPage
= localPageNumber
;
862 * @see org.eclipse.linuxtools.tmf.component.TmfComponent#broadcast(org.eclipse.linuxtools.tmf.signal.TmfSignal)
865 public void broadcast(TmfSignal signal
) {
866 fIsSignalSent
= true;
867 super.broadcast(signal
);
868 fIsSignalSent
= false;
872 * Cancels any ongoing find operation
874 protected void cancelOngoingRequests() {
876 ITmfEventRequest pageRequest
= null;
878 // Cancel the search thread
879 if (fFindJob
!= null) {
884 fFindCriteria
= null;
885 fCurrentFindIndex
= 0;
887 pageRequest
= fPageRequest
;
892 if (pageRequest
!= null && !pageRequest
.isCompleted()) {
893 pageRequest
.cancel();
898 * Resets loader attributes
900 protected void resetLoader() {
905 fCheckPoints
.clear();
907 fCurrentFindIndex
= 0;
908 fFindCriteria
= null;
910 fView
.setFrameSync(new Frame());
920 * Fills current page with sequence diagram content.
922 * @param events sequence diagram events
924 protected void fillCurrentPage(List
<ITmfSyncSequenceDiagramEvent
> events
) {
928 fEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>(events
);
929 if (fView
!= null && !events
.isEmpty()) {
930 fView
.toggleWaitCursorAsync(true);
936 final Frame frame
= new Frame();
938 if (!events
.isEmpty()) {
939 Map
<String
, Lifeline
> nodeToLifelineMap
= new HashMap
<String
, Lifeline
>();
941 frame
.setName(Messages
.TmfUml2SDSyncLoader_FrameName
);
943 for (int i
= 0; i
< events
.size(); i
++) {
945 ITmfSyncSequenceDiagramEvent sdEvent
= events
.get(i
);
947 if ((nodeToLifelineMap
.get(sdEvent
.getSender()) == null) && (!filterLifeLine(sdEvent
.getSender()))) {
948 Lifeline lifeline
= new Lifeline();
949 lifeline
.setName(sdEvent
.getSender());
950 nodeToLifelineMap
.put(sdEvent
.getSender(), lifeline
);
951 frame
.addLifeLine(lifeline
);
954 if ((nodeToLifelineMap
.get(sdEvent
.getReceiver()) == null) && (!filterLifeLine(sdEvent
.getReceiver()))) {
955 Lifeline lifeline
= new Lifeline();
956 lifeline
.setName(sdEvent
.getReceiver());
957 nodeToLifelineMap
.put(sdEvent
.getReceiver(), lifeline
);
958 frame
.addLifeLine(lifeline
);
962 int eventOccurence
= 1;
964 for (int i
= 0; i
< events
.size(); i
++) {
965 ITmfSyncSequenceDiagramEvent sdEvent
= events
.get(i
);
967 // Check message filter
968 if (filterMessage(sdEvent
)) {
972 // Set the message sender and receiver
973 Lifeline startLifeline
= nodeToLifelineMap
.get(sdEvent
.getSender());
974 Lifeline endLifeline
= nodeToLifelineMap
.get(sdEvent
.getReceiver());
976 // Check if any of the lifelines were filtered
977 if ((startLifeline
== null) || (endLifeline
== null)) {
981 int tmp
= Math
.max(startLifeline
.getEventOccurrence(), endLifeline
.getEventOccurrence());
982 eventOccurence
= Math
.max(eventOccurence
, tmp
);
984 startLifeline
.setCurrentEventOccurrence(eventOccurence
);
985 endLifeline
.setCurrentEventOccurrence(eventOccurence
);
987 TmfSyncMessage message
= new TmfSyncMessage(sdEvent
, eventOccurence
++);
989 message
.setStartLifeline(startLifeline
);
990 message
.setEndLifeline(endLifeline
);
992 message
.setTime(sdEvent
.getStartTime());
994 // add the message to the frame
995 frame
.addMessage(message
);
1000 if (!fView
.getSDWidget().isDisposed()) {
1001 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1008 // check if view was disposed in the meanwhile
1009 if ((fView
!= null) && (!fView
.getSDWidget().isDisposed())) {
1011 fView
.setFrame(fFrame
);
1013 if (fCurrentTime
!= null) {
1014 moveToMessageInPage();
1017 if (fFindCriteria
!= null) {
1018 find(fFindCriteria
);
1021 fView
.toggleWaitCursorAsync(false);
1038 * Moves to a certain message defined by timestamp (across pages)
1040 protected void moveToMessage() {
1045 page
= getPage(fCurrentTime
);
1047 if (page
== fCurrentPage
) {
1048 moveToMessageInPage();
1051 fCurrentPage
= page
;
1059 * Moves to a certain message defined by timestamp in current page
1061 protected void moveToMessageInPage() {
1064 if (!fView
.getSDWidget().isDisposed()) {
1065 // Check for GUI thread
1066 if(Display
.getCurrent() != null) {
1067 // Already in GUI thread - execute directly
1068 TmfSyncMessage prevMessage
= null;
1069 TmfSyncMessage syncMessage
= null;
1070 boolean isExactTime
= false;
1071 for (int i
= 0; i
< fFrame
.syncMessageCount(); i
++) {
1072 if (fFrame
.getSyncMessage(i
) instanceof TmfSyncMessage
) {
1073 syncMessage
= (TmfSyncMessage
) fFrame
.getSyncMessage(i
);
1074 if (syncMessage
.getStartTime().compareTo(fCurrentTime
, false) == 0) {
1077 } else if ((syncMessage
.getStartTime().compareTo(fCurrentTime
, false) > 0) && (prevMessage
!= null)) {
1078 syncMessage
= prevMessage
;
1081 prevMessage
= syncMessage
;
1084 if (fIsSelect
&& isExactTime
) {
1085 fView
.getSDWidget().moveTo(syncMessage
);
1088 fView
.getSDWidget().ensureVisible(syncMessage
);
1089 fView
.getSDWidget().clearSelection();
1090 fView
.getSDWidget().redraw();
1094 // Not in GUI thread - queue action in GUI thread.
1095 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1098 moveToMessageInPage();
1110 * Moves to a certain message defined by timestamp (across pages)
1112 protected void moveToPage() {
1117 * Moves to a certain page.
1119 * @param notifyAll true to broadcast time range signal to other signal handlers else false
1121 protected void moveToPage(boolean notifyAll
) {
1123 TmfTimeRange window
= null;
1128 if (fCurrentPage
> fCheckPoints
.size()) {
1131 window
= fCheckPoints
.get(fCurrentPage
);
1136 if (window
== null) {
1137 window
= TmfTimeRange
.ETERNITY
;
1140 fPageRequest
= new TmfEventRequest(ITmfEvent
.class, window
, TmfDataRequest
.ALL_DATA
, 1, ITmfDataRequest
.ExecutionType
.FOREGROUND
) {
1141 private final List
<ITmfSyncSequenceDiagramEvent
> fSdEvent
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>();
1144 public void handleData(ITmfEvent event
) {
1145 super.handleData(event
);
1147 ITmfSyncSequenceDiagramEvent sdEvent
= getSequenceDiagramEvent(event
);
1149 if (sdEvent
!= null) {
1150 fSdEvent
.add(sdEvent
);
1155 public void handleSuccess() {
1156 fillCurrentPage(fSdEvent
);
1157 super.handleSuccess();
1162 fTrace
.sendRequest(fPageRequest
);
1165 TmfTimeRange timeRange
= getSignalTimeRange(window
.getStartTime());
1166 broadcast(new TmfRangeSynchSignal(this, timeRange
, timeRange
.getStartTime()));
1171 * Gets page that contains timestamp
1173 * @param time The timestamp
1174 * @return page that contains the time
1177 protected int getPage(ITmfTimestamp time
) {
1182 size
= fCheckPoints
.size();
1183 for (page
= 0; page
< size
; page
++) {
1184 TmfTimeRange timeRange
= fCheckPoints
.get(page
);
1185 if (timeRange
.getEndTime().compareTo(time
, false) >= 0) {
1199 * Background search in trace for expression in criteria.
1201 * @param findCriteria The find criteria
1202 * @return true if background request was started else false
1204 protected boolean findInNextPages(Criteria findCriteria
) {
1207 if (fFindJob
!= null) {
1211 int nextPage
= fCurrentPage
+ 1;
1213 if ((nextPage
) >= fCheckPoints
.size()) {
1214 // we are at the end
1218 TmfTimeRange window
= new TmfTimeRange(fCheckPoints
.get(nextPage
).getStartTime(), fCheckPoints
.get(fCheckPoints
.size()-1).getEndTime());
1219 fFindJob
= new SearchJob(findCriteria
, window
);
1220 fFindJob
.schedule();
1221 fView
.toggleWaitCursorAsync(true);
1229 * Gets time range for time range signal.
1231 * @param startTime The start time of time range.
1232 * @return the time range
1235 protected TmfTimeRange
getSignalTimeRange(ITmfTimestamp startTime
) {
1238 long offset
= fTrace
== null ?
0 : fTrace
.getCurrentRange().getEndTime().getDelta(fTrace
.getCurrentRange().getStartTime()).normalize(0, startTime
.getScale()).getValue();
1239 TmfTimestamp initialEndOfWindow
= new TmfTimestamp(startTime
.getValue() + offset
, startTime
.getScale(), startTime
.getPrecision());
1240 return new TmfTimeRange(startTime
, initialEndOfWindow
);
1248 * Checks if filter criteria matches the message name in given SD event.
1250 * @param sdEvent The SD event to check
1251 * @return true if match else false.
1253 protected boolean filterMessage(ITmfSyncSequenceDiagramEvent sdEvent
) {
1256 if (fFilterCriteria
!= null) {
1257 for(FilterCriteria criteria
: fFilterCriteria
) {
1258 if (criteria
.isActive() && criteria
.getCriteria().isSyncMessageSelected() && criteria
.getCriteria().matches(sdEvent
.getName())) {
1270 * Checks if filter criteria matches a lifeline name (sender or receiver) in given SD event.
1272 * @param lifeline the message receiver
1273 * @return true if match else false.
1275 protected boolean filterLifeLine(String lifeline
) {
1278 if (fFilterCriteria
!= null) {
1279 for(FilterCriteria criteria
: fFilterCriteria
) {
1280 if (criteria
.isActive() && criteria
.getCriteria().isLifeLineSelected() && criteria
.getCriteria().matches(lifeline
)) {
1292 * Job to search in trace for given time range.
1294 protected class SearchJob
extends Job
{
1297 * The search event request.
1299 final protected SearchEventRequest fSearchRequest
;
1304 * @param findCriteria The search criteria
1305 * @param window Time range to search in
1308 public SearchJob(Criteria findCriteria
, TmfTimeRange window
) {
1309 super(Messages
.TmfUml2SDSyncLoader_SearchJobDescrition
);
1310 fSearchRequest
= new SearchEventRequest(window
, TmfDataRequest
.ALL_DATA
, 1, ITmfDataRequest
.ExecutionType
.FOREGROUND
, findCriteria
);
1315 * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
1318 protected IStatus
run(IProgressMonitor monitor
) {
1319 fSearchRequest
.setMonitor(monitor
);
1321 fTrace
.sendRequest(fSearchRequest
);
1324 fSearchRequest
.waitForCompletion();
1325 } catch (InterruptedException e
) {
1326 Activator
.getDefault().logError("Search request interrupted!", e
); //$NON-NLS-1$
1329 IStatus status
= Status
.OK_STATUS
;
1330 if (fSearchRequest
.isFound() && (fSearchRequest
.getFoundTime() != null)) {
1331 fCurrentTime
= fSearchRequest
.getFoundTime();
1333 // Avoid double-selection. Selection will be done when calling find(criteria)
1334 // after moving to relevant page
1336 if (!fView
.getSDWidget().isDisposed()) {
1337 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1347 if (monitor
.isCanceled()) {
1348 status
= Status
.CANCEL_STATUS
;
1351 // String was not found
1352 status
= new Status(IStatus
.WARNING
, Activator
.PLUGIN_ID
, Messages
.TmfUml2SDSyncLoader_SearchNotFound
);
1354 setProperty(IProgressConstants
.KEEP_PROPERTY
, Boolean
.TRUE
);
1360 fView
.toggleWaitCursorAsync(false);
1371 * @see org.eclipse.core.runtime.jobs.Job#canceling()
1374 protected void canceling() {
1375 fSearchRequest
.cancel();
1386 * TMF event request for searching within trace.
1388 protected class SearchEventRequest
extends TmfEventRequest
{
1391 * The find criteria.
1393 final private Criteria fCriteria
;
1395 * A progress monitor
1397 private IProgressMonitor fMonitor
;
1399 * Flag to indicate that node was found according the criteria .
1401 private boolean fIsFound
= false;
1403 * Time stamp of found item.
1405 private ITmfTimestamp fFoundTime
= null;
1409 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1410 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1411 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1412 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1413 * @param criteria The search criteria
1415 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType execType
, Criteria criteria
) {
1416 this(range
, nbRequested
, blockSize
, execType
, criteria
, null);
1421 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1422 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1423 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1424 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1425 * @param criteria The search criteria
1426 * @param monitor progress monitor
1428 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType execType
, Criteria criteria
, IProgressMonitor monitor
) {
1429 super(ITmfEvent
.class, range
, nbRequested
, blockSize
, execType
);
1430 fCriteria
= new Criteria(criteria
);
1436 * @see org.eclipse.linuxtools.tmf.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.event.TmfData)
1439 public void handleData(ITmfEvent event
) {
1440 super.handleData(event
);
1442 if ((fMonitor
!= null) && fMonitor
.isCanceled()) {
1447 ITmfSyncSequenceDiagramEvent sdEvent
= getSequenceDiagramEvent(event
);
1449 if (sdEvent
!= null) {
1451 if (fCriteria
.isLifeLineSelected()) {
1452 if (fCriteria
.matches(sdEvent
.getSender())) {
1453 fFoundTime
= event
.getTimestamp();
1458 if (fCriteria
.matches(sdEvent
.getReceiver())) {
1459 fFoundTime
= event
.getTimestamp();
1465 if (fCriteria
.isSyncMessageSelected() && fCriteria
.matches(sdEvent
.getName())) {
1466 fFoundTime
= event
.getTimestamp();
1474 * Set progress monitor.
1476 * @param monitor The monitor to assign
1478 public void setMonitor(IProgressMonitor monitor
) {
1483 * Check if find criteria was met.
1485 * @return true if find criteria was met.
1487 public boolean isFound() {
1492 * Returns timestamp of found time.
1494 * @return timestamp of found time.
1497 public ITmfTimestamp
getFoundTime() {
1503 * Job class to provide progress monitor feedback.
1506 * @author Bernd Hufmann
1509 protected static class IndexingJob
extends Job
{
1512 * @param name The job name
1514 public IndexingJob(String name
) {
1519 protected IStatus
run(IProgressMonitor monitor
) {
1520 while (!monitor
.isCanceled()) {
1523 } catch (InterruptedException e
) {
1524 return Status
.OK_STATUS
;
1528 return Status
.OK_STATUS
;
1534 * Returns sequence diagram event if details in given event are available else null.
1536 * @param tmfEvent Event to parse for sequence diagram event details
1537 * @return sequence diagram event if details are available else null
1540 protected ITmfSyncSequenceDiagramEvent
getSequenceDiagramEvent(ITmfEvent tmfEvent
){
1541 //type = .*RECEIVE.* or .*SEND.*
1542 //content = sender:<sender name>:receiver:<receiver name>,signal:<signal name>
1543 String eventType
= tmfEvent
.getType().toString();
1544 if (eventType
.contains(Messages
.TmfUml2SDSyncLoader_EventTypeSend
) || eventType
.contains(Messages
.TmfUml2SDSyncLoader_EventTypeReceive
)) {
1545 Object sender
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncLoader_FieldSender
);
1546 Object receiver
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncLoader_FieldReceiver
);
1547 Object name
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncLoader_FieldSignal
);
1548 if ((sender
instanceof ITmfEventField
) && (receiver
instanceof ITmfEventField
) && (name
instanceof ITmfEventField
)) {
1549 ITmfSyncSequenceDiagramEvent sdEvent
= new TmfSyncSequenceDiagramEvent(tmfEvent
,
1550 ((ITmfEventField
) sender
).getValue().toString(),
1551 ((ITmfEventField
) receiver
).getValue().toString(),
1552 ((ITmfEventField
) name
).getValue().toString());