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
= fView
.getSite().getPage().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);
538 if (fIndexRequest
!= null) {
539 if (!fIndexRequest
.isCompleted()) {
540 fIndexRequest
.cancel();
542 fIndexRequest
= null;
544 cancelOngoingRequests();
546 fView
.setSDFindProvider(null);
547 fView
.setSDPagingProvider(null);
548 fView
.setSDFilterProvider(null);
557 * @see org.eclipse.hyades.uml2sd.ui.actions.provider.ISDGraphNodeSupporter#isNodeSupported(int)
560 public boolean isNodeSupported(int nodeType
) {
562 case ISDGraphNodeSupporter
.LIFELINE
:
563 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
574 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter#getNodeName(int, java.lang.String)
577 public String
getNodeName(int nodeType
, String loaderClassName
) {
579 case ISDGraphNodeSupporter
.LIFELINE
:
580 return Messages
.TmfUml2SDSyncLoader_CategoryLifeline
;
581 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
582 return Messages
.TmfUml2SDSyncLoader_CategoryMessage
;
586 return ""; //$NON-NLS-1$
591 * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
594 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
595 ISelection sel
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
596 if ((sel
!= null) && (sel
instanceof StructuredSelection
)) {
597 StructuredSelection stSel
= (StructuredSelection
) sel
;
598 if (stSel
.getFirstElement() instanceof TmfSyncMessage
) {
599 TmfSyncMessage syncMsg
= ((TmfSyncMessage
) stSel
.getFirstElement());
600 broadcast(new TmfTimeSynchSignal(this, syncMsg
.getStartTime()));
608 * org.eclipse.hyades.uml2sd.ui.actions.provider.ISDFindProvider#find(org.eclipse.hyades.uml2sd.ui.actions.widgets.Criteria)
611 public boolean find(Criteria toSearch
) {
614 if (fFrame
== null) {
618 if ((fFindResults
== null) || (fFindCriteria
== null) || !fFindCriteria
.compareTo(toSearch
)) {
619 fFindResults
= new CopyOnWriteArrayList
<GraphNode
>();
620 fFindCriteria
= toSearch
;
621 if (fFindCriteria
.isLifeLineSelected()) {
622 for (int i
= 0; i
< fFrame
.lifeLinesCount(); i
++) {
623 if (fFindCriteria
.matches(fFrame
.getLifeline(i
).getName())) {
624 fFindResults
.add(fFrame
.getLifeline(i
));
629 ArrayList
<GraphNode
> msgs
= new ArrayList
<GraphNode
>();
630 if (fFindCriteria
.isSyncMessageSelected()) {
631 for (int i
= 0; i
< fFrame
.syncMessageCount(); i
++) {
632 if (fFindCriteria
.matches(fFrame
.getSyncMessage(i
).getName())) {
633 msgs
.add(fFrame
.getSyncMessage(i
));
638 if (!msgs
.isEmpty()) {
639 fFindResults
.addAll(msgs
);
642 @SuppressWarnings("rawtypes")
643 List selection
= fView
.getSDWidget().getSelection();
644 if ((selection
!= null) && (selection
.size() == 1)) {
645 fCurrentFindIndex
= fFindResults
.indexOf(selection
.get(0)) + 1;
647 fCurrentFindIndex
= 0;
653 if (fFindResults
.size() > fCurrentFindIndex
) {
654 GraphNode current
= fFindResults
.get(fCurrentFindIndex
);
655 fView
.getSDWidget().moveTo(current
);
659 fCurrentFindIndex
=0;
660 return findInNextPages(fFindCriteria
); // search in other page
668 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFindProvider#cancel()
671 public void cancel() {
672 cancelOngoingRequests();
677 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFilterProvider#filter(java.util.List)
679 @SuppressWarnings("unchecked")
681 public boolean filter(List
<?
> filters
) {
684 cancelOngoingRequests();
686 if (filters
== null) {
687 fFilterCriteria
= new ArrayList
<FilterCriteria
>();
689 List
<FilterCriteria
> list
= (List
<FilterCriteria
>)filters
;
690 fFilterCriteria
= new ArrayList
<FilterCriteria
>(list
);
693 fillCurrentPage(fEvents
);
703 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasNextPage()
706 public boolean hasNextPage() {
709 int size
= fCheckPoints
.size();
711 return fCurrentPage
< (size
- 1);
721 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasPrevPage()
724 public boolean hasPrevPage() {
727 return fCurrentPage
> 0;
735 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#nextPage()
738 public void nextPage() {
742 if (fCurrentPage
>= (fCheckPoints
.size() - 1)) {
746 cancelOngoingRequests();
757 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#prevPage()
760 public void prevPage() {
764 if (fCurrentPage
<= 0) {
768 cancelOngoingRequests();
779 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#firstPage()
782 public void firstPage() {
786 cancelOngoingRequests();
797 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#lastPage()
800 public void lastPage() {
803 cancelOngoingRequests();
805 fCurrentPage
= fCheckPoints
.size() - 1;
814 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#currentPage()
817 public int currentPage() {
828 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pagesCount()
831 public int pagesCount() {
834 return fCheckPoints
.size();
842 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pageNumberChanged(int)
845 public void pageNumberChanged(int pagenNumber
) {
846 int localPageNumber
= pagenNumber
;
850 cancelOngoingRequests();
852 if (localPageNumber
< 0) {
855 int size
= fCheckPoints
.size();
856 if (localPageNumber
> (size
- 1)) {
857 localPageNumber
= size
- 1;
859 fCurrentPage
= localPageNumber
;
868 * @see org.eclipse.linuxtools.tmf.component.TmfComponent#broadcast(org.eclipse.linuxtools.tmf.signal.TmfSignal)
871 public void broadcast(TmfSignal signal
) {
872 fIsSignalSent
= true;
873 super.broadcast(signal
);
874 fIsSignalSent
= false;
878 * Cancels any ongoing find operation
880 protected void cancelOngoingRequests() {
883 // Cancel the search thread
884 if (fFindJob
!= null) {
889 fFindCriteria
= null;
890 fCurrentFindIndex
= 0;
892 if (fPageRequest
!= null) {
893 if (!fPageRequest
.isCompleted()) {
894 fPageRequest
.cancel();
904 * Resets loader attributes
906 protected void resetLoader() {
911 fCheckPoints
.clear();
913 fCurrentFindIndex
= 0;
914 fFindCriteria
= null;
916 fInitialWindow
= INITIAL_WINDOW_OFFSET
;
917 fView
.setFrameSync(new Frame());
927 * Fills current page with sequence diagram content.
929 * @param events sequence diagram events
931 protected void fillCurrentPage(List
<ITmfSyncSequenceDiagramEvent
> events
) {
935 fEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>(events
);
936 if (fView
!= null && !events
.isEmpty()) {
937 fView
.toggleWaitCursorAsync(true);
943 final Frame frame
= new Frame();
945 if (!events
.isEmpty()) {
946 Map
<String
, Lifeline
> nodeToLifelineMap
= new HashMap
<String
, Lifeline
>();
948 frame
.setName(Messages
.TmfUml2SDSyncLoader_FrameName
);
950 for (int i
= 0; i
< events
.size(); i
++) {
952 ITmfSyncSequenceDiagramEvent sdEvent
= events
.get(i
);
954 if ((nodeToLifelineMap
.get(sdEvent
.getSender()) == null) && (!filterLifeLine(sdEvent
.getSender()))) {
955 Lifeline lifeline
= new Lifeline();
956 lifeline
.setName(sdEvent
.getSender());
957 nodeToLifelineMap
.put(sdEvent
.getSender(), lifeline
);
958 frame
.addLifeLine(lifeline
);
961 if ((nodeToLifelineMap
.get(sdEvent
.getReceiver()) == null) && (!filterLifeLine(sdEvent
.getReceiver()))) {
962 Lifeline lifeline
= new Lifeline();
963 lifeline
.setName(sdEvent
.getReceiver());
964 nodeToLifelineMap
.put(sdEvent
.getReceiver(), lifeline
);
965 frame
.addLifeLine(lifeline
);
969 int eventOccurence
= 1;
971 for (int i
= 0; i
< events
.size(); i
++) {
972 ITmfSyncSequenceDiagramEvent sdEvent
= events
.get(i
);
974 // Check message filter
975 if (filterMessage(sdEvent
)) {
979 // Set the message sender and receiver
980 Lifeline startLifeline
= nodeToLifelineMap
.get(sdEvent
.getSender());
981 Lifeline endLifeline
= nodeToLifelineMap
.get(sdEvent
.getReceiver());
983 // Check if any of the lifelines were filtered
984 if ((startLifeline
== null) || (endLifeline
== null)) {
988 int tmp
= Math
.max(startLifeline
.getEventOccurrence(), endLifeline
.getEventOccurrence());
989 eventOccurence
= Math
.max(eventOccurence
, tmp
);
991 startLifeline
.setCurrentEventOccurrence(eventOccurence
);
992 endLifeline
.setCurrentEventOccurrence(eventOccurence
);
994 TmfSyncMessage message
= new TmfSyncMessage(sdEvent
, eventOccurence
++);
996 message
.setStartLifeline(startLifeline
);
997 message
.setEndLifeline(endLifeline
);
999 message
.setTime(sdEvent
.getStartTime());
1001 // add the message to the frame
1002 frame
.addMessage(message
);
1007 if (!fView
.getSDWidget().isDisposed()) {
1008 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1015 // check if view was disposed in the meanwhile
1016 if ((fView
!= null) && (!fView
.getSDWidget().isDisposed())) {
1018 fView
.setFrame(fFrame
);
1020 if (fCurrentTime
!= null) {
1021 moveToMessageInPage();
1024 if (fFindCriteria
!= null) {
1025 find(fFindCriteria
);
1028 fView
.toggleWaitCursorAsync(false);
1045 * Moves to a certain message defined by timestamp (across pages)
1047 protected void moveToMessage() {
1052 page
= getPage(fCurrentTime
);
1054 if (page
== fCurrentPage
) {
1055 moveToMessageInPage();
1058 fCurrentPage
= page
;
1066 * Moves to a certain message defined by timestamp in current page
1068 protected void moveToMessageInPage() {
1071 if (!fView
.getSDWidget().isDisposed()) {
1072 // Check for GUI thread
1073 if(Display
.getCurrent() != null) {
1074 // Already in GUI thread - execute directly
1075 TmfSyncMessage prevMessage
= null;
1076 TmfSyncMessage syncMessage
= null;
1077 boolean isExactTime
= false;
1078 for (int i
= 0; i
< fFrame
.syncMessageCount(); i
++) {
1079 if (fFrame
.getSyncMessage(i
) instanceof TmfSyncMessage
) {
1080 syncMessage
= (TmfSyncMessage
) fFrame
.getSyncMessage(i
);
1081 if (syncMessage
.getStartTime().compareTo(fCurrentTime
, false) == 0) {
1084 } else if ((syncMessage
.getStartTime().compareTo(fCurrentTime
, false) > 0) && (prevMessage
!= null)) {
1085 syncMessage
= prevMessage
;
1088 prevMessage
= syncMessage
;
1091 if (fIsSelect
&& isExactTime
) {
1092 fView
.getSDWidget().moveTo(syncMessage
);
1095 fView
.getSDWidget().ensureVisible(syncMessage
);
1096 fView
.getSDWidget().clearSelection();
1097 fView
.getSDWidget().redraw();
1101 // Not in GUI thread - queue action in GUI thread.
1102 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1105 moveToMessageInPage();
1117 * Moves to a certain message defined by timestamp (across pages)
1119 protected void moveToPage() {
1124 * Moves to a certain page.
1126 * @param notifyAll true to broadcast time range signal to other signal handlers else false
1128 protected void moveToPage(boolean notifyAll
) {
1130 TmfTimeRange window
= null;
1135 if (fCurrentPage
> fCheckPoints
.size()) {
1138 window
= fCheckPoints
.get(fCurrentPage
);
1143 if (window
== null) {
1144 window
= TmfTimeRange
.ETERNITY
;
1147 fPageRequest
= new TmfEventRequest(ITmfEvent
.class, window
, TmfDataRequest
.ALL_DATA
, 1, ITmfDataRequest
.ExecutionType
.FOREGROUND
) {
1148 private final List
<ITmfSyncSequenceDiagramEvent
> fSdEvent
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>();
1151 public void handleData(ITmfEvent event
) {
1152 super.handleData(event
);
1154 ITmfSyncSequenceDiagramEvent sdEvent
= getSequnceDiagramEvent(event
);
1156 if (sdEvent
!= null) {
1157 fSdEvent
.add(sdEvent
);
1162 public void handleSuccess() {
1163 fillCurrentPage(fSdEvent
);
1164 super.handleSuccess();
1169 fTrace
.sendRequest(fPageRequest
);
1172 TmfTimeRange timeRange
= getSignalTimeRange(window
.getStartTime());
1173 broadcast(new TmfRangeSynchSignal(this, timeRange
, timeRange
.getStartTime()));
1178 * Gets page that contains timestamp
1180 * @param time The timestamp
1181 * @return page that contains the time
1183 protected int getPage(ITmfTimestamp time
) {
1188 size
= fCheckPoints
.size();
1189 for (page
= 0; page
< size
; page
++) {
1190 TmfTimeRange timeRange
= fCheckPoints
.get(page
);
1191 if (timeRange
.getEndTime().compareTo(time
, false) >= 0) {
1205 * Background search in trace for expression in criteria.
1207 * @param findCriteria The find criteria
1208 * @return true if background request was started else false
1210 protected boolean findInNextPages(Criteria findCriteria
) {
1213 if (fFindJob
!= null) {
1217 int nextPage
= fCurrentPage
+ 1;
1219 if ((nextPage
) >= fCheckPoints
.size()) {
1220 // we are at the end
1224 TmfTimeRange window
= new TmfTimeRange(fCheckPoints
.get(nextPage
).getStartTime(), fCheckPoints
.get(fCheckPoints
.size()-1).getEndTime());
1225 fFindJob
= new SearchJob(findCriteria
, window
);
1226 fFindJob
.schedule();
1227 fView
.toggleWaitCursorAsync(true);
1235 * Gets time range for time range signal.
1237 * @param startTime The start time of time range.
1238 * @return the time range
1240 protected TmfTimeRange
getSignalTimeRange(ITmfTimestamp startTime
) {
1243 TmfTimestamp initialEndOfWindow
= new TmfTimestamp(startTime
.getValue() + fInitialWindow
, startTime
.getScale(), startTime
.getPrecision());
1244 return new TmfTimeRange(startTime
, initialEndOfWindow
);
1252 * Checks if filter criteria matches the message name in given SD event.
1254 * @param sdEvent The SD event to check
1255 * @return true if match else false.
1257 protected boolean filterMessage(ITmfSyncSequenceDiagramEvent sdEvent
) {
1260 if (fFilterCriteria
!= null) {
1261 for(FilterCriteria criteria
: fFilterCriteria
) {
1262 if (criteria
.isActive() && criteria
.getCriteria().isSyncMessageSelected() && criteria
.getCriteria().matches(sdEvent
.getName())) {
1274 * Checks if filter criteria matches a lifeline name (sender or receiver) in given SD event.
1276 * @param lifeline the message receiver
1277 * @return true if match else false.
1279 protected boolean filterLifeLine(String lifeline
) {
1282 if (fFilterCriteria
!= null) {
1283 for(FilterCriteria criteria
: fFilterCriteria
) {
1284 if (criteria
.isActive() && criteria
.getCriteria().isLifeLineSelected() && criteria
.getCriteria().matches(lifeline
)) {
1296 * Job to search in trace for given time range.
1298 protected class SearchJob
extends Job
{
1301 * The search event request.
1303 final protected SearchEventRequest fSearchRequest
;
1308 * @param findCriteria The search criteria
1309 * @param window Time range to search in
1311 public SearchJob(Criteria findCriteria
, TmfTimeRange window
) {
1312 super(Messages
.TmfUml2SDSyncLoader_SearchJobDescrition
);
1313 fSearchRequest
= new SearchEventRequest(window
, TmfDataRequest
.ALL_DATA
, 1, ITmfDataRequest
.ExecutionType
.FOREGROUND
, findCriteria
);
1318 * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
1321 protected IStatus
run(IProgressMonitor monitor
) {
1322 fSearchRequest
.setMonitor(monitor
);
1324 fTrace
.sendRequest(fSearchRequest
);
1327 fSearchRequest
.waitForCompletion();
1328 } catch (InterruptedException e
) {
1329 Activator
.getDefault().logError("Search request interrupted!", e
); //$NON-NLS-1$
1332 IStatus status
= Status
.OK_STATUS
;
1333 if (fSearchRequest
.isFound() && (fSearchRequest
.getFoundTime() != null)) {
1334 fCurrentTime
= fSearchRequest
.getFoundTime();
1336 // Avoid double-selection. Selection will be done when calling find(criteria)
1337 // after moving to relevant page
1339 if (!fView
.getSDWidget().isDisposed()) {
1340 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1350 if (monitor
.isCanceled()) {
1351 status
= Status
.CANCEL_STATUS
;
1354 // String was not found
1355 status
= new Status(IStatus
.WARNING
, Activator
.PLUGIN_ID
, Messages
.TmfUml2SDSyncLoader_SearchNotFound
);
1357 setProperty(IProgressConstants
.KEEP_PROPERTY
, Boolean
.TRUE
);
1363 fView
.toggleWaitCursorAsync(false);
1374 * @see org.eclipse.core.runtime.jobs.Job#canceling()
1377 protected void canceling() {
1378 fSearchRequest
.cancel();
1389 * TMF event request for searching within trace.
1391 protected class SearchEventRequest
extends TmfEventRequest
{
1394 * The find criteria.
1396 final private Criteria fCriteria
;
1398 * A progress monitor
1400 private IProgressMonitor fMonitor
;
1402 * Flag to indicate that node was found according the criteria .
1404 private boolean fIsFound
= false;
1406 * Time stamp of found item.
1408 private ITmfTimestamp fFoundTime
= null;
1412 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1413 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1414 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1415 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1416 * @param criteria The search criteria
1418 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType execType
, Criteria criteria
) {
1419 this(range
, nbRequested
, blockSize
, execType
, criteria
, null);
1424 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1425 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1426 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1427 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1428 * @param criteria The search criteria
1429 * @param monitor progress monitor
1431 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType execType
, Criteria criteria
, IProgressMonitor monitor
) {
1432 super(ITmfEvent
.class, range
, nbRequested
, blockSize
, execType
);
1433 fCriteria
= new Criteria(criteria
);
1439 * @see org.eclipse.linuxtools.tmf.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.event.TmfData)
1442 public void handleData(ITmfEvent event
) {
1443 super.handleData(event
);
1445 if ((fMonitor
!= null) && fMonitor
.isCanceled()) {
1450 ITmfSyncSequenceDiagramEvent sdEvent
= getSequnceDiagramEvent(event
);
1452 if (sdEvent
!= null) {
1454 if (fCriteria
.isLifeLineSelected()) {
1455 if (fCriteria
.matches(sdEvent
.getSender())) {
1456 fFoundTime
= event
.getTimestamp();
1461 if (fCriteria
.matches(sdEvent
.getReceiver())) {
1462 fFoundTime
= event
.getTimestamp();
1468 if (fCriteria
.isSyncMessageSelected() && fCriteria
.matches(sdEvent
.getName())) {
1469 fFoundTime
= event
.getTimestamp();
1477 * Set progress monitor.
1479 * @param monitor The monitor to assign
1481 public void setMonitor(IProgressMonitor monitor
) {
1486 * Check if find criteria was met.
1488 * @return true if find criteria was met.
1490 public boolean isFound() {
1495 * Returns timestamp of found time.
1497 * @return timestamp of found time.
1499 public ITmfTimestamp
getFoundTime() {
1505 * Job class to provide progress monitor feedback.
1508 * @author Bernd Hufmann
1511 protected static class IndexingJob
extends Job
{
1514 * @param name The job name
1516 public IndexingJob(String name
) {
1521 protected IStatus
run(IProgressMonitor monitor
) {
1522 while (!monitor
.isCanceled()) {
1525 } catch (InterruptedException e
) {
1526 return Status
.OK_STATUS
;
1530 return Status
.OK_STATUS
;
1536 * Returns sequence diagram event if details in given event are available else null.
1538 * @param tmfEvent Event to parse for sequence diagram event details
1539 * @return sequence diagram event if details are available else null
1541 protected ITmfSyncSequenceDiagramEvent
getSequnceDiagramEvent(ITmfEvent tmfEvent
){
1542 //type = .*RECEIVE.* or .*SEND.*
1543 //content = sender:<sender name>:receiver:<receiver name>,signal:<signal name>
1544 String eventType
= tmfEvent
.getType().toString();
1545 if (eventType
.contains(Messages
.TmfUml2SDSyncCloader_EventTypeSend
) || eventType
.contains(Messages
.TmfUml2SDSyncCloader_EventTypeReceive
)) {
1546 Object sender
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncCloader_FieldSender
);
1547 Object receiver
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncCloader_FieldReceiver
);
1548 Object name
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncCloader_FieldSignal
);
1549 if ((sender
instanceof ITmfEventField
) && (receiver
instanceof ITmfEventField
) && (name
instanceof ITmfEventField
)) {
1550 ITmfSyncSequenceDiagramEvent sdEvent
= new TmfSyncSequenceDiagramEvent(tmfEvent
,
1551 ((ITmfEventField
) sender
).getValue().toString(),
1552 ((ITmfEventField
) receiver
).getValue().toString(),
1553 ((ITmfEventField
) name
).getValue().toString());