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
.ITmfRequest
;
37 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfDataRequest
;
38 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfEventRequest
;
39 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfRangeSynchSignal
;
40 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignal
;
41 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
42 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimeSynchSignal
;
43 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceClosedSignal
;
44 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
45 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
46 import org
.eclipse
.linuxtools
.tmf
.core
.uml2sd
.ITmfSyncSequenceDiagramEvent
;
47 import org
.eclipse
.linuxtools
.tmf
.core
.uml2sd
.TmfSyncSequenceDiagramEvent
;
48 import org
.eclipse
.linuxtools
.tmf
.ui
.editors
.ITmfTraceEditor
;
49 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.SDView
;
50 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Frame
;
51 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
52 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Lifeline
;
53 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.Criteria
;
54 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.FilterCriteria
;
55 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.FilterListDialog
;
56 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDAdvancedPagingProvider
;
57 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDFilterProvider
;
58 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDFindProvider
;
59 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDGraphNodeSupporter
;
60 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.load
.IUml2SDLoader
;
61 import org
.eclipse
.swt
.widgets
.Display
;
62 import org
.eclipse
.ui
.IEditorPart
;
63 import org
.eclipse
.ui
.ISelectionListener
;
64 import org
.eclipse
.ui
.IWorkbenchPart
;
65 import org
.eclipse
.ui
.IWorkbenchWindow
;
66 import org
.eclipse
.ui
.PlatformUI
;
67 import org
.eclipse
.ui
.progress
.IProgressConstants
;
71 * This class is a reference implementation of the
72 * <code>org.eclipse.linuxtools.tmf.ui.Uml2SDLoader</code> extension point. It
73 * provides a Sequence Diagram loader for a user space trace with specific trace
74 * content for sending and receiving signals between components. I also includes
75 * a default implementation for the <code>ITmfEvent</code> parsing.
78 * The class <code>TmfUml2SDSyncLoader</code> analyzes events from type
79 * <code>ITmfEvent</code> and creates events type
80 * <code>ITmfSyncSequenceDiagramEvent</code> if the <code>ITmfEvent</code>
81 * contains all relevant information. The analysis checks that the event type
82 * strings contains either string SEND or RECEIVE. If event type matches these
83 * key words, the analyzer will look for strings sender, receiver and signal in
84 * the event fields of type <code>ITmfEventField</code>. If all the data is
85 * found a sequence diagram event from can be created. Note that Sync Messages
86 * are assumed, which means start and end time are the same. <br>
88 * The parsing of the <code>ITmfEvent</code> is done in the method
89 * <code>getSequnceDiagramEvent()</code> of class
90 * <code>TmfUml2SDSyncLoader</code>. By extending the class
91 * <code>TmfUml2SDSyncLoader</code> and overwriting
92 * <code>getSequnceDiagramEvent()</code> a customized parsing algorithm can be
95 * Note that combined traces of multiple components, that contain the trace
96 * information about the same interactions are not supported in the class
97 * <code>TmfUml2SDSyncLoader</code>.
100 * @author Bernd Hufmann
102 public class TmfUml2SDSyncLoader
extends TmfComponent
implements IUml2SDLoader
, ISDFindProvider
, ISDFilterProvider
, ISDAdvancedPagingProvider
, ISelectionListener
{
104 // ------------------------------------------------------------------------
106 // ------------------------------------------------------------------------
108 * Default title name.
110 protected final static String TITLE
= Messages
.TmfUml2SDSyncLoader_ViewName
;
112 * Default block size for background request.
114 protected final static int DEFAULT_BLOCK_SIZE
= 50000;
116 * Maximum number of messages per page.
118 protected final static int MAX_NUM_OF_MSG
= 10000;
120 // ------------------------------------------------------------------------
122 // ------------------------------------------------------------------------
124 // Experiment attributes
126 * The TMF trace reference.
129 protected ITmfTrace fTrace
= null;
131 * The current indexing event request.
133 protected ITmfEventRequest fIndexRequest
= null;
135 * The current request to fill a page.
137 protected ITmfEventRequest fPageRequest
= null;
139 * Flag whether the time range signal was sent by this loader class or not
141 volatile protected boolean fIsSignalSent
= false;
143 // The view and event attributes
145 * The sequence diagram view reference.
147 protected SDView fView
= null;
149 * The current sequence diagram frame reference.
151 protected Frame fFrame
= null;
153 * The list of sequence diagram events of current page.
155 protected List
<ITmfSyncSequenceDiagramEvent
> fEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>();
157 // Checkpoint and page attributes
159 * The checkpoints of the whole sequence diagram trace (i.e. start time stamp of each page)
161 protected List
<TmfTimeRange
> fCheckPoints
= new ArrayList
<TmfTimeRange
>(MAX_NUM_OF_MSG
);
163 * The current page displayed.
165 volatile protected int fCurrentPage
= 0;
167 * The current time selected.
169 protected ITmfTimestamp fCurrentTime
= null;
171 * Flag to specify that selection of message is done by selection or by signal.
173 volatile protected boolean fIsSelect
= false;
177 * The job for searching across pages.
179 protected SearchJob fFindJob
= null;
181 * List of found nodes within a page.
183 protected List
<GraphNode
> fFindResults
= new ArrayList
<GraphNode
>();
185 * The current find criteria reference
187 protected Criteria fFindCriteria
= null;
189 * The current find index within the list of found nodes (<code>fFindeResults</code> within a page.
191 volatile protected int fCurrentFindIndex
= 0;
195 * The list of active filters.
197 protected List
<FilterCriteria
> fFilterCriteria
= null;
199 // Thread synchronization
201 * The synchronization lock.
203 protected ReentrantLock fLock
= new ReentrantLock();
205 // ------------------------------------------------------------------------
207 // ------------------------------------------------------------------------
209 * Default constructor
211 public TmfUml2SDSyncLoader() {
218 * @param name Name of loader
220 public TmfUml2SDSyncLoader(String name
) {
224 // ------------------------------------------------------------------------
226 // ------------------------------------------------------------------------
228 * Returns the current time if available else null.
230 * @return the current time if available else null
232 public ITmfTimestamp
getCurrentTime() {
235 if (fCurrentTime
!= null) {
245 * Waits for the page request to be completed
247 public void waitForCompletion() {
249 ITmfEventRequest request
= fPageRequest
;
251 if (request
!= null) {
253 request
.waitForCompletion();
254 } catch (InterruptedException e
) {
261 * Signal handler for the trace selected signal.
263 * Spawns a request to index the trace (checkpoints creation) as well as it fills
266 * @param signal The trace selected signal
270 public void traceSelected(TmfTraceSelectedSignal signal
) {
272 ITmfRequest indexRequest
= null;
275 // Update the trace reference
276 ITmfTrace trace
= signal
.getTrace();
277 if (!trace
.equals(fTrace
)) {
283 final Job job
= new IndexingJob("Indexing " + getName() + "..."); //$NON-NLS-1$ //$NON-NLS-2$
287 indexRequest
= fIndexRequest
;
289 cancelOngoingRequests();
291 TmfTimeRange window
= TmfTimeRange
.ETERNITY
;
293 fIndexRequest
= new TmfEventRequest(ITmfEvent
.class, window
, TmfDataRequest
.ALL_DATA
, DEFAULT_BLOCK_SIZE
, ITmfDataRequest
.ExecutionType
.BACKGROUND
) {
295 private ITmfTimestamp fFirstTime
= null;
296 private ITmfTimestamp fLastTime
= null;
297 private int fNbSeqEvents
= 0;
298 private final List
<ITmfSyncSequenceDiagramEvent
> fSdEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>(MAX_NUM_OF_MSG
);
302 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
305 public void handleData(ITmfEvent event
) {
306 super.handleData(event
);
308 ITmfSyncSequenceDiagramEvent sdEvent
= getSequnceDiagramEvent(event
);
310 if (sdEvent
!= null) {
313 if (fFirstTime
== null) {
314 fFirstTime
= event
.getTimestamp();
317 fLastTime
= event
.getTimestamp();
319 if ((fNbSeqEvents
% MAX_NUM_OF_MSG
) == 0) {
322 fCheckPoints
.add(new TmfTimeRange(fFirstTime
, fLastTime
));
324 fView
.updateCoolBar();
333 if (fNbSeqEvents
> MAX_NUM_OF_MSG
) {
338 fSdEvents
.add(sdEvent
);
340 if (fNbSeqEvents
== MAX_NUM_OF_MSG
) {
341 fillCurrentPage(fSdEvents
);
348 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleSuccess()
351 public void handleSuccess() {
352 if ((fFirstTime
!= null) && (fLastTime
!= null)) {
356 fCheckPoints
.add(new TmfTimeRange(fFirstTime
, fLastTime
));
358 fView
.updateCoolBar();
365 if (fNbSeqEvents
<= MAX_NUM_OF_MSG
) {
366 fillCurrentPage(fSdEvents
);
369 super.handleSuccess();
374 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleCompleted()
377 public void handleCompleted() {
378 if (fEvents
.isEmpty()) {
379 fFrame
= new Frame();
380 fView
.setFrameSync(fFrame
);
382 super.handleCompleted();
390 if (indexRequest
!= null && !indexRequest
.isCompleted()) {
391 indexRequest
.cancel();
394 fTrace
.sendRequest(fIndexRequest
);
399 * Signal handler for the trace closed signal.
401 * @param signal The trace closed signal
405 public void traceClosed(TmfTraceClosedSignal signal
) {
406 if (signal
.getTrace() != fTrace
) {
409 ITmfRequest indexRequest
= null;
412 indexRequest
= fIndexRequest
;
413 fIndexRequest
= null;
415 cancelOngoingRequests();
417 if (fFilterCriteria
!= null) {
418 fFilterCriteria
.clear();
421 FilterListDialog
.deactivateSavedGlobalFilters();
426 if (indexRequest
!= null && !indexRequest
.isCompleted()) {
427 indexRequest
.cancel();
434 * Moves to the page that contains the time provided by the signal. The messages will be selected
435 * if the provided time is the time of a message.
437 * @param signal The Time synch signal.
440 public void synchToTime(TmfTimeSynchSignal signal
) {
443 if ((signal
.getSource() != this) && (fFrame
!= null) && (fCheckPoints
.size() > 0)) {
444 fCurrentTime
= signal
.getCurrentTime();
454 * Moves to the page that contains the current time provided by signal.
455 * No message will be selected however the focus will be set to the message
456 * if the provided time is the time of a message.
458 * @param signal The time range sync signal
461 public void synchToTimeRange(TmfRangeSynchSignal signal
) {
464 if ((signal
.getSource() != this) && (fFrame
!= null) && !fIsSignalSent
&& (fCheckPoints
.size() > 0)) {
465 TmfTimeRange newTimeRange
= signal
.getCurrentRange();
468 fCurrentTime
= newTimeRange
.getStartTime();
480 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#setViewer(org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView)
483 public void setViewer(SDView viewer
) {
488 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
489 fView
.setSDFindProvider(this);
490 fView
.setSDPagingProvider(this);
491 fView
.setSDFilterProvider(this);
495 IEditorPart editor
= fView
.getSite().getPage().getActiveEditor();
496 if (editor
instanceof ITmfTraceEditor
) {
497 ITmfTrace trace
= ((ITmfTraceEditor
) editor
).getTrace();
499 traceSelected(new TmfTraceSelectedSignal(this, trace
));
509 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#getTitleString()
512 public String
getTitleString() {
518 * @see org.eclipse.linuxtools.tmf.component.TmfComponent#dispose()
521 public void dispose() {
523 ITmfRequest indexRequest
= null;
526 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
527 // During Eclipse shutdown the active workbench window is null
528 if (window
!= null) {
529 window
.getSelectionService().removePostSelectionListener(this);
532 indexRequest
= fIndexRequest
;
533 fIndexRequest
= null;
534 cancelOngoingRequests();
536 fView
.setSDFindProvider(null);
537 fView
.setSDPagingProvider(null);
538 fView
.setSDFilterProvider(null);
543 if (indexRequest
!= null && !indexRequest
.isCompleted()) {
544 indexRequest
.cancel();
550 * @see org.eclipse.hyades.uml2sd.ui.actions.provider.ISDGraphNodeSupporter#isNodeSupported(int)
553 public boolean isNodeSupported(int nodeType
) {
555 case ISDGraphNodeSupporter
.LIFELINE
:
556 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
567 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter#getNodeName(int, java.lang.String)
570 public String
getNodeName(int nodeType
, String loaderClassName
) {
572 case ISDGraphNodeSupporter
.LIFELINE
:
573 return Messages
.TmfUml2SDSyncLoader_CategoryLifeline
;
574 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
575 return Messages
.TmfUml2SDSyncLoader_CategoryMessage
;
579 return ""; //$NON-NLS-1$
584 * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
587 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
588 ISelection sel
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
589 if ((sel
!= null) && (sel
instanceof StructuredSelection
)) {
590 StructuredSelection stSel
= (StructuredSelection
) sel
;
591 if (stSel
.getFirstElement() instanceof TmfSyncMessage
) {
592 TmfSyncMessage syncMsg
= ((TmfSyncMessage
) stSel
.getFirstElement());
593 broadcast(new TmfTimeSynchSignal(this, syncMsg
.getStartTime()));
601 * org.eclipse.hyades.uml2sd.ui.actions.provider.ISDFindProvider#find(org.eclipse.hyades.uml2sd.ui.actions.widgets.Criteria)
604 public boolean find(Criteria toSearch
) {
607 if (fFrame
== null) {
611 if ((fFindResults
== null) || (fFindCriteria
== null) || !fFindCriteria
.compareTo(toSearch
)) {
612 fFindResults
= new CopyOnWriteArrayList
<GraphNode
>();
613 fFindCriteria
= toSearch
;
614 if (fFindCriteria
.isLifeLineSelected()) {
615 for (int i
= 0; i
< fFrame
.lifeLinesCount(); i
++) {
616 if (fFindCriteria
.matches(fFrame
.getLifeline(i
).getName())) {
617 fFindResults
.add(fFrame
.getLifeline(i
));
622 ArrayList
<GraphNode
> msgs
= new ArrayList
<GraphNode
>();
623 if (fFindCriteria
.isSyncMessageSelected()) {
624 for (int i
= 0; i
< fFrame
.syncMessageCount(); i
++) {
625 if (fFindCriteria
.matches(fFrame
.getSyncMessage(i
).getName())) {
626 msgs
.add(fFrame
.getSyncMessage(i
));
631 if (!msgs
.isEmpty()) {
632 fFindResults
.addAll(msgs
);
635 @SuppressWarnings("rawtypes")
636 List selection
= fView
.getSDWidget().getSelection();
637 if ((selection
!= null) && (selection
.size() == 1)) {
638 fCurrentFindIndex
= fFindResults
.indexOf(selection
.get(0)) + 1;
640 fCurrentFindIndex
= 0;
646 if (fFindResults
.size() > fCurrentFindIndex
) {
647 GraphNode current
= fFindResults
.get(fCurrentFindIndex
);
648 fView
.getSDWidget().moveTo(current
);
652 fCurrentFindIndex
=0;
653 return findInNextPages(fFindCriteria
); // search in other page
661 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFindProvider#cancel()
664 public void cancel() {
665 cancelOngoingRequests();
670 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFilterProvider#filter(java.util.List)
672 @SuppressWarnings("unchecked")
674 public boolean filter(List
<?
> filters
) {
677 cancelOngoingRequests();
679 if (filters
== null) {
680 fFilterCriteria
= new ArrayList
<FilterCriteria
>();
682 List
<FilterCriteria
> list
= (List
<FilterCriteria
>)filters
;
683 fFilterCriteria
= new ArrayList
<FilterCriteria
>(list
);
686 fillCurrentPage(fEvents
);
696 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasNextPage()
699 public boolean hasNextPage() {
702 int size
= fCheckPoints
.size();
704 return fCurrentPage
< (size
- 1);
714 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasPrevPage()
717 public boolean hasPrevPage() {
720 return fCurrentPage
> 0;
728 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#nextPage()
731 public void nextPage() {
735 if (fCurrentPage
>= (fCheckPoints
.size() - 1)) {
739 cancelOngoingRequests();
750 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#prevPage()
753 public void prevPage() {
757 if (fCurrentPage
<= 0) {
761 cancelOngoingRequests();
772 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#firstPage()
775 public void firstPage() {
779 cancelOngoingRequests();
790 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#lastPage()
793 public void lastPage() {
796 cancelOngoingRequests();
798 fCurrentPage
= fCheckPoints
.size() - 1;
807 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#currentPage()
810 public int currentPage() {
821 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pagesCount()
824 public int pagesCount() {
827 return fCheckPoints
.size();
835 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pageNumberChanged(int)
838 public void pageNumberChanged(int pagenNumber
) {
839 int localPageNumber
= pagenNumber
;
843 cancelOngoingRequests();
845 if (localPageNumber
< 0) {
848 int size
= fCheckPoints
.size();
849 if (localPageNumber
> (size
- 1)) {
850 localPageNumber
= size
- 1;
852 fCurrentPage
= localPageNumber
;
861 * @see org.eclipse.linuxtools.tmf.component.TmfComponent#broadcast(org.eclipse.linuxtools.tmf.signal.TmfSignal)
864 public void broadcast(TmfSignal signal
) {
865 fIsSignalSent
= true;
866 super.broadcast(signal
);
867 fIsSignalSent
= false;
871 * Cancels any ongoing find operation
873 protected void cancelOngoingRequests() {
875 ITmfRequest pageRequest
= null;
877 // Cancel the search thread
878 if (fFindJob
!= null) {
883 fFindCriteria
= null;
884 fCurrentFindIndex
= 0;
886 pageRequest
= fPageRequest
;
891 if (pageRequest
!= null && !pageRequest
.isCompleted()) {
892 pageRequest
.cancel();
897 * Resets loader attributes
899 protected void resetLoader() {
904 fCheckPoints
.clear();
906 fCurrentFindIndex
= 0;
907 fFindCriteria
= null;
909 fView
.setFrameSync(new Frame());
919 * Fills current page with sequence diagram content.
921 * @param events sequence diagram events
923 protected void fillCurrentPage(List
<ITmfSyncSequenceDiagramEvent
> events
) {
927 fEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>(events
);
928 if (fView
!= null && !events
.isEmpty()) {
929 fView
.toggleWaitCursorAsync(true);
935 final Frame frame
= new Frame();
937 if (!events
.isEmpty()) {
938 Map
<String
, Lifeline
> nodeToLifelineMap
= new HashMap
<String
, Lifeline
>();
940 frame
.setName(Messages
.TmfUml2SDSyncLoader_FrameName
);
942 for (int i
= 0; i
< events
.size(); i
++) {
944 ITmfSyncSequenceDiagramEvent sdEvent
= events
.get(i
);
946 if ((nodeToLifelineMap
.get(sdEvent
.getSender()) == null) && (!filterLifeLine(sdEvent
.getSender()))) {
947 Lifeline lifeline
= new Lifeline();
948 lifeline
.setName(sdEvent
.getSender());
949 nodeToLifelineMap
.put(sdEvent
.getSender(), lifeline
);
950 frame
.addLifeLine(lifeline
);
953 if ((nodeToLifelineMap
.get(sdEvent
.getReceiver()) == null) && (!filterLifeLine(sdEvent
.getReceiver()))) {
954 Lifeline lifeline
= new Lifeline();
955 lifeline
.setName(sdEvent
.getReceiver());
956 nodeToLifelineMap
.put(sdEvent
.getReceiver(), lifeline
);
957 frame
.addLifeLine(lifeline
);
961 int eventOccurence
= 1;
963 for (int i
= 0; i
< events
.size(); i
++) {
964 ITmfSyncSequenceDiagramEvent sdEvent
= events
.get(i
);
966 // Check message filter
967 if (filterMessage(sdEvent
)) {
971 // Set the message sender and receiver
972 Lifeline startLifeline
= nodeToLifelineMap
.get(sdEvent
.getSender());
973 Lifeline endLifeline
= nodeToLifelineMap
.get(sdEvent
.getReceiver());
975 // Check if any of the lifelines were filtered
976 if ((startLifeline
== null) || (endLifeline
== null)) {
980 int tmp
= Math
.max(startLifeline
.getEventOccurrence(), endLifeline
.getEventOccurrence());
981 eventOccurence
= Math
.max(eventOccurence
, tmp
);
983 startLifeline
.setCurrentEventOccurrence(eventOccurence
);
984 endLifeline
.setCurrentEventOccurrence(eventOccurence
);
986 TmfSyncMessage message
= new TmfSyncMessage(sdEvent
, eventOccurence
++);
988 message
.setStartLifeline(startLifeline
);
989 message
.setEndLifeline(endLifeline
);
991 message
.setTime(sdEvent
.getStartTime());
993 // add the message to the frame
994 frame
.addMessage(message
);
999 if (!fView
.getSDWidget().isDisposed()) {
1000 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1007 // check if view was disposed in the meanwhile
1008 if ((fView
!= null) && (!fView
.getSDWidget().isDisposed())) {
1010 fView
.setFrame(fFrame
);
1012 if (fCurrentTime
!= null) {
1013 moveToMessageInPage();
1016 if (fFindCriteria
!= null) {
1017 find(fFindCriteria
);
1020 fView
.toggleWaitCursorAsync(false);
1037 * Moves to a certain message defined by timestamp (across pages)
1039 protected void moveToMessage() {
1044 page
= getPage(fCurrentTime
);
1046 if (page
== fCurrentPage
) {
1047 moveToMessageInPage();
1050 fCurrentPage
= page
;
1058 * Moves to a certain message defined by timestamp in current page
1060 protected void moveToMessageInPage() {
1063 if (!fView
.getSDWidget().isDisposed()) {
1064 // Check for GUI thread
1065 if(Display
.getCurrent() != null) {
1066 // Already in GUI thread - execute directly
1067 TmfSyncMessage prevMessage
= null;
1068 TmfSyncMessage syncMessage
= null;
1069 boolean isExactTime
= false;
1070 for (int i
= 0; i
< fFrame
.syncMessageCount(); i
++) {
1071 if (fFrame
.getSyncMessage(i
) instanceof TmfSyncMessage
) {
1072 syncMessage
= (TmfSyncMessage
) fFrame
.getSyncMessage(i
);
1073 if (syncMessage
.getStartTime().compareTo(fCurrentTime
, false) == 0) {
1076 } else if ((syncMessage
.getStartTime().compareTo(fCurrentTime
, false) > 0) && (prevMessage
!= null)) {
1077 syncMessage
= prevMessage
;
1080 prevMessage
= syncMessage
;
1083 if (fIsSelect
&& isExactTime
) {
1084 fView
.getSDWidget().moveTo(syncMessage
);
1087 fView
.getSDWidget().ensureVisible(syncMessage
);
1088 fView
.getSDWidget().clearSelection();
1089 fView
.getSDWidget().redraw();
1093 // Not in GUI thread - queue action in GUI thread.
1094 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1097 moveToMessageInPage();
1109 * Moves to a certain message defined by timestamp (across pages)
1111 protected void moveToPage() {
1116 * Moves to a certain page.
1118 * @param notifyAll true to broadcast time range signal to other signal handlers else false
1120 protected void moveToPage(boolean notifyAll
) {
1122 TmfTimeRange window
= null;
1127 if (fCurrentPage
> fCheckPoints
.size()) {
1130 window
= fCheckPoints
.get(fCurrentPage
);
1135 if (window
== null) {
1136 window
= TmfTimeRange
.ETERNITY
;
1139 fPageRequest
= new TmfEventRequest(ITmfEvent
.class, window
, TmfDataRequest
.ALL_DATA
, 1, ITmfDataRequest
.ExecutionType
.FOREGROUND
) {
1140 private final List
<ITmfSyncSequenceDiagramEvent
> fSdEvent
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>();
1143 public void handleData(ITmfEvent event
) {
1144 super.handleData(event
);
1146 ITmfSyncSequenceDiagramEvent sdEvent
= getSequnceDiagramEvent(event
);
1148 if (sdEvent
!= null) {
1149 fSdEvent
.add(sdEvent
);
1154 public void handleSuccess() {
1155 fillCurrentPage(fSdEvent
);
1156 super.handleSuccess();
1161 fTrace
.sendRequest(fPageRequest
);
1164 TmfTimeRange timeRange
= getSignalTimeRange(window
.getStartTime());
1165 broadcast(new TmfRangeSynchSignal(this, timeRange
, timeRange
.getStartTime()));
1170 * Gets page that contains timestamp
1172 * @param time The timestamp
1173 * @return page that contains the time
1175 protected int getPage(ITmfTimestamp time
) {
1180 size
= fCheckPoints
.size();
1181 for (page
= 0; page
< size
; page
++) {
1182 TmfTimeRange timeRange
= fCheckPoints
.get(page
);
1183 if (timeRange
.getEndTime().compareTo(time
, false) >= 0) {
1197 * Background search in trace for expression in criteria.
1199 * @param findCriteria The find criteria
1200 * @return true if background request was started else false
1202 protected boolean findInNextPages(Criteria findCriteria
) {
1205 if (fFindJob
!= null) {
1209 int nextPage
= fCurrentPage
+ 1;
1211 if ((nextPage
) >= fCheckPoints
.size()) {
1212 // we are at the end
1216 TmfTimeRange window
= new TmfTimeRange(fCheckPoints
.get(nextPage
).getStartTime(), fCheckPoints
.get(fCheckPoints
.size()-1).getEndTime());
1217 fFindJob
= new SearchJob(findCriteria
, window
);
1218 fFindJob
.schedule();
1219 fView
.toggleWaitCursorAsync(true);
1227 * Gets time range for time range signal.
1229 * @param startTime The start time of time range.
1230 * @return the time range
1232 protected TmfTimeRange
getSignalTimeRange(ITmfTimestamp startTime
) {
1235 long offset
= fTrace
== null ?
0 : fTrace
.getCurrentRange().getEndTime().getDelta(fTrace
.getCurrentRange().getStartTime()).normalize(0, startTime
.getScale()).getValue();
1236 TmfTimestamp initialEndOfWindow
= new TmfTimestamp(startTime
.getValue() + offset
, startTime
.getScale(), startTime
.getPrecision());
1237 return new TmfTimeRange(startTime
, initialEndOfWindow
);
1245 * Checks if filter criteria matches the message name in given SD event.
1247 * @param sdEvent The SD event to check
1248 * @return true if match else false.
1250 protected boolean filterMessage(ITmfSyncSequenceDiagramEvent sdEvent
) {
1253 if (fFilterCriteria
!= null) {
1254 for(FilterCriteria criteria
: fFilterCriteria
) {
1255 if (criteria
.isActive() && criteria
.getCriteria().isSyncMessageSelected() && criteria
.getCriteria().matches(sdEvent
.getName())) {
1267 * Checks if filter criteria matches a lifeline name (sender or receiver) in given SD event.
1269 * @param lifeline the message receiver
1270 * @return true if match else false.
1272 protected boolean filterLifeLine(String lifeline
) {
1275 if (fFilterCriteria
!= null) {
1276 for(FilterCriteria criteria
: fFilterCriteria
) {
1277 if (criteria
.isActive() && criteria
.getCriteria().isLifeLineSelected() && criteria
.getCriteria().matches(lifeline
)) {
1289 * Job to search in trace for given time range.
1291 protected class SearchJob
extends Job
{
1294 * The search event request.
1296 final protected SearchEventRequest fSearchRequest
;
1301 * @param findCriteria The search criteria
1302 * @param window Time range to search in
1304 public SearchJob(Criteria findCriteria
, TmfTimeRange window
) {
1305 super(Messages
.TmfUml2SDSyncLoader_SearchJobDescrition
);
1306 fSearchRequest
= new SearchEventRequest(window
, TmfDataRequest
.ALL_DATA
, 1, ITmfDataRequest
.ExecutionType
.FOREGROUND
, findCriteria
);
1311 * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
1314 protected IStatus
run(IProgressMonitor monitor
) {
1315 fSearchRequest
.setMonitor(monitor
);
1317 fTrace
.sendRequest(fSearchRequest
);
1320 fSearchRequest
.waitForCompletion();
1321 } catch (InterruptedException e
) {
1322 Activator
.getDefault().logError("Search request interrupted!", e
); //$NON-NLS-1$
1325 IStatus status
= Status
.OK_STATUS
;
1326 if (fSearchRequest
.isFound() && (fSearchRequest
.getFoundTime() != null)) {
1327 fCurrentTime
= fSearchRequest
.getFoundTime();
1329 // Avoid double-selection. Selection will be done when calling find(criteria)
1330 // after moving to relevant page
1332 if (!fView
.getSDWidget().isDisposed()) {
1333 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1343 if (monitor
.isCanceled()) {
1344 status
= Status
.CANCEL_STATUS
;
1347 // String was not found
1348 status
= new Status(IStatus
.WARNING
, Activator
.PLUGIN_ID
, Messages
.TmfUml2SDSyncLoader_SearchNotFound
);
1350 setProperty(IProgressConstants
.KEEP_PROPERTY
, Boolean
.TRUE
);
1356 fView
.toggleWaitCursorAsync(false);
1367 * @see org.eclipse.core.runtime.jobs.Job#canceling()
1370 protected void canceling() {
1371 fSearchRequest
.cancel();
1382 * TMF event request for searching within trace.
1384 protected class SearchEventRequest
extends TmfEventRequest
{
1387 * The find criteria.
1389 final private Criteria fCriteria
;
1391 * A progress monitor
1393 private IProgressMonitor fMonitor
;
1395 * Flag to indicate that node was found according the criteria .
1397 private boolean fIsFound
= false;
1399 * Time stamp of found item.
1401 private ITmfTimestamp fFoundTime
= null;
1405 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1406 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1407 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1408 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1409 * @param criteria The search criteria
1411 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType execType
, Criteria criteria
) {
1412 this(range
, nbRequested
, blockSize
, execType
, criteria
, null);
1417 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1418 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1419 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1420 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1421 * @param criteria The search criteria
1422 * @param monitor progress monitor
1424 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType execType
, Criteria criteria
, IProgressMonitor monitor
) {
1425 super(ITmfEvent
.class, range
, nbRequested
, blockSize
, execType
);
1426 fCriteria
= new Criteria(criteria
);
1432 * @see org.eclipse.linuxtools.tmf.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.event.TmfData)
1435 public void handleData(ITmfEvent event
) {
1436 super.handleData(event
);
1438 if ((fMonitor
!= null) && fMonitor
.isCanceled()) {
1443 ITmfSyncSequenceDiagramEvent sdEvent
= getSequnceDiagramEvent(event
);
1445 if (sdEvent
!= null) {
1447 if (fCriteria
.isLifeLineSelected()) {
1448 if (fCriteria
.matches(sdEvent
.getSender())) {
1449 fFoundTime
= event
.getTimestamp();
1454 if (fCriteria
.matches(sdEvent
.getReceiver())) {
1455 fFoundTime
= event
.getTimestamp();
1461 if (fCriteria
.isSyncMessageSelected() && fCriteria
.matches(sdEvent
.getName())) {
1462 fFoundTime
= event
.getTimestamp();
1470 * Set progress monitor.
1472 * @param monitor The monitor to assign
1474 public void setMonitor(IProgressMonitor monitor
) {
1479 * Check if find criteria was met.
1481 * @return true if find criteria was met.
1483 public boolean isFound() {
1488 * Returns timestamp of found time.
1490 * @return timestamp of found time.
1492 public ITmfTimestamp
getFoundTime() {
1498 * Job class to provide progress monitor feedback.
1501 * @author Bernd Hufmann
1504 protected static class IndexingJob
extends Job
{
1507 * @param name The job name
1509 public IndexingJob(String name
) {
1514 protected IStatus
run(IProgressMonitor monitor
) {
1515 while (!monitor
.isCanceled()) {
1518 } catch (InterruptedException e
) {
1519 return Status
.OK_STATUS
;
1523 return Status
.OK_STATUS
;
1529 * Returns sequence diagram event if details in given event are available else null.
1531 * @param tmfEvent Event to parse for sequence diagram event details
1532 * @return sequence diagram event if details are available else null
1534 protected ITmfSyncSequenceDiagramEvent
getSequnceDiagramEvent(ITmfEvent tmfEvent
){
1535 //type = .*RECEIVE.* or .*SEND.*
1536 //content = sender:<sender name>:receiver:<receiver name>,signal:<signal name>
1537 String eventType
= tmfEvent
.getType().toString();
1538 if (eventType
.contains(Messages
.TmfUml2SDSyncCloader_EventTypeSend
) || eventType
.contains(Messages
.TmfUml2SDSyncCloader_EventTypeReceive
)) {
1539 Object sender
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncCloader_FieldSender
);
1540 Object receiver
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncCloader_FieldReceiver
);
1541 Object name
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncCloader_FieldSignal
);
1542 if ((sender
instanceof ITmfEventField
) && (receiver
instanceof ITmfEventField
) && (name
instanceof ITmfEventField
)) {
1543 ITmfSyncSequenceDiagramEvent sdEvent
= new TmfSyncSequenceDiagramEvent(tmfEvent
,
1544 ((ITmfEventField
) sender
).getValue().toString(),
1545 ((ITmfEventField
) receiver
).getValue().toString(),
1546 ((ITmfEventField
) name
).getValue().toString());