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 // ------------------------------------------------------------------------
121 // ------------------------------------------------------------------------
123 // Experiment attributes
125 * The TMF trace reference.
128 protected ITmfTrace fTrace
= null;
130 * The current indexing event request.
132 protected ITmfEventRequest fIndexRequest
= null;
134 * The current request to fill a page.
136 protected ITmfEventRequest fPageRequest
= null;
138 * Flag whether the time range signal was sent by this loader class or not
140 volatile protected boolean fIsSignalSent
= false;
142 // The view and event attributes
144 * The sequence diagram view reference.
146 protected SDView fView
= null;
148 * The current sequence diagram frame reference.
150 protected Frame fFrame
= null;
152 * The list of sequence diagram events of current page.
154 protected List
<ITmfSyncSequenceDiagramEvent
> fEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>();
156 // Checkpoint and page attributes
158 * The checkpoints of the whole sequence diagram trace (i.e. start time stamp of each page)
160 protected List
<TmfTimeRange
> fCheckPoints
= new ArrayList
<TmfTimeRange
>(MAX_NUM_OF_MSG
);
162 * The current page displayed.
164 volatile protected int fCurrentPage
= 0;
166 * The current time selected.
168 protected ITmfTimestamp fCurrentTime
= null;
170 * Flag to specify that selection of message is done by selection or by signal.
172 volatile protected boolean fIsSelect
= false;
176 * The job for searching across pages.
178 protected SearchJob fFindJob
= null;
180 * List of found nodes within a page.
182 protected List
<GraphNode
> fFindResults
= new ArrayList
<GraphNode
>();
184 * The current find criteria reference
186 protected Criteria fFindCriteria
= null;
188 * The current find index within the list of found nodes (<code>fFindeResults</code> within a page.
190 volatile protected int fCurrentFindIndex
= 0;
194 * The list of active filters.
196 protected List
<FilterCriteria
> fFilterCriteria
= null;
198 // Thread synchronization
200 * The synchronization lock.
202 protected ReentrantLock fLock
= new ReentrantLock();
204 // ------------------------------------------------------------------------
206 // ------------------------------------------------------------------------
208 * Default constructor
210 public TmfUml2SDSyncLoader() {
217 * @param name Name of loader
219 public TmfUml2SDSyncLoader(String name
) {
223 // ------------------------------------------------------------------------
225 // ------------------------------------------------------------------------
227 * Returns the current time if available else null.
229 * @return the current time if available else null
231 public ITmfTimestamp
getCurrentTime() {
234 if (fCurrentTime
!= null) {
244 * Waits for the page request to be completed
246 public void waitForCompletion() {
248 ITmfEventRequest request
= fPageRequest
;
250 if (request
!= null) {
252 request
.waitForCompletion();
253 } catch (InterruptedException e
) {
260 * Signal handler for the trace selected signal.
262 * Spawns a request to index the trace (checkpoints creation) as well as it fills
265 * @param signal The trace selected signal
269 public void traceSelected(TmfTraceSelectedSignal signal
) {
271 ITmfEventRequest indexRequest
= null;
274 // Update the trace reference
275 ITmfTrace trace
= signal
.getTrace();
276 if (!trace
.equals(fTrace
)) {
282 final Job job
= new IndexingJob("Indexing " + getName() + "..."); //$NON-NLS-1$ //$NON-NLS-2$
286 indexRequest
= fIndexRequest
;
288 cancelOngoingRequests();
290 TmfTimeRange window
= TmfTimeRange
.ETERNITY
;
292 fIndexRequest
= new TmfEventRequest(ITmfEvent
.class, window
, TmfDataRequest
.ALL_DATA
, DEFAULT_BLOCK_SIZE
, ITmfDataRequest
.ExecutionType
.BACKGROUND
) {
294 private ITmfTimestamp fFirstTime
= null;
295 private ITmfTimestamp fLastTime
= null;
296 private int fNbSeqEvents
= 0;
297 private final List
<ITmfSyncSequenceDiagramEvent
> fSdEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>(MAX_NUM_OF_MSG
);
301 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
304 public void handleData(ITmfEvent event
) {
305 super.handleData(event
);
307 ITmfSyncSequenceDiagramEvent sdEvent
= getSequenceDiagramEvent(event
);
309 if (sdEvent
!= null) {
312 if (fFirstTime
== null) {
313 fFirstTime
= event
.getTimestamp();
316 fLastTime
= event
.getTimestamp();
318 if ((fNbSeqEvents
% MAX_NUM_OF_MSG
) == 0) {
321 fCheckPoints
.add(new TmfTimeRange(fFirstTime
, fLastTime
));
323 fView
.updateCoolBar();
332 if (fNbSeqEvents
> MAX_NUM_OF_MSG
) {
337 fSdEvents
.add(sdEvent
);
339 if (fNbSeqEvents
== MAX_NUM_OF_MSG
) {
340 fillCurrentPage(fSdEvents
);
347 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleSuccess()
350 public void handleSuccess() {
351 if ((fFirstTime
!= null) && (fLastTime
!= null)) {
355 fCheckPoints
.add(new TmfTimeRange(fFirstTime
, fLastTime
));
357 fView
.updateCoolBar();
364 if (fNbSeqEvents
<= MAX_NUM_OF_MSG
) {
365 fillCurrentPage(fSdEvents
);
368 super.handleSuccess();
373 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleCompleted()
376 public void handleCompleted() {
377 if (fEvents
.isEmpty()) {
378 fFrame
= new Frame();
379 fView
.setFrameSync(fFrame
);
381 super.handleCompleted();
389 if (indexRequest
!= null && !indexRequest
.isCompleted()) {
390 indexRequest
.cancel();
393 fTrace
.sendRequest(fIndexRequest
);
398 * Signal handler for the trace closed signal.
400 * @param signal The trace closed signal
404 public void traceClosed(TmfTraceClosedSignal signal
) {
405 if (signal
.getTrace() != fTrace
) {
408 ITmfEventRequest indexRequest
= null;
411 indexRequest
= fIndexRequest
;
412 fIndexRequest
= null;
414 cancelOngoingRequests();
416 if (fFilterCriteria
!= null) {
417 fFilterCriteria
.clear();
420 FilterListDialog
.deactivateSavedGlobalFilters();
425 if (indexRequest
!= null && !indexRequest
.isCompleted()) {
426 indexRequest
.cancel();
433 * Moves to the page that contains the time provided by the signal. The messages will be selected
434 * if the provided time is the time of a message.
436 * @param signal The Time synch signal.
439 public void synchToTime(TmfTimeSynchSignal signal
) {
442 if ((signal
.getSource() != this) && (fFrame
!= null) && (fCheckPoints
.size() > 0)) {
443 fCurrentTime
= signal
.getCurrentTime();
453 * Moves to the page that contains the current time provided by signal.
454 * No message will be selected however the focus will be set to the message
455 * if the provided time is the time of a message.
457 * @param signal The time range sync signal
460 public void synchToTimeRange(TmfRangeSynchSignal signal
) {
463 if ((signal
.getSource() != this) && (fFrame
!= null) && !fIsSignalSent
&& (fCheckPoints
.size() > 0)) {
464 TmfTimeRange newTimeRange
= signal
.getCurrentRange();
467 fCurrentTime
= newTimeRange
.getStartTime();
479 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#setViewer(org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView)
482 public void setViewer(SDView viewer
) {
487 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
488 fView
.setSDFindProvider(this);
489 fView
.setSDPagingProvider(this);
490 fView
.setSDFilterProvider(this);
494 IEditorPart editor
= fView
.getSite().getPage().getActiveEditor();
495 if (editor
instanceof ITmfTraceEditor
) {
496 ITmfTrace trace
= ((ITmfTraceEditor
) editor
).getTrace();
498 traceSelected(new TmfTraceSelectedSignal(this, trace
));
508 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#getTitleString()
511 public String
getTitleString() {
517 * @see org.eclipse.linuxtools.tmf.component.TmfComponent#dispose()
520 public void dispose() {
522 ITmfEventRequest indexRequest
= null;
525 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
526 // During Eclipse shutdown the active workbench window is null
527 if (window
!= null) {
528 window
.getSelectionService().removePostSelectionListener(this);
531 indexRequest
= fIndexRequest
;
532 fIndexRequest
= null;
533 cancelOngoingRequests();
535 fView
.setSDFindProvider(null);
536 fView
.setSDPagingProvider(null);
537 fView
.setSDFilterProvider(null);
542 if (indexRequest
!= null && !indexRequest
.isCompleted()) {
543 indexRequest
.cancel();
549 * @see org.eclipse.hyades.uml2sd.ui.actions.provider.ISDGraphNodeSupporter#isNodeSupported(int)
552 public boolean isNodeSupported(int nodeType
) {
554 case ISDGraphNodeSupporter
.LIFELINE
:
555 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
566 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter#getNodeName(int, java.lang.String)
569 public String
getNodeName(int nodeType
, String loaderClassName
) {
571 case ISDGraphNodeSupporter
.LIFELINE
:
572 return Messages
.TmfUml2SDSyncLoader_CategoryLifeline
;
573 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
574 return Messages
.TmfUml2SDSyncLoader_CategoryMessage
;
578 return ""; //$NON-NLS-1$
583 * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
586 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
587 ISelection sel
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
588 if ((sel
!= null) && (sel
instanceof StructuredSelection
)) {
589 StructuredSelection stSel
= (StructuredSelection
) sel
;
590 if (stSel
.getFirstElement() instanceof TmfSyncMessage
) {
591 TmfSyncMessage syncMsg
= ((TmfSyncMessage
) stSel
.getFirstElement());
592 broadcast(new TmfTimeSynchSignal(this, syncMsg
.getStartTime()));
600 * org.eclipse.hyades.uml2sd.ui.actions.provider.ISDFindProvider#find(org.eclipse.hyades.uml2sd.ui.actions.widgets.Criteria)
603 public boolean find(Criteria toSearch
) {
606 if (fFrame
== null) {
610 if ((fFindResults
== null) || (fFindCriteria
== null) || !fFindCriteria
.compareTo(toSearch
)) {
611 fFindResults
= new CopyOnWriteArrayList
<GraphNode
>();
612 fFindCriteria
= toSearch
;
613 if (fFindCriteria
.isLifeLineSelected()) {
614 for (int i
= 0; i
< fFrame
.lifeLinesCount(); i
++) {
615 if (fFindCriteria
.matches(fFrame
.getLifeline(i
).getName())) {
616 fFindResults
.add(fFrame
.getLifeline(i
));
621 ArrayList
<GraphNode
> msgs
= new ArrayList
<GraphNode
>();
622 if (fFindCriteria
.isSyncMessageSelected()) {
623 for (int i
= 0; i
< fFrame
.syncMessageCount(); i
++) {
624 if (fFindCriteria
.matches(fFrame
.getSyncMessage(i
).getName())) {
625 msgs
.add(fFrame
.getSyncMessage(i
));
630 if (!msgs
.isEmpty()) {
631 fFindResults
.addAll(msgs
);
634 @SuppressWarnings("rawtypes")
635 List selection
= fView
.getSDWidget().getSelection();
636 if ((selection
!= null) && (selection
.size() == 1)) {
637 fCurrentFindIndex
= fFindResults
.indexOf(selection
.get(0)) + 1;
639 fCurrentFindIndex
= 0;
645 if (fFindResults
.size() > fCurrentFindIndex
) {
646 GraphNode current
= fFindResults
.get(fCurrentFindIndex
);
647 fView
.getSDWidget().moveTo(current
);
651 fCurrentFindIndex
=0;
652 return findInNextPages(fFindCriteria
); // search in other page
660 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFindProvider#cancel()
663 public void cancel() {
664 cancelOngoingRequests();
669 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFilterProvider#filter(java.util.List)
671 @SuppressWarnings("unchecked")
673 public boolean filter(List
<?
> filters
) {
676 cancelOngoingRequests();
678 if (filters
== null) {
679 fFilterCriteria
= new ArrayList
<FilterCriteria
>();
681 List
<FilterCriteria
> list
= (List
<FilterCriteria
>)filters
;
682 fFilterCriteria
= new ArrayList
<FilterCriteria
>(list
);
685 fillCurrentPage(fEvents
);
695 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasNextPage()
698 public boolean hasNextPage() {
701 int size
= fCheckPoints
.size();
703 return fCurrentPage
< (size
- 1);
713 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasPrevPage()
716 public boolean hasPrevPage() {
719 return fCurrentPage
> 0;
727 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#nextPage()
730 public void nextPage() {
734 if (fCurrentPage
>= (fCheckPoints
.size() - 1)) {
738 cancelOngoingRequests();
749 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#prevPage()
752 public void prevPage() {
756 if (fCurrentPage
<= 0) {
760 cancelOngoingRequests();
771 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#firstPage()
774 public void firstPage() {
778 cancelOngoingRequests();
789 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#lastPage()
792 public void lastPage() {
795 cancelOngoingRequests();
797 fCurrentPage
= fCheckPoints
.size() - 1;
806 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#currentPage()
809 public int currentPage() {
820 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pagesCount()
823 public int pagesCount() {
826 return fCheckPoints
.size();
834 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pageNumberChanged(int)
837 public void pageNumberChanged(int pagenNumber
) {
838 int localPageNumber
= pagenNumber
;
842 cancelOngoingRequests();
844 if (localPageNumber
< 0) {
847 int size
= fCheckPoints
.size();
848 if (localPageNumber
> (size
- 1)) {
849 localPageNumber
= size
- 1;
851 fCurrentPage
= localPageNumber
;
860 * @see org.eclipse.linuxtools.tmf.component.TmfComponent#broadcast(org.eclipse.linuxtools.tmf.signal.TmfSignal)
863 public void broadcast(TmfSignal signal
) {
864 fIsSignalSent
= true;
865 super.broadcast(signal
);
866 fIsSignalSent
= false;
870 * Cancels any ongoing find operation
872 protected void cancelOngoingRequests() {
874 ITmfEventRequest pageRequest
= null;
876 // Cancel the search thread
877 if (fFindJob
!= null) {
882 fFindCriteria
= null;
883 fCurrentFindIndex
= 0;
885 pageRequest
= fPageRequest
;
890 if (pageRequest
!= null && !pageRequest
.isCompleted()) {
891 pageRequest
.cancel();
896 * Resets loader attributes
898 protected void resetLoader() {
903 fCheckPoints
.clear();
905 fCurrentFindIndex
= 0;
906 fFindCriteria
= null;
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
= getSequenceDiagramEvent(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 long offset
= fTrace
== null ?
0 : fTrace
.getCurrentRange().getEndTime().getDelta(fTrace
.getCurrentRange().getStartTime()).normalize(0, startTime
.getScale()).getValue();
1235 TmfTimestamp initialEndOfWindow
= new TmfTimestamp(startTime
.getValue() + offset
, startTime
.getScale(), startTime
.getPrecision());
1236 return new TmfTimeRange(startTime
, initialEndOfWindow
);
1244 * Checks if filter criteria matches the message name in given SD event.
1246 * @param sdEvent The SD event to check
1247 * @return true if match else false.
1249 protected boolean filterMessage(ITmfSyncSequenceDiagramEvent sdEvent
) {
1252 if (fFilterCriteria
!= null) {
1253 for(FilterCriteria criteria
: fFilterCriteria
) {
1254 if (criteria
.isActive() && criteria
.getCriteria().isSyncMessageSelected() && criteria
.getCriteria().matches(sdEvent
.getName())) {
1266 * Checks if filter criteria matches a lifeline name (sender or receiver) in given SD event.
1268 * @param lifeline the message receiver
1269 * @return true if match else false.
1271 protected boolean filterLifeLine(String lifeline
) {
1274 if (fFilterCriteria
!= null) {
1275 for(FilterCriteria criteria
: fFilterCriteria
) {
1276 if (criteria
.isActive() && criteria
.getCriteria().isLifeLineSelected() && criteria
.getCriteria().matches(lifeline
)) {
1288 * Job to search in trace for given time range.
1290 protected class SearchJob
extends Job
{
1293 * The search event request.
1295 final protected SearchEventRequest fSearchRequest
;
1300 * @param findCriteria The search criteria
1301 * @param window Time range to search in
1303 public SearchJob(Criteria findCriteria
, TmfTimeRange window
) {
1304 super(Messages
.TmfUml2SDSyncLoader_SearchJobDescrition
);
1305 fSearchRequest
= new SearchEventRequest(window
, TmfDataRequest
.ALL_DATA
, 1, ITmfDataRequest
.ExecutionType
.FOREGROUND
, findCriteria
);
1310 * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
1313 protected IStatus
run(IProgressMonitor monitor
) {
1314 fSearchRequest
.setMonitor(monitor
);
1316 fTrace
.sendRequest(fSearchRequest
);
1319 fSearchRequest
.waitForCompletion();
1320 } catch (InterruptedException e
) {
1321 Activator
.getDefault().logError("Search request interrupted!", e
); //$NON-NLS-1$
1324 IStatus status
= Status
.OK_STATUS
;
1325 if (fSearchRequest
.isFound() && (fSearchRequest
.getFoundTime() != null)) {
1326 fCurrentTime
= fSearchRequest
.getFoundTime();
1328 // Avoid double-selection. Selection will be done when calling find(criteria)
1329 // after moving to relevant page
1331 if (!fView
.getSDWidget().isDisposed()) {
1332 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1342 if (monitor
.isCanceled()) {
1343 status
= Status
.CANCEL_STATUS
;
1346 // String was not found
1347 status
= new Status(IStatus
.WARNING
, Activator
.PLUGIN_ID
, Messages
.TmfUml2SDSyncLoader_SearchNotFound
);
1349 setProperty(IProgressConstants
.KEEP_PROPERTY
, Boolean
.TRUE
);
1355 fView
.toggleWaitCursorAsync(false);
1366 * @see org.eclipse.core.runtime.jobs.Job#canceling()
1369 protected void canceling() {
1370 fSearchRequest
.cancel();
1381 * TMF event request for searching within trace.
1383 protected class SearchEventRequest
extends TmfEventRequest
{
1386 * The find criteria.
1388 final private Criteria fCriteria
;
1390 * A progress monitor
1392 private IProgressMonitor fMonitor
;
1394 * Flag to indicate that node was found according the criteria .
1396 private boolean fIsFound
= false;
1398 * Time stamp of found item.
1400 private ITmfTimestamp fFoundTime
= null;
1404 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1405 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1406 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1407 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1408 * @param criteria The search criteria
1410 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType execType
, Criteria criteria
) {
1411 this(range
, nbRequested
, blockSize
, execType
, criteria
, null);
1416 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1417 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1418 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1419 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1420 * @param criteria The search criteria
1421 * @param monitor progress monitor
1423 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType execType
, Criteria criteria
, IProgressMonitor monitor
) {
1424 super(ITmfEvent
.class, range
, nbRequested
, blockSize
, execType
);
1425 fCriteria
= new Criteria(criteria
);
1431 * @see org.eclipse.linuxtools.tmf.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.event.TmfData)
1434 public void handleData(ITmfEvent event
) {
1435 super.handleData(event
);
1437 if ((fMonitor
!= null) && fMonitor
.isCanceled()) {
1442 ITmfSyncSequenceDiagramEvent sdEvent
= getSequenceDiagramEvent(event
);
1444 if (sdEvent
!= null) {
1446 if (fCriteria
.isLifeLineSelected()) {
1447 if (fCriteria
.matches(sdEvent
.getSender())) {
1448 fFoundTime
= event
.getTimestamp();
1453 if (fCriteria
.matches(sdEvent
.getReceiver())) {
1454 fFoundTime
= event
.getTimestamp();
1460 if (fCriteria
.isSyncMessageSelected() && fCriteria
.matches(sdEvent
.getName())) {
1461 fFoundTime
= event
.getTimestamp();
1469 * Set progress monitor.
1471 * @param monitor The monitor to assign
1473 public void setMonitor(IProgressMonitor monitor
) {
1478 * Check if find criteria was met.
1480 * @return true if find criteria was met.
1482 public boolean isFound() {
1487 * Returns timestamp of found time.
1489 * @return timestamp of found time.
1491 public ITmfTimestamp
getFoundTime() {
1497 * Job class to provide progress monitor feedback.
1500 * @author Bernd Hufmann
1503 protected static class IndexingJob
extends Job
{
1506 * @param name The job name
1508 public IndexingJob(String name
) {
1513 protected IStatus
run(IProgressMonitor monitor
) {
1514 while (!monitor
.isCanceled()) {
1517 } catch (InterruptedException e
) {
1518 return Status
.OK_STATUS
;
1522 return Status
.OK_STATUS
;
1528 * Returns sequence diagram event if details in given event are available else null.
1530 * @param tmfEvent Event to parse for sequence diagram event details
1531 * @return sequence diagram event if details are available else null
1534 protected ITmfSyncSequenceDiagramEvent
getSequenceDiagramEvent(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
.TmfUml2SDSyncLoader_EventTypeSend
) || eventType
.contains(Messages
.TmfUml2SDSyncLoader_EventTypeReceive
)) {
1539 Object sender
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncLoader_FieldSender
);
1540 Object receiver
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncLoader_FieldReceiver
);
1541 Object name
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncLoader_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());