1 /**********************************************************************
2 * Copyright (c) 2011, 2012 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.loader
;
14 import java
.util
.ArrayList
;
15 import java
.util
.HashMap
;
16 import java
.util
.List
;
18 import java
.util
.concurrent
.CopyOnWriteArrayList
;
19 import java
.util
.concurrent
.locks
.ReentrantLock
;
21 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
22 import org
.eclipse
.core
.runtime
.IStatus
;
23 import org
.eclipse
.core
.runtime
.Status
;
24 import org
.eclipse
.core
.runtime
.jobs
.Job
;
25 import org
.eclipse
.jface
.viewers
.ISelection
;
26 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
27 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.component
.TmfComponent
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
34 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfDataRequest
;
35 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfEventRequest
;
36 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfDataRequest
;
37 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfEventRequest
;
38 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfRangeSynchSignal
;
39 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignal
;
40 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
41 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimeSynchSignal
;
42 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceClosedSignal
;
43 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
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 * Initial time range window.
121 protected final static long INITIAL_WINDOW_OFFSET
= (1L * 100 * 1000 * 1000); // .1sec
123 // ------------------------------------------------------------------------
125 // ------------------------------------------------------------------------
127 // Experiment attributes
129 * The TMF trace reference.
132 protected ITmfTrace fTrace
= null;
134 * The current indexing event request.
136 protected ITmfEventRequest fIndexRequest
= null;
138 * The current request to fill a page.
140 protected ITmfEventRequest fPageRequest
= null;
142 * Flag whether the time range signal was sent by this loader class or not
144 volatile protected boolean fIsSignalSent
= false;
146 * The initial request window size.
148 volatile protected long fInitialWindow
= INITIAL_WINDOW_OFFSET
;
150 // The view and event attributes
152 * The sequence diagram view reference.
154 protected SDView fView
= null;
156 * The current sequence diagram frame reference.
158 protected Frame fFrame
= null;
160 * The list of sequence diagram events of current page.
162 protected List
<ITmfSyncSequenceDiagramEvent
> fEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>();
164 // Checkpoint and page attributes
166 * The checkpoints of the whole sequence diagram trace (i.e. start time stamp of each page)
168 protected List
<TmfTimeRange
> fCheckPoints
= new ArrayList
<TmfTimeRange
>(MAX_NUM_OF_MSG
);
170 * The current page displayed.
172 volatile protected int fCurrentPage
= 0;
174 * The current time selected.
176 protected ITmfTimestamp fCurrentTime
= null;
178 * Flag to specify that selection of message is done by selection or by signal.
180 volatile protected boolean fIsSelect
= false;
184 * The job for searching across pages.
186 protected SearchJob fFindJob
= null;
188 * List of found nodes within a page.
190 protected List
<GraphNode
> fFindResults
= new ArrayList
<GraphNode
>();
192 * The current find criteria reference
194 protected Criteria fFindCriteria
= null;
196 * The current find index within the list of found nodes (<code>fFindeResults</code> within a page.
198 volatile protected int fCurrentFindIndex
= 0;
202 * The list of active filters.
204 protected List
<FilterCriteria
> fFilterCriteria
= null;
206 // Thread synchronization
208 * The synchronization lock.
210 protected ReentrantLock fLock
= new ReentrantLock();
212 // ------------------------------------------------------------------------
214 // ------------------------------------------------------------------------
216 * Default constructor
218 public TmfUml2SDSyncLoader() {
225 * @param name Name of loader
227 public TmfUml2SDSyncLoader(String name
) {
231 // ------------------------------------------------------------------------
233 // ------------------------------------------------------------------------
235 * Returns the current time if available else null.
237 * @return the current time if available else null
239 public ITmfTimestamp
getCurrentTime() {
242 if (fCurrentTime
!= null) {
252 * Waits for the page request to be completed
254 public void waitForCompletion() {
256 ITmfEventRequest request
= fPageRequest
;
258 if (request
!= null) {
260 request
.waitForCompletion();
261 } catch (InterruptedException e
) {
268 * Signal handler for the trace selected signal.
270 * Spawns a request to index the trace (checkpoints creation) as well as it fills
273 * @param signal The trace selected signal
277 public void traceSelected(TmfTraceSelectedSignal signal
) {
281 // Update the trace reference
282 ITmfTrace trace
= signal
.getTrace();
283 if (!trace
.equals(fTrace
)) {
289 final Job job
= new IndexingJob("Indexing " + getName() + "..."); //$NON-NLS-1$ //$NON-NLS-2$
293 if (fIndexRequest
!= null && !fIndexRequest
.isCompleted()) {
294 fIndexRequest
.cancel();
297 cancelOngoingRequests();
300 TmfTimeRange window
= TmfTimeRange
.ETERNITY
;
302 fIndexRequest
= new TmfEventRequest(ITmfEvent
.class, window
, TmfDataRequest
.ALL_DATA
, DEFAULT_BLOCK_SIZE
, ITmfDataRequest
.ExecutionType
.BACKGROUND
) {
304 private ITmfTimestamp fFirstTime
= null;
305 private ITmfTimestamp fLastTime
= null;
306 private int fNbSeqEvents
= 0;
307 private final List
<ITmfSyncSequenceDiagramEvent
> fSdEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>(MAX_NUM_OF_MSG
);
311 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
314 public void handleData(ITmfEvent event
) {
315 super.handleData(event
);
317 ITmfSyncSequenceDiagramEvent sdEvent
= getSequnceDiagramEvent(event
);
319 if (sdEvent
!= null) {
322 if (fFirstTime
== null) {
323 fFirstTime
= event
.getTimestamp();
326 fLastTime
= event
.getTimestamp();
328 if ((fNbSeqEvents
% MAX_NUM_OF_MSG
) == 0) {
331 fCheckPoints
.add(new TmfTimeRange(fFirstTime
, fLastTime
));
333 fView
.updateCoolBar();
342 if (fNbSeqEvents
> MAX_NUM_OF_MSG
) {
347 fSdEvents
.add(sdEvent
);
349 if (fNbSeqEvents
== MAX_NUM_OF_MSG
) {
350 fillCurrentPage(fSdEvents
);
357 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleSuccess()
360 public void handleSuccess() {
361 if ((fFirstTime
!= null) && (fLastTime
!= null)) {
365 fCheckPoints
.add(new TmfTimeRange(fFirstTime
, fLastTime
));
367 fView
.updateCoolBar();
374 if (fNbSeqEvents
<= MAX_NUM_OF_MSG
) {
375 fillCurrentPage(fSdEvents
);
378 super.handleSuccess();
383 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleCompleted()
386 public void handleCompleted() {
387 if (fEvents
.isEmpty()) {
388 fFrame
= new Frame();
389 fView
.setFrameSync(fFrame
);
391 super.handleCompleted();
396 fTrace
.sendRequest(fIndexRequest
);
404 * Signal handler for the trace closed signal.
406 * @param signal The trace closed signal
410 public void traceClosed(TmfTraceClosedSignal signal
) {
411 if (signal
.getTrace() != fTrace
) {
416 if (fIndexRequest
!= null) {
417 if (!fIndexRequest
.isCompleted()) {
418 fIndexRequest
.cancel();
420 fIndexRequest
= null;
423 cancelOngoingRequests();
425 if (fFilterCriteria
!= null) {
426 fFilterCriteria
.clear();
429 FilterListDialog
.deactivateSavedGlobalFilters();
439 * Moves to the page that contains the time provided by the signal. The messages will be selected
440 * if the provided time is the time of a message.
442 * @param signal The Time synch signal.
445 public void synchToTime(TmfTimeSynchSignal signal
) {
448 if ((signal
.getSource() != this) && (fFrame
!= null) && (fCheckPoints
.size() > 0)) {
449 fCurrentTime
= signal
.getCurrentTime();
459 * Moves to the page that contains the current time provided by signal.
460 * No message will be selected however the focus will be set to the message
461 * if the provided time is the time of a message.
463 * @param signal The time range sync signal
466 public void synchToTimeRange(TmfRangeSynchSignal signal
) {
469 if ((signal
.getSource() != this) && (fFrame
!= null) && !fIsSignalSent
&& (fCheckPoints
.size() > 0)) {
470 TmfTimeRange newTimeRange
= signal
.getCurrentRange();
471 ITmfTimestamp delta
= newTimeRange
.getEndTime().getDelta(newTimeRange
.getStartTime());
472 fInitialWindow
= delta
.getValue();
475 fCurrentTime
= newTimeRange
.getStartTime();
487 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#setViewer(org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView)
490 public void setViewer(SDView viewer
) {
495 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
496 fView
.setSDFindProvider(this);
497 fView
.setSDPagingProvider(this);
498 fView
.setSDFilterProvider(this);
502 IEditorPart editor
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
503 if (editor
instanceof ITmfTraceEditor
) {
504 ITmfTrace trace
= ((ITmfTraceEditor
) editor
).getTrace();
506 traceSelected(new TmfTraceSelectedSignal(this, trace
));
516 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#getTitleString()
519 public String
getTitleString() {
525 * @see org.eclipse.linuxtools.tmf.component.TmfComponent#dispose()
528 public void dispose() {
532 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
533 // During Eclipse shutdown the active workbench window is null
534 if (window
!= null) {
535 window
.getSelectionService().removePostSelectionListener(this);
537 fView
.setSDFindProvider(null);
538 fView
.setSDPagingProvider(null);
539 fView
.setSDFilterProvider(null);
548 * @see org.eclipse.hyades.uml2sd.ui.actions.provider.ISDGraphNodeSupporter#isNodeSupported(int)
551 public boolean isNodeSupported(int nodeType
) {
553 case ISDGraphNodeSupporter
.LIFELINE
:
554 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
565 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter#getNodeName(int, java.lang.String)
568 public String
getNodeName(int nodeType
, String loaderClassName
) {
570 case ISDGraphNodeSupporter
.LIFELINE
:
571 return Messages
.TmfUml2SDSyncLoader_CategoryLifeline
;
572 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
573 return Messages
.TmfUml2SDSyncLoader_CategoryMessage
;
577 return ""; //$NON-NLS-1$
582 * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
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 broadcast(new TmfTimeSynchSignal(this, syncMsg
.getStartTime()));
599 * org.eclipse.hyades.uml2sd.ui.actions.provider.ISDFindProvider#find(org.eclipse.hyades.uml2sd.ui.actions.widgets.Criteria)
602 public boolean find(Criteria toSearch
) {
605 if (fFrame
== null) {
609 if ((fFindResults
== null) || (fFindCriteria
== null) || !fFindCriteria
.compareTo(toSearch
)) {
610 fFindResults
= new CopyOnWriteArrayList
<GraphNode
>();
611 fFindCriteria
= toSearch
;
612 if (fFindCriteria
.isLifeLineSelected()) {
613 for (int i
= 0; i
< fFrame
.lifeLinesCount(); i
++) {
614 if (fFindCriteria
.matches(fFrame
.getLifeline(i
).getName())) {
615 fFindResults
.add(fFrame
.getLifeline(i
));
620 ArrayList
<GraphNode
> msgs
= new ArrayList
<GraphNode
>();
621 if (fFindCriteria
.isSyncMessageSelected()) {
622 for (int i
= 0; i
< fFrame
.syncMessageCount(); i
++) {
623 if (fFindCriteria
.matches(fFrame
.getSyncMessage(i
).getName())) {
624 msgs
.add(fFrame
.getSyncMessage(i
));
629 if (!msgs
.isEmpty()) {
630 fFindResults
.addAll(msgs
);
633 @SuppressWarnings("rawtypes")
634 List selection
= fView
.getSDWidget().getSelection();
635 if ((selection
!= null) && (selection
.size() == 1)) {
636 fCurrentFindIndex
= fFindResults
.indexOf(selection
.get(0)) + 1;
638 fCurrentFindIndex
= 0;
644 if (fFindResults
.size() > fCurrentFindIndex
) {
645 GraphNode current
= fFindResults
.get(fCurrentFindIndex
);
646 fView
.getSDWidget().moveTo(current
);
650 fCurrentFindIndex
=0;
651 return findInNextPages(fFindCriteria
); // search in other page
659 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFindProvider#cancel()
662 public void cancel() {
663 cancelOngoingRequests();
668 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFilterProvider#filter(java.util.List)
670 @SuppressWarnings("unchecked")
672 public boolean filter(List
<?
> filters
) {
675 cancelOngoingRequests();
677 if (filters
== null) {
678 fFilterCriteria
= new ArrayList
<FilterCriteria
>();
680 List
<FilterCriteria
> list
= (List
<FilterCriteria
>)filters
;
681 fFilterCriteria
= new ArrayList
<FilterCriteria
>(list
);
684 fillCurrentPage(fEvents
);
694 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasNextPage()
697 public boolean hasNextPage() {
700 int size
= fCheckPoints
.size();
702 return fCurrentPage
< (size
- 1);
712 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasPrevPage()
715 public boolean hasPrevPage() {
718 return fCurrentPage
> 0;
726 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#nextPage()
729 public void nextPage() {
733 if (fCurrentPage
>= (fCheckPoints
.size() - 1)) {
737 cancelOngoingRequests();
748 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#prevPage()
751 public void prevPage() {
755 if (fCurrentPage
<= 0) {
759 cancelOngoingRequests();
770 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#firstPage()
773 public void firstPage() {
777 cancelOngoingRequests();
788 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#lastPage()
791 public void lastPage() {
794 cancelOngoingRequests();
796 fCurrentPage
= fCheckPoints
.size() - 1;
805 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#currentPage()
808 public int currentPage() {
819 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pagesCount()
822 public int pagesCount() {
825 return fCheckPoints
.size();
833 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pageNumberChanged(int)
836 public void pageNumberChanged(int pagenNumber
) {
837 int localPageNumber
= pagenNumber
;
841 cancelOngoingRequests();
843 if (localPageNumber
< 0) {
846 int size
= fCheckPoints
.size();
847 if (localPageNumber
> (size
- 1)) {
848 localPageNumber
= size
- 1;
850 fCurrentPage
= localPageNumber
;
859 * @see org.eclipse.linuxtools.tmf.component.TmfComponent#broadcast(org.eclipse.linuxtools.tmf.signal.TmfSignal)
862 public void broadcast(TmfSignal signal
) {
863 fIsSignalSent
= true;
864 super.broadcast(signal
);
865 fIsSignalSent
= false;
869 * Cancels any ongoing find operation
871 protected void cancelOngoingRequests() {
874 // Cancel the search thread
875 if (fFindJob
!= null) {
880 fFindCriteria
= null;
881 fCurrentFindIndex
= 0;
883 if (fPageRequest
!= null) {
884 if (!fPageRequest
.isCompleted()) {
885 fPageRequest
.cancel();
895 * Resets loader attributes
897 protected void resetLoader() {
902 fCheckPoints
.clear();
904 fCurrentFindIndex
= 0;
905 fFindCriteria
= null;
907 fInitialWindow
= INITIAL_WINDOW_OFFSET
;
908 fView
.setFrameSync(new Frame());
918 * Fills current page with sequence diagram content.
920 * @param events sequence diagram events
922 protected void fillCurrentPage(List
<ITmfSyncSequenceDiagramEvent
> events
) {
926 fEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>(events
);
927 if (fView
!= null && !events
.isEmpty()) {
928 fView
.toggleWaitCursorAsync(true);
934 final Frame frame
= new Frame();
936 if (!events
.isEmpty()) {
937 Map
<String
, Lifeline
> nodeToLifelineMap
= new HashMap
<String
, Lifeline
>();
939 frame
.setName(Messages
.TmfUml2SDSyncLoader_FrameName
);
941 for (int i
= 0; i
< events
.size(); i
++) {
943 ITmfSyncSequenceDiagramEvent sdEvent
= events
.get(i
);
945 if ((nodeToLifelineMap
.get(sdEvent
.getSender()) == null) && (!filterLifeLine(sdEvent
.getSender()))) {
946 Lifeline lifeline
= new Lifeline();
947 lifeline
.setName(sdEvent
.getSender());
948 nodeToLifelineMap
.put(sdEvent
.getSender(), lifeline
);
949 frame
.addLifeLine(lifeline
);
952 if ((nodeToLifelineMap
.get(sdEvent
.getReceiver()) == null) && (!filterLifeLine(sdEvent
.getReceiver()))) {
953 Lifeline lifeline
= new Lifeline();
954 lifeline
.setName(sdEvent
.getReceiver());
955 nodeToLifelineMap
.put(sdEvent
.getReceiver(), lifeline
);
956 frame
.addLifeLine(lifeline
);
960 int eventOccurence
= 1;
962 for (int i
= 0; i
< events
.size(); i
++) {
963 ITmfSyncSequenceDiagramEvent sdEvent
= events
.get(i
);
965 // Check message filter
966 if (filterMessage(sdEvent
)) {
970 // Set the message sender and receiver
971 Lifeline startLifeline
= nodeToLifelineMap
.get(sdEvent
.getSender());
972 Lifeline endLifeline
= nodeToLifelineMap
.get(sdEvent
.getReceiver());
974 // Check if any of the lifelines were filtered
975 if ((startLifeline
== null) || (endLifeline
== null)) {
979 int tmp
= Math
.max(startLifeline
.getEventOccurrence(), endLifeline
.getEventOccurrence());
980 eventOccurence
= Math
.max(eventOccurence
, tmp
);
982 startLifeline
.setCurrentEventOccurrence(eventOccurence
);
983 endLifeline
.setCurrentEventOccurrence(eventOccurence
);
985 TmfSyncMessage message
= new TmfSyncMessage(sdEvent
, eventOccurence
++);
987 message
.setStartLifeline(startLifeline
);
988 message
.setEndLifeline(endLifeline
);
990 message
.setTime(sdEvent
.getStartTime());
992 // add the message to the frame
993 frame
.addMessage(message
);
998 if (!fView
.getSDWidget().isDisposed()) {
999 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1006 // check if view was disposed in the meanwhile
1007 if ((fView
!= null) && (!fView
.getSDWidget().isDisposed())) {
1009 fView
.setFrame(fFrame
);
1011 if (fCurrentTime
!= null) {
1012 moveToMessageInPage();
1015 if (fFindCriteria
!= null) {
1016 find(fFindCriteria
);
1019 fView
.toggleWaitCursorAsync(false);
1036 * Moves to a certain message defined by timestamp (across pages)
1038 protected void moveToMessage() {
1043 page
= getPage(fCurrentTime
);
1045 if (page
== fCurrentPage
) {
1046 moveToMessageInPage();
1049 fCurrentPage
= page
;
1057 * Moves to a certain message defined by timestamp in current page
1059 protected void moveToMessageInPage() {
1062 if (!fView
.getSDWidget().isDisposed()) {
1063 // Check for GUI thread
1064 if(Display
.getCurrent() != null) {
1065 // Already in GUI thread - execute directly
1066 TmfSyncMessage prevMessage
= null;
1067 TmfSyncMessage syncMessage
= null;
1068 boolean isExactTime
= false;
1069 for (int i
= 0; i
< fFrame
.syncMessageCount(); i
++) {
1070 if (fFrame
.getSyncMessage(i
) instanceof TmfSyncMessage
) {
1071 syncMessage
= (TmfSyncMessage
) fFrame
.getSyncMessage(i
);
1072 if (syncMessage
.getStartTime().compareTo(fCurrentTime
, false) == 0) {
1075 } else if ((syncMessage
.getStartTime().compareTo(fCurrentTime
, false) > 0) && (prevMessage
!= null)) {
1076 syncMessage
= prevMessage
;
1079 prevMessage
= syncMessage
;
1082 if (fIsSelect
&& isExactTime
) {
1083 fView
.getSDWidget().moveTo(syncMessage
);
1086 fView
.getSDWidget().ensureVisible(syncMessage
);
1087 fView
.getSDWidget().clearSelection();
1088 fView
.getSDWidget().redraw();
1092 // Not in GUI thread - queue action in GUI thread.
1093 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1096 moveToMessageInPage();
1108 * Moves to a certain message defined by timestamp (across pages)
1110 protected void moveToPage() {
1115 * Moves to a certain page.
1117 * @param notifyAll true to broadcast time range signal to other signal handlers else false
1119 protected void moveToPage(boolean notifyAll
) {
1121 TmfTimeRange window
= null;
1126 if (fCurrentPage
> fCheckPoints
.size()) {
1129 window
= fCheckPoints
.get(fCurrentPage
);
1134 if (window
== null) {
1135 window
= TmfTimeRange
.ETERNITY
;
1138 fPageRequest
= new TmfEventRequest(ITmfEvent
.class, window
, TmfDataRequest
.ALL_DATA
, 1, ITmfDataRequest
.ExecutionType
.FOREGROUND
) {
1139 private final List
<ITmfSyncSequenceDiagramEvent
> fSdEvent
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>();
1142 public void handleData(ITmfEvent event
) {
1143 super.handleData(event
);
1145 ITmfSyncSequenceDiagramEvent sdEvent
= getSequnceDiagramEvent(event
);
1147 if (sdEvent
!= null) {
1148 fSdEvent
.add(sdEvent
);
1153 public void handleSuccess() {
1154 fillCurrentPage(fSdEvent
);
1155 super.handleSuccess();
1160 fTrace
.sendRequest(fPageRequest
);
1163 TmfTimeRange timeRange
= getSignalTimeRange(window
.getStartTime());
1164 broadcast(new TmfRangeSynchSignal(this, timeRange
, timeRange
.getStartTime()));
1169 * Gets page that contains timestamp
1171 * @param time The timestamp
1172 * @return page that contains the time
1174 protected int getPage(ITmfTimestamp time
) {
1179 size
= fCheckPoints
.size();
1180 for (page
= 0; page
< size
; page
++) {
1181 TmfTimeRange timeRange
= fCheckPoints
.get(page
);
1182 if (timeRange
.getEndTime().compareTo(time
, false) >= 0) {
1196 * Background search in trace for expression in criteria.
1198 * @param findCriteria The find criteria
1199 * @return true if background request was started else false
1201 protected boolean findInNextPages(Criteria findCriteria
) {
1204 if (fFindJob
!= null) {
1208 int nextPage
= fCurrentPage
+ 1;
1210 if ((nextPage
) >= fCheckPoints
.size()) {
1211 // we are at the end
1215 TmfTimeRange window
= new TmfTimeRange(fCheckPoints
.get(nextPage
).getStartTime(), fCheckPoints
.get(fCheckPoints
.size()-1).getEndTime());
1216 fFindJob
= new SearchJob(findCriteria
, window
);
1217 fFindJob
.schedule();
1218 fView
.toggleWaitCursorAsync(true);
1226 * Gets time range for time range signal.
1228 * @param startTime The start time of time range.
1229 * @return the time range
1231 protected TmfTimeRange
getSignalTimeRange(ITmfTimestamp startTime
) {
1234 TmfTimestamp initialEndOfWindow
= new TmfTimestamp(startTime
.getValue() + fInitialWindow
, startTime
.getScale(), startTime
.getPrecision());
1235 return new TmfTimeRange(startTime
, initialEndOfWindow
);
1243 * Checks if filter criteria matches the message name in given SD event.
1245 * @param sdEvent The SD event to check
1246 * @return true if match else false.
1248 protected boolean filterMessage(ITmfSyncSequenceDiagramEvent sdEvent
) {
1251 if (fFilterCriteria
!= null) {
1252 for(FilterCriteria criteria
: fFilterCriteria
) {
1253 if (criteria
.isActive() && criteria
.getCriteria().isSyncMessageSelected() && criteria
.getCriteria().matches(sdEvent
.getName())) {
1265 * Checks if filter criteria matches a lifeline name (sender or receiver) in given SD event.
1267 * @param lifeline the message receiver
1268 * @return true if match else false.
1270 protected boolean filterLifeLine(String lifeline
) {
1273 if (fFilterCriteria
!= null) {
1274 for(FilterCriteria criteria
: fFilterCriteria
) {
1275 if (criteria
.isActive() && criteria
.getCriteria().isLifeLineSelected() && criteria
.getCriteria().matches(lifeline
)) {
1287 * Job to search in trace for given time range.
1289 protected class SearchJob
extends Job
{
1292 * The search event request.
1294 final protected SearchEventRequest fSearchRequest
;
1299 * @param findCriteria The search criteria
1300 * @param window Time range to search in
1302 public SearchJob(Criteria findCriteria
, TmfTimeRange window
) {
1303 super(Messages
.TmfUml2SDSyncLoader_SearchJobDescrition
);
1304 fSearchRequest
= new SearchEventRequest(window
, TmfDataRequest
.ALL_DATA
, 1, ITmfDataRequest
.ExecutionType
.FOREGROUND
, findCriteria
);
1309 * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
1312 protected IStatus
run(IProgressMonitor monitor
) {
1313 fSearchRequest
.setMonitor(monitor
);
1315 fTrace
.sendRequest(fSearchRequest
);
1318 fSearchRequest
.waitForCompletion();
1319 } catch (InterruptedException e
) {
1320 Activator
.getDefault().logError("Search request interrupted!", e
); //$NON-NLS-1$
1323 IStatus status
= Status
.OK_STATUS
;
1324 if (fSearchRequest
.isFound() && (fSearchRequest
.getFoundTime() != null)) {
1325 fCurrentTime
= fSearchRequest
.getFoundTime();
1327 // Avoid double-selection. Selection will be done when calling find(criteria)
1328 // after moving to relevant page
1330 if (!fView
.getSDWidget().isDisposed()) {
1331 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1341 if (monitor
.isCanceled()) {
1342 status
= Status
.CANCEL_STATUS
;
1345 // String was not found
1346 status
= new Status(IStatus
.WARNING
, Activator
.PLUGIN_ID
, Messages
.TmfUml2SDSyncLoader_SearchNotFound
);
1348 setProperty(IProgressConstants
.KEEP_PROPERTY
, Boolean
.TRUE
);
1354 fView
.toggleWaitCursorAsync(false);
1365 * @see org.eclipse.core.runtime.jobs.Job#canceling()
1368 protected void canceling() {
1369 fSearchRequest
.cancel();
1380 * TMF event request for searching within trace.
1382 protected class SearchEventRequest
extends TmfEventRequest
{
1385 * The find criteria.
1387 final private Criteria fCriteria
;
1389 * A progress monitor
1391 private IProgressMonitor fMonitor
;
1393 * Flag to indicate that node was found according the criteria .
1395 private boolean fIsFound
= false;
1397 * Time stamp of found item.
1399 private ITmfTimestamp fFoundTime
= null;
1403 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1404 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1405 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1406 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1407 * @param criteria The search criteria
1409 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType execType
, Criteria criteria
) {
1410 this(range
, nbRequested
, blockSize
, execType
, criteria
, null);
1415 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1416 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1417 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1418 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1419 * @param criteria The search criteria
1420 * @param monitor progress monitor
1422 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType execType
, Criteria criteria
, IProgressMonitor monitor
) {
1423 super(ITmfEvent
.class, range
, nbRequested
, blockSize
, execType
);
1424 fCriteria
= new Criteria(criteria
);
1430 * @see org.eclipse.linuxtools.tmf.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.event.TmfData)
1433 public void handleData(ITmfEvent event
) {
1434 super.handleData(event
);
1436 if ((fMonitor
!= null) && fMonitor
.isCanceled()) {
1441 ITmfSyncSequenceDiagramEvent sdEvent
= getSequnceDiagramEvent(event
);
1443 if (sdEvent
!= null) {
1445 if (fCriteria
.isLifeLineSelected()) {
1446 if (fCriteria
.matches(sdEvent
.getSender())) {
1447 fFoundTime
= event
.getTimestamp();
1452 if (fCriteria
.matches(sdEvent
.getReceiver())) {
1453 fFoundTime
= event
.getTimestamp();
1459 if (fCriteria
.isSyncMessageSelected() && fCriteria
.matches(sdEvent
.getName())) {
1460 fFoundTime
= event
.getTimestamp();
1468 * Set progress monitor.
1470 * @param monitor The monitor to assign
1472 public void setMonitor(IProgressMonitor monitor
) {
1477 * Check if find criteria was met.
1479 * @return true if find criteria was met.
1481 public boolean isFound() {
1486 * Returns timestamp of found time.
1488 * @return timestamp of found time.
1490 public ITmfTimestamp
getFoundTime() {
1496 * Job class to provide progress monitor feedback.
1499 * @author Bernd Hufmann
1502 protected static class IndexingJob
extends Job
{
1504 public IndexingJob(String name
) {
1509 protected IStatus
run(IProgressMonitor monitor
) {
1510 while (!monitor
.isCanceled()) {
1513 } catch (InterruptedException e
) {
1514 return Status
.OK_STATUS
;
1518 return Status
.OK_STATUS
;
1524 * Returns sequence diagram event if details in given event are available else null.
1526 * @param tmfEvent Event to parse for sequence diagram event details
1527 * @return sequence diagram event if details are available else null
1529 protected ITmfSyncSequenceDiagramEvent
getSequnceDiagramEvent(ITmfEvent tmfEvent
){
1530 //type = .*RECEIVE.* or .*SEND.*
1531 //content = sender:<sender name>:receiver:<receiver name>,signal:<signal name>
1532 String eventType
= tmfEvent
.getType().toString();
1533 if (eventType
.contains(Messages
.TmfUml2SDSyncCloader_EventTypeSend
) || eventType
.contains(Messages
.TmfUml2SDSyncCloader_EventTypeReceive
)) {
1534 Object sender
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncCloader_FieldSender
);
1535 Object receiver
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncCloader_FieldReceiver
);
1536 Object name
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncCloader_FieldSignal
);
1537 if ((sender
instanceof ITmfEventField
) && (receiver
instanceof ITmfEventField
) && (name
instanceof ITmfEventField
)) {
1538 ITmfSyncSequenceDiagramEvent sdEvent
= new TmfSyncSequenceDiagramEvent(tmfEvent
,
1539 ((ITmfEventField
) sender
).getValue().toString(),
1540 ((ITmfEventField
) receiver
).getValue().toString(),
1541 ((ITmfEventField
) name
).getValue().toString());