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
) {
273 // Update the trace reference
274 ITmfTrace trace
= signal
.getTrace();
275 if (!trace
.equals(fTrace
)) {
281 final Job job
= new IndexingJob("Indexing " + getName() + "..."); //$NON-NLS-1$ //$NON-NLS-2$
285 if (fIndexRequest
!= null && !fIndexRequest
.isCompleted()) {
286 fIndexRequest
.cancel();
289 cancelOngoingRequests();
292 TmfTimeRange window
= TmfTimeRange
.ETERNITY
;
294 fIndexRequest
= new TmfEventRequest(ITmfEvent
.class, window
, TmfDataRequest
.ALL_DATA
, DEFAULT_BLOCK_SIZE
, ITmfDataRequest
.ExecutionType
.BACKGROUND
) {
296 private ITmfTimestamp fFirstTime
= null;
297 private ITmfTimestamp fLastTime
= null;
298 private int fNbSeqEvents
= 0;
299 private final List
<ITmfSyncSequenceDiagramEvent
> fSdEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>(MAX_NUM_OF_MSG
);
303 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.core.event.ITmfEvent)
306 public void handleData(ITmfEvent event
) {
307 super.handleData(event
);
309 ITmfSyncSequenceDiagramEvent sdEvent
= getSequnceDiagramEvent(event
);
311 if (sdEvent
!= null) {
314 if (fFirstTime
== null) {
315 fFirstTime
= event
.getTimestamp();
318 fLastTime
= event
.getTimestamp();
320 if ((fNbSeqEvents
% MAX_NUM_OF_MSG
) == 0) {
323 fCheckPoints
.add(new TmfTimeRange(fFirstTime
, fLastTime
));
325 fView
.updateCoolBar();
334 if (fNbSeqEvents
> MAX_NUM_OF_MSG
) {
339 fSdEvents
.add(sdEvent
);
341 if (fNbSeqEvents
== MAX_NUM_OF_MSG
) {
342 fillCurrentPage(fSdEvents
);
349 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleSuccess()
352 public void handleSuccess() {
353 if ((fFirstTime
!= null) && (fLastTime
!= null)) {
357 fCheckPoints
.add(new TmfTimeRange(fFirstTime
, fLastTime
));
359 fView
.updateCoolBar();
366 if (fNbSeqEvents
<= MAX_NUM_OF_MSG
) {
367 fillCurrentPage(fSdEvents
);
370 super.handleSuccess();
375 * @see org.eclipse.linuxtools.tmf.core.request.TmfDataRequest#handleCompleted()
378 public void handleCompleted() {
379 if (fEvents
.isEmpty()) {
380 fFrame
= new Frame();
381 fView
.setFrameSync(fFrame
);
383 super.handleCompleted();
388 fTrace
.sendRequest(fIndexRequest
);
396 * Signal handler for the trace closed signal.
398 * @param signal The trace closed signal
402 public void traceClosed(TmfTraceClosedSignal signal
) {
403 if (signal
.getTrace() != fTrace
) {
408 if (fIndexRequest
!= null) {
409 if (!fIndexRequest
.isCompleted()) {
410 fIndexRequest
.cancel();
412 fIndexRequest
= null;
415 cancelOngoingRequests();
417 if (fFilterCriteria
!= null) {
418 fFilterCriteria
.clear();
421 FilterListDialog
.deactivateSavedGlobalFilters();
431 * Moves to the page that contains the time provided by the signal. The messages will be selected
432 * if the provided time is the time of a message.
434 * @param signal The Time synch signal.
437 public void synchToTime(TmfTimeSynchSignal signal
) {
440 if ((signal
.getSource() != this) && (fFrame
!= null) && (fCheckPoints
.size() > 0)) {
441 fCurrentTime
= signal
.getCurrentTime();
451 * Moves to the page that contains the current time provided by signal.
452 * No message will be selected however the focus will be set to the message
453 * if the provided time is the time of a message.
455 * @param signal The time range sync signal
458 public void synchToTimeRange(TmfRangeSynchSignal signal
) {
461 if ((signal
.getSource() != this) && (fFrame
!= null) && !fIsSignalSent
&& (fCheckPoints
.size() > 0)) {
462 TmfTimeRange newTimeRange
= signal
.getCurrentRange();
465 fCurrentTime
= newTimeRange
.getStartTime();
477 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#setViewer(org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView)
480 public void setViewer(SDView viewer
) {
485 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
486 fView
.setSDFindProvider(this);
487 fView
.setSDPagingProvider(this);
488 fView
.setSDFilterProvider(this);
492 IEditorPart editor
= fView
.getSite().getPage().getActiveEditor();
493 if (editor
instanceof ITmfTraceEditor
) {
494 ITmfTrace trace
= ((ITmfTraceEditor
) editor
).getTrace();
496 traceSelected(new TmfTraceSelectedSignal(this, trace
));
506 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#getTitleString()
509 public String
getTitleString() {
515 * @see org.eclipse.linuxtools.tmf.component.TmfComponent#dispose()
518 public void dispose() {
522 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
523 // During Eclipse shutdown the active workbench window is null
524 if (window
!= null) {
525 window
.getSelectionService().removePostSelectionListener(this);
528 if (fIndexRequest
!= null) {
529 if (!fIndexRequest
.isCompleted()) {
530 fIndexRequest
.cancel();
532 fIndexRequest
= null;
534 cancelOngoingRequests();
536 fView
.setSDFindProvider(null);
537 fView
.setSDPagingProvider(null);
538 fView
.setSDFilterProvider(null);
547 * @see org.eclipse.hyades.uml2sd.ui.actions.provider.ISDGraphNodeSupporter#isNodeSupported(int)
550 public boolean isNodeSupported(int nodeType
) {
552 case ISDGraphNodeSupporter
.LIFELINE
:
553 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
564 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter#getNodeName(int, java.lang.String)
567 public String
getNodeName(int nodeType
, String loaderClassName
) {
569 case ISDGraphNodeSupporter
.LIFELINE
:
570 return Messages
.TmfUml2SDSyncLoader_CategoryLifeline
;
571 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
572 return Messages
.TmfUml2SDSyncLoader_CategoryMessage
;
576 return ""; //$NON-NLS-1$
581 * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
584 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
585 ISelection sel
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
586 if ((sel
!= null) && (sel
instanceof StructuredSelection
)) {
587 StructuredSelection stSel
= (StructuredSelection
) sel
;
588 if (stSel
.getFirstElement() instanceof TmfSyncMessage
) {
589 TmfSyncMessage syncMsg
= ((TmfSyncMessage
) stSel
.getFirstElement());
590 broadcast(new TmfTimeSynchSignal(this, syncMsg
.getStartTime()));
598 * org.eclipse.hyades.uml2sd.ui.actions.provider.ISDFindProvider#find(org.eclipse.hyades.uml2sd.ui.actions.widgets.Criteria)
601 public boolean find(Criteria toSearch
) {
604 if (fFrame
== null) {
608 if ((fFindResults
== null) || (fFindCriteria
== null) || !fFindCriteria
.compareTo(toSearch
)) {
609 fFindResults
= new CopyOnWriteArrayList
<GraphNode
>();
610 fFindCriteria
= toSearch
;
611 if (fFindCriteria
.isLifeLineSelected()) {
612 for (int i
= 0; i
< fFrame
.lifeLinesCount(); i
++) {
613 if (fFindCriteria
.matches(fFrame
.getLifeline(i
).getName())) {
614 fFindResults
.add(fFrame
.getLifeline(i
));
619 ArrayList
<GraphNode
> msgs
= new ArrayList
<GraphNode
>();
620 if (fFindCriteria
.isSyncMessageSelected()) {
621 for (int i
= 0; i
< fFrame
.syncMessageCount(); i
++) {
622 if (fFindCriteria
.matches(fFrame
.getSyncMessage(i
).getName())) {
623 msgs
.add(fFrame
.getSyncMessage(i
));
628 if (!msgs
.isEmpty()) {
629 fFindResults
.addAll(msgs
);
632 @SuppressWarnings("rawtypes")
633 List selection
= fView
.getSDWidget().getSelection();
634 if ((selection
!= null) && (selection
.size() == 1)) {
635 fCurrentFindIndex
= fFindResults
.indexOf(selection
.get(0)) + 1;
637 fCurrentFindIndex
= 0;
643 if (fFindResults
.size() > fCurrentFindIndex
) {
644 GraphNode current
= fFindResults
.get(fCurrentFindIndex
);
645 fView
.getSDWidget().moveTo(current
);
649 fCurrentFindIndex
=0;
650 return findInNextPages(fFindCriteria
); // search in other page
658 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFindProvider#cancel()
661 public void cancel() {
662 cancelOngoingRequests();
667 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFilterProvider#filter(java.util.List)
669 @SuppressWarnings("unchecked")
671 public boolean filter(List
<?
> filters
) {
674 cancelOngoingRequests();
676 if (filters
== null) {
677 fFilterCriteria
= new ArrayList
<FilterCriteria
>();
679 List
<FilterCriteria
> list
= (List
<FilterCriteria
>)filters
;
680 fFilterCriteria
= new ArrayList
<FilterCriteria
>(list
);
683 fillCurrentPage(fEvents
);
693 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasNextPage()
696 public boolean hasNextPage() {
699 int size
= fCheckPoints
.size();
701 return fCurrentPage
< (size
- 1);
711 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasPrevPage()
714 public boolean hasPrevPage() {
717 return fCurrentPage
> 0;
725 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#nextPage()
728 public void nextPage() {
732 if (fCurrentPage
>= (fCheckPoints
.size() - 1)) {
736 cancelOngoingRequests();
747 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#prevPage()
750 public void prevPage() {
754 if (fCurrentPage
<= 0) {
758 cancelOngoingRequests();
769 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#firstPage()
772 public void firstPage() {
776 cancelOngoingRequests();
787 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#lastPage()
790 public void lastPage() {
793 cancelOngoingRequests();
795 fCurrentPage
= fCheckPoints
.size() - 1;
804 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#currentPage()
807 public int currentPage() {
818 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pagesCount()
821 public int pagesCount() {
824 return fCheckPoints
.size();
832 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pageNumberChanged(int)
835 public void pageNumberChanged(int pagenNumber
) {
836 int localPageNumber
= pagenNumber
;
840 cancelOngoingRequests();
842 if (localPageNumber
< 0) {
845 int size
= fCheckPoints
.size();
846 if (localPageNumber
> (size
- 1)) {
847 localPageNumber
= size
- 1;
849 fCurrentPage
= localPageNumber
;
858 * @see org.eclipse.linuxtools.tmf.component.TmfComponent#broadcast(org.eclipse.linuxtools.tmf.signal.TmfSignal)
861 public void broadcast(TmfSignal signal
) {
862 fIsSignalSent
= true;
863 super.broadcast(signal
);
864 fIsSignalSent
= false;
868 * Cancels any ongoing find operation
870 protected void cancelOngoingRequests() {
873 // Cancel the search thread
874 if (fFindJob
!= null) {
879 fFindCriteria
= null;
880 fCurrentFindIndex
= 0;
882 if (fPageRequest
!= null) {
883 if (!fPageRequest
.isCompleted()) {
884 fPageRequest
.cancel();
894 * Resets loader attributes
896 protected void resetLoader() {
901 fCheckPoints
.clear();
903 fCurrentFindIndex
= 0;
904 fFindCriteria
= null;
906 fView
.setFrameSync(new Frame());
916 * Fills current page with sequence diagram content.
918 * @param events sequence diagram events
920 protected void fillCurrentPage(List
<ITmfSyncSequenceDiagramEvent
> events
) {
924 fEvents
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>(events
);
925 if (fView
!= null && !events
.isEmpty()) {
926 fView
.toggleWaitCursorAsync(true);
932 final Frame frame
= new Frame();
934 if (!events
.isEmpty()) {
935 Map
<String
, Lifeline
> nodeToLifelineMap
= new HashMap
<String
, Lifeline
>();
937 frame
.setName(Messages
.TmfUml2SDSyncLoader_FrameName
);
939 for (int i
= 0; i
< events
.size(); i
++) {
941 ITmfSyncSequenceDiagramEvent sdEvent
= events
.get(i
);
943 if ((nodeToLifelineMap
.get(sdEvent
.getSender()) == null) && (!filterLifeLine(sdEvent
.getSender()))) {
944 Lifeline lifeline
= new Lifeline();
945 lifeline
.setName(sdEvent
.getSender());
946 nodeToLifelineMap
.put(sdEvent
.getSender(), lifeline
);
947 frame
.addLifeLine(lifeline
);
950 if ((nodeToLifelineMap
.get(sdEvent
.getReceiver()) == null) && (!filterLifeLine(sdEvent
.getReceiver()))) {
951 Lifeline lifeline
= new Lifeline();
952 lifeline
.setName(sdEvent
.getReceiver());
953 nodeToLifelineMap
.put(sdEvent
.getReceiver(), lifeline
);
954 frame
.addLifeLine(lifeline
);
958 int eventOccurence
= 1;
960 for (int i
= 0; i
< events
.size(); i
++) {
961 ITmfSyncSequenceDiagramEvent sdEvent
= events
.get(i
);
963 // Check message filter
964 if (filterMessage(sdEvent
)) {
968 // Set the message sender and receiver
969 Lifeline startLifeline
= nodeToLifelineMap
.get(sdEvent
.getSender());
970 Lifeline endLifeline
= nodeToLifelineMap
.get(sdEvent
.getReceiver());
972 // Check if any of the lifelines were filtered
973 if ((startLifeline
== null) || (endLifeline
== null)) {
977 int tmp
= Math
.max(startLifeline
.getEventOccurrence(), endLifeline
.getEventOccurrence());
978 eventOccurence
= Math
.max(eventOccurence
, tmp
);
980 startLifeline
.setCurrentEventOccurrence(eventOccurence
);
981 endLifeline
.setCurrentEventOccurrence(eventOccurence
);
983 TmfSyncMessage message
= new TmfSyncMessage(sdEvent
, eventOccurence
++);
985 message
.setStartLifeline(startLifeline
);
986 message
.setEndLifeline(endLifeline
);
988 message
.setTime(sdEvent
.getStartTime());
990 // add the message to the frame
991 frame
.addMessage(message
);
996 if (!fView
.getSDWidget().isDisposed()) {
997 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1004 // check if view was disposed in the meanwhile
1005 if ((fView
!= null) && (!fView
.getSDWidget().isDisposed())) {
1007 fView
.setFrame(fFrame
);
1009 if (fCurrentTime
!= null) {
1010 moveToMessageInPage();
1013 if (fFindCriteria
!= null) {
1014 find(fFindCriteria
);
1017 fView
.toggleWaitCursorAsync(false);
1034 * Moves to a certain message defined by timestamp (across pages)
1036 protected void moveToMessage() {
1041 page
= getPage(fCurrentTime
);
1043 if (page
== fCurrentPage
) {
1044 moveToMessageInPage();
1047 fCurrentPage
= page
;
1055 * Moves to a certain message defined by timestamp in current page
1057 protected void moveToMessageInPage() {
1060 if (!fView
.getSDWidget().isDisposed()) {
1061 // Check for GUI thread
1062 if(Display
.getCurrent() != null) {
1063 // Already in GUI thread - execute directly
1064 TmfSyncMessage prevMessage
= null;
1065 TmfSyncMessage syncMessage
= null;
1066 boolean isExactTime
= false;
1067 for (int i
= 0; i
< fFrame
.syncMessageCount(); i
++) {
1068 if (fFrame
.getSyncMessage(i
) instanceof TmfSyncMessage
) {
1069 syncMessage
= (TmfSyncMessage
) fFrame
.getSyncMessage(i
);
1070 if (syncMessage
.getStartTime().compareTo(fCurrentTime
, false) == 0) {
1073 } else if ((syncMessage
.getStartTime().compareTo(fCurrentTime
, false) > 0) && (prevMessage
!= null)) {
1074 syncMessage
= prevMessage
;
1077 prevMessage
= syncMessage
;
1080 if (fIsSelect
&& isExactTime
) {
1081 fView
.getSDWidget().moveTo(syncMessage
);
1084 fView
.getSDWidget().ensureVisible(syncMessage
);
1085 fView
.getSDWidget().clearSelection();
1086 fView
.getSDWidget().redraw();
1090 // Not in GUI thread - queue action in GUI thread.
1091 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1094 moveToMessageInPage();
1106 * Moves to a certain message defined by timestamp (across pages)
1108 protected void moveToPage() {
1113 * Moves to a certain page.
1115 * @param notifyAll true to broadcast time range signal to other signal handlers else false
1117 protected void moveToPage(boolean notifyAll
) {
1119 TmfTimeRange window
= null;
1124 if (fCurrentPage
> fCheckPoints
.size()) {
1127 window
= fCheckPoints
.get(fCurrentPage
);
1132 if (window
== null) {
1133 window
= TmfTimeRange
.ETERNITY
;
1136 fPageRequest
= new TmfEventRequest(ITmfEvent
.class, window
, TmfDataRequest
.ALL_DATA
, 1, ITmfDataRequest
.ExecutionType
.FOREGROUND
) {
1137 private final List
<ITmfSyncSequenceDiagramEvent
> fSdEvent
= new ArrayList
<ITmfSyncSequenceDiagramEvent
>();
1140 public void handleData(ITmfEvent event
) {
1141 super.handleData(event
);
1143 ITmfSyncSequenceDiagramEvent sdEvent
= getSequnceDiagramEvent(event
);
1145 if (sdEvent
!= null) {
1146 fSdEvent
.add(sdEvent
);
1151 public void handleSuccess() {
1152 fillCurrentPage(fSdEvent
);
1153 super.handleSuccess();
1158 fTrace
.sendRequest(fPageRequest
);
1161 TmfTimeRange timeRange
= getSignalTimeRange(window
.getStartTime());
1162 broadcast(new TmfRangeSynchSignal(this, timeRange
, timeRange
.getStartTime()));
1167 * Gets page that contains timestamp
1169 * @param time The timestamp
1170 * @return page that contains the time
1172 protected int getPage(ITmfTimestamp time
) {
1177 size
= fCheckPoints
.size();
1178 for (page
= 0; page
< size
; page
++) {
1179 TmfTimeRange timeRange
= fCheckPoints
.get(page
);
1180 if (timeRange
.getEndTime().compareTo(time
, false) >= 0) {
1194 * Background search in trace for expression in criteria.
1196 * @param findCriteria The find criteria
1197 * @return true if background request was started else false
1199 protected boolean findInNextPages(Criteria findCriteria
) {
1202 if (fFindJob
!= null) {
1206 int nextPage
= fCurrentPage
+ 1;
1208 if ((nextPage
) >= fCheckPoints
.size()) {
1209 // we are at the end
1213 TmfTimeRange window
= new TmfTimeRange(fCheckPoints
.get(nextPage
).getStartTime(), fCheckPoints
.get(fCheckPoints
.size()-1).getEndTime());
1214 fFindJob
= new SearchJob(findCriteria
, window
);
1215 fFindJob
.schedule();
1216 fView
.toggleWaitCursorAsync(true);
1224 * Gets time range for time range signal.
1226 * @param startTime The start time of time range.
1227 * @return the time range
1229 protected TmfTimeRange
getSignalTimeRange(ITmfTimestamp startTime
) {
1232 long offset
= fTrace
== null ?
0 : fTrace
.getCurrentRange().getEndTime().getDelta(fTrace
.getCurrentRange().getStartTime()).normalize(0, startTime
.getScale()).getValue();
1233 TmfTimestamp initialEndOfWindow
= new TmfTimestamp(startTime
.getValue() + offset
, startTime
.getScale(), startTime
.getPrecision());
1234 return new TmfTimeRange(startTime
, initialEndOfWindow
);
1242 * Checks if filter criteria matches the message name in given SD event.
1244 * @param sdEvent The SD event to check
1245 * @return true if match else false.
1247 protected boolean filterMessage(ITmfSyncSequenceDiagramEvent sdEvent
) {
1250 if (fFilterCriteria
!= null) {
1251 for(FilterCriteria criteria
: fFilterCriteria
) {
1252 if (criteria
.isActive() && criteria
.getCriteria().isSyncMessageSelected() && criteria
.getCriteria().matches(sdEvent
.getName())) {
1264 * Checks if filter criteria matches a lifeline name (sender or receiver) in given SD event.
1266 * @param lifeline the message receiver
1267 * @return true if match else false.
1269 protected boolean filterLifeLine(String lifeline
) {
1272 if (fFilterCriteria
!= null) {
1273 for(FilterCriteria criteria
: fFilterCriteria
) {
1274 if (criteria
.isActive() && criteria
.getCriteria().isLifeLineSelected() && criteria
.getCriteria().matches(lifeline
)) {
1286 * Job to search in trace for given time range.
1288 protected class SearchJob
extends Job
{
1291 * The search event request.
1293 final protected SearchEventRequest fSearchRequest
;
1298 * @param findCriteria The search criteria
1299 * @param window Time range to search in
1301 public SearchJob(Criteria findCriteria
, TmfTimeRange window
) {
1302 super(Messages
.TmfUml2SDSyncLoader_SearchJobDescrition
);
1303 fSearchRequest
= new SearchEventRequest(window
, TmfDataRequest
.ALL_DATA
, 1, ITmfDataRequest
.ExecutionType
.FOREGROUND
, findCriteria
);
1308 * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
1311 protected IStatus
run(IProgressMonitor monitor
) {
1312 fSearchRequest
.setMonitor(monitor
);
1314 fTrace
.sendRequest(fSearchRequest
);
1317 fSearchRequest
.waitForCompletion();
1318 } catch (InterruptedException e
) {
1319 Activator
.getDefault().logError("Search request interrupted!", e
); //$NON-NLS-1$
1322 IStatus status
= Status
.OK_STATUS
;
1323 if (fSearchRequest
.isFound() && (fSearchRequest
.getFoundTime() != null)) {
1324 fCurrentTime
= fSearchRequest
.getFoundTime();
1326 // Avoid double-selection. Selection will be done when calling find(criteria)
1327 // after moving to relevant page
1329 if (!fView
.getSDWidget().isDisposed()) {
1330 fView
.getSDWidget().getDisplay().asyncExec(new Runnable() {
1340 if (monitor
.isCanceled()) {
1341 status
= Status
.CANCEL_STATUS
;
1344 // String was not found
1345 status
= new Status(IStatus
.WARNING
, Activator
.PLUGIN_ID
, Messages
.TmfUml2SDSyncLoader_SearchNotFound
);
1347 setProperty(IProgressConstants
.KEEP_PROPERTY
, Boolean
.TRUE
);
1353 fView
.toggleWaitCursorAsync(false);
1364 * @see org.eclipse.core.runtime.jobs.Job#canceling()
1367 protected void canceling() {
1368 fSearchRequest
.cancel();
1379 * TMF event request for searching within trace.
1381 protected class SearchEventRequest
extends TmfEventRequest
{
1384 * The find criteria.
1386 final private Criteria fCriteria
;
1388 * A progress monitor
1390 private IProgressMonitor fMonitor
;
1392 * Flag to indicate that node was found according the criteria .
1394 private boolean fIsFound
= false;
1396 * Time stamp of found item.
1398 private ITmfTimestamp fFoundTime
= null;
1402 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1403 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1404 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1405 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1406 * @param criteria The search criteria
1408 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType execType
, Criteria criteria
) {
1409 this(range
, nbRequested
, blockSize
, execType
, criteria
, null);
1414 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1415 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1416 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1417 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1418 * @param criteria The search criteria
1419 * @param monitor progress monitor
1421 public SearchEventRequest(TmfTimeRange range
, int nbRequested
, int blockSize
, ExecutionType execType
, Criteria criteria
, IProgressMonitor monitor
) {
1422 super(ITmfEvent
.class, range
, nbRequested
, blockSize
, execType
);
1423 fCriteria
= new Criteria(criteria
);
1429 * @see org.eclipse.linuxtools.tmf.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.event.TmfData)
1432 public void handleData(ITmfEvent event
) {
1433 super.handleData(event
);
1435 if ((fMonitor
!= null) && fMonitor
.isCanceled()) {
1440 ITmfSyncSequenceDiagramEvent sdEvent
= getSequnceDiagramEvent(event
);
1442 if (sdEvent
!= null) {
1444 if (fCriteria
.isLifeLineSelected()) {
1445 if (fCriteria
.matches(sdEvent
.getSender())) {
1446 fFoundTime
= event
.getTimestamp();
1451 if (fCriteria
.matches(sdEvent
.getReceiver())) {
1452 fFoundTime
= event
.getTimestamp();
1458 if (fCriteria
.isSyncMessageSelected() && fCriteria
.matches(sdEvent
.getName())) {
1459 fFoundTime
= event
.getTimestamp();
1467 * Set progress monitor.
1469 * @param monitor The monitor to assign
1471 public void setMonitor(IProgressMonitor monitor
) {
1476 * Check if find criteria was met.
1478 * @return true if find criteria was met.
1480 public boolean isFound() {
1485 * Returns timestamp of found time.
1487 * @return timestamp of found time.
1489 public ITmfTimestamp
getFoundTime() {
1495 * Job class to provide progress monitor feedback.
1498 * @author Bernd Hufmann
1501 protected static class IndexingJob
extends Job
{
1504 * @param name The job name
1506 public IndexingJob(String name
) {
1511 protected IStatus
run(IProgressMonitor monitor
) {
1512 while (!monitor
.isCanceled()) {
1515 } catch (InterruptedException e
) {
1516 return Status
.OK_STATUS
;
1520 return Status
.OK_STATUS
;
1526 * Returns sequence diagram event if details in given event are available else null.
1528 * @param tmfEvent Event to parse for sequence diagram event details
1529 * @return sequence diagram event if details are available else null
1531 protected ITmfSyncSequenceDiagramEvent
getSequnceDiagramEvent(ITmfEvent tmfEvent
){
1532 //type = .*RECEIVE.* or .*SEND.*
1533 //content = sender:<sender name>:receiver:<receiver name>,signal:<signal name>
1534 String eventType
= tmfEvent
.getType().toString();
1535 if (eventType
.contains(Messages
.TmfUml2SDSyncCloader_EventTypeSend
) || eventType
.contains(Messages
.TmfUml2SDSyncCloader_EventTypeReceive
)) {
1536 Object sender
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncCloader_FieldSender
);
1537 Object receiver
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncCloader_FieldReceiver
);
1538 Object name
= tmfEvent
.getContent().getField(Messages
.TmfUml2SDSyncCloader_FieldSignal
);
1539 if ((sender
instanceof ITmfEventField
) && (receiver
instanceof ITmfEventField
) && (name
instanceof ITmfEventField
)) {
1540 ITmfSyncSequenceDiagramEvent sdEvent
= new TmfSyncSequenceDiagramEvent(tmfEvent
,
1541 ((ITmfEventField
) sender
).getValue().toString(),
1542 ((ITmfEventField
) receiver
).getValue().toString(),
1543 ((ITmfEventField
) name
).getValue().toString());