ctf: Rename internal CTFStrings to MetadataStrings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / loader / TmfUml2SDSyncLoader.java
CommitLineData
73005152 1/**********************************************************************
c8422608 2 * Copyright (c) 2011, 2013 Ericsson
a55887ca 3 *
73005152
BH
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
a55887ca
AM
8 *
9 * Contributors:
73005152
BH
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
c8422608 12
df0b8ff4 13package org.eclipse.linuxtools.tmf.ui.views.uml2sd.loader;
73005152
BH
14
15import java.util.ArrayList;
16import java.util.HashMap;
17import java.util.List;
eb63f5ff 18import java.util.Map;
73005152
BH
19import java.util.concurrent.CopyOnWriteArrayList;
20import java.util.concurrent.locks.ReentrantLock;
21
22import org.eclipse.core.runtime.IProgressMonitor;
23import org.eclipse.core.runtime.IStatus;
24import org.eclipse.core.runtime.Status;
25import org.eclipse.core.runtime.jobs.Job;
26import org.eclipse.jface.viewers.ISelection;
27import org.eclipse.jface.viewers.StructuredSelection;
8fd82db5 28import org.eclipse.linuxtools.internal.tmf.ui.Activator;
6c13869b 29import org.eclipse.linuxtools.tmf.core.component.TmfComponent;
13e157b1
MK
30import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
31import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
6c13869b
FC
32import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
33import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
34import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
35import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
6c13869b
FC
36import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;
37import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
38import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
39import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;
faa38350 40import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal;
fec1ac0b 41import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
faa38350 42import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal;
3bd46eef
AM
43import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
44import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
45import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
faa38350 46import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
248af329 47import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
6c13869b
FC
48import org.eclipse.linuxtools.tmf.core.uml2sd.ITmfSyncSequenceDiagramEvent;
49import org.eclipse.linuxtools.tmf.core.uml2sd.TmfSyncSequenceDiagramEvent;
faa38350 50import org.eclipse.linuxtools.tmf.ui.editors.ITmfTraceEditor;
73005152
BH
51import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView;
52import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Frame;
53import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode;
54import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline;
df0b8ff4
BH
55import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.Criteria;
56import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.FilterCriteria;
57import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.FilterListDialog;
73005152
BH
58import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider;
59import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFilterProvider;
60import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFindProvider;
61import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter;
73005152 62import org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader;
de7ddc02 63import org.eclipse.swt.widgets.Display;
faa38350 64import org.eclipse.ui.IEditorPart;
73005152
BH
65import org.eclipse.ui.ISelectionListener;
66import org.eclipse.ui.IWorkbenchPart;
526d9026 67import org.eclipse.ui.IWorkbenchWindow;
73005152
BH
68import org.eclipse.ui.PlatformUI;
69import org.eclipse.ui.progress.IProgressConstants;
70
71/**
73005152 72 * <p>
a55887ca
AM
73 * This class is a reference implementation of the
74 * <code>org.eclipse.linuxtools.tmf.ui.Uml2SDLoader</code> extension point. It
75 * provides a Sequence Diagram loader for a user space trace with specific trace
76 * content for sending and receiving signals between components. I also includes
77 * a default implementation for the <code>ITmfEvent</code> parsing.
73005152 78 * </p>
a55887ca
AM
79 *
80 * The class <code>TmfUml2SDSyncLoader</code> analyzes events from type
81 * <code>ITmfEvent</code> and creates events type
82 * <code>ITmfSyncSequenceDiagramEvent</code> if the <code>ITmfEvent</code>
83 * contains all relevant information. The analysis checks that the event type
84 * strings contains either string SEND or RECEIVE. If event type matches these
85 * key words, the analyzer will look for strings sender, receiver and signal in
86 * the event fields of type <code>ITmfEventField</code>. If all the data is
87 * found a sequence diagram event from can be created. Note that Sync Messages
88 * are assumed, which means start and end time are the same. <br>
df0b8ff4 89 * <br>
a55887ca
AM
90 * The parsing of the <code>ITmfEvent</code> is done in the method
91 * <code>getSequnceDiagramEvent()</code> of class
92 * <code>TmfUml2SDSyncLoader</code>. By extending the class
93 * <code>TmfUml2SDSyncLoader</code> and overwriting
94 * <code>getSequnceDiagramEvent()</code> a customized parsing algorithm can be
95 * implemented.<br>
96 * <br>
97 * Note that combined traces of multiple components, that contain the trace
98 * information about the same interactions are not supported in the class
99 * <code>TmfUml2SDSyncLoader</code>.
100 *
df0b8ff4
BH
101 * @version 1.0
102 * @author Bernd Hufmann
73005152
BH
103 */
104public class TmfUml2SDSyncLoader extends TmfComponent implements IUml2SDLoader, ISDFindProvider, ISDFilterProvider, ISDAdvancedPagingProvider, ISelectionListener {
105
106 // ------------------------------------------------------------------------
df0b8ff4 107 // Constants
73005152 108 // ------------------------------------------------------------------------
df0b8ff4
BH
109 /**
110 * Default title name.
111 */
f26e290b 112 protected static final String TITLE = Messages.TmfUml2SDSyncLoader_ViewName;
df0b8ff4
BH
113 /**
114 * Default block size for background request.
115 */
f26e290b 116 protected static final int DEFAULT_BLOCK_SIZE = 50000;
df0b8ff4
BH
117 /**
118 * Maximum number of messages per page.
119 */
f26e290b
BH
120 protected static final int MAX_NUM_OF_MSG = 10000;
121
122 private static final int INDEXING_THREAD_SLEEP_VALUE = 100;
df0b8ff4
BH
123
124 // ------------------------------------------------------------------------
125 // Attributes
126 // ------------------------------------------------------------------------
73005152
BH
127
128 // Experiment attributes
df0b8ff4 129 /**
faa38350
PT
130 * The TMF trace reference.
131 * @since 2.0
df0b8ff4 132 */
faa38350 133 protected ITmfTrace fTrace = null;
df0b8ff4
BH
134 /**
135 * The current indexing event request.
136 */
6256d8ad 137 protected ITmfEventRequest fIndexRequest = null;
df0b8ff4
BH
138 /**
139 * The current request to fill a page.
140 */
6256d8ad 141 protected ITmfEventRequest fPageRequest = null;
df0b8ff4
BH
142 /**
143 * Flag whether the time range signal was sent by this loader class or not
144 */
f26e290b 145 protected volatile boolean fIsSignalSent = false;
13e157b1 146
73005152 147 // The view and event attributes
df0b8ff4
BH
148 /**
149 * The sequence diagram view reference.
150 */
73005152 151 protected SDView fView = null;
df0b8ff4
BH
152 /**
153 * The current sequence diagram frame reference.
154 */
73005152 155 protected Frame fFrame = null;
df0b8ff4
BH
156 /**
157 * The list of sequence diagram events of current page.
158 */
73005152
BH
159 protected List<ITmfSyncSequenceDiagramEvent> fEvents = new ArrayList<ITmfSyncSequenceDiagramEvent>();
160
161 // Checkpoint and page attributes
df0b8ff4
BH
162 /**
163 * The checkpoints of the whole sequence diagram trace (i.e. start time stamp of each page)
164 */
73005152 165 protected List<TmfTimeRange> fCheckPoints = new ArrayList<TmfTimeRange>(MAX_NUM_OF_MSG);
df0b8ff4
BH
166 /**
167 * The current page displayed.
168 */
f26e290b 169 protected volatile int fCurrentPage = 0;
df0b8ff4
BH
170 /**
171 * The current time selected.
172 */
4df4581d 173 protected ITmfTimestamp fCurrentTime = null;
df0b8ff4
BH
174 /**
175 * Flag to specify that selection of message is done by selection or by signal.
176 */
f26e290b 177 protected volatile boolean fIsSelect = false;
73005152
BH
178
179 // Search attributes
df0b8ff4 180 /**
a55887ca 181 * The job for searching across pages.
df0b8ff4 182 */
73005152 183 protected SearchJob fFindJob = null;
df0b8ff4
BH
184 /**
185 * List of found nodes within a page.
186 */
73005152 187 protected List<GraphNode> fFindResults = new ArrayList<GraphNode>();
df0b8ff4
BH
188 /**
189 * The current find criteria reference
190 */
73005152 191 protected Criteria fFindCriteria = null;
df0b8ff4
BH
192 /**
193 * The current find index within the list of found nodes (<code>fFindeResults</code> within a page.
194 */
f26e290b 195 protected volatile int fCurrentFindIndex = 0;
73005152
BH
196
197 // Filter attributes
df0b8ff4
BH
198 /**
199 * The list of active filters.
200 */
73005152 201 protected List<FilterCriteria> fFilterCriteria = null;
a55887ca 202
73005152 203 // Thread synchronization
df0b8ff4
BH
204 /**
205 * The synchronization lock.
206 */
73005152 207 protected ReentrantLock fLock = new ReentrantLock();
a55887ca 208
73005152
BH
209 // ------------------------------------------------------------------------
210 // Constructors
211 // ------------------------------------------------------------------------
df0b8ff4
BH
212 /**
213 * Default constructor
214 */
73005152
BH
215 public TmfUml2SDSyncLoader() {
216 super(TITLE);
217 }
218
df0b8ff4
BH
219 /**
220 * Constructor
a55887ca 221 *
df0b8ff4
BH
222 * @param name Name of loader
223 */
73005152
BH
224 public TmfUml2SDSyncLoader(String name) {
225 super(name);
226 }
227
228 // ------------------------------------------------------------------------
229 // Operations
230 // ------------------------------------------------------------------------
3bd46eef 231
73005152 232 /**
df0b8ff4 233 * Returns the current time if available else null.
a55887ca 234 *
df0b8ff4 235 * @return the current time if available else null
3bd46eef 236 * @since 2.0
73005152 237 */
4df4581d 238 public ITmfTimestamp getCurrentTime() {
a55887ca 239 fLock.lock();
73005152 240 try {
a55887ca 241 if (fCurrentTime != null) {
4593bd5b 242 return fCurrentTime;
73005152
BH
243 }
244 return null;
245 } finally {
246 fLock.unlock();
247 }
248 }
a55887ca 249
73005152
BH
250 /**
251 * Waits for the page request to be completed
252 */
253 public void waitForCompletion() {
254 fLock.lock();
6256d8ad 255 ITmfEventRequest request = fPageRequest;
73005152 256 fLock.unlock();
a55887ca
AM
257 if (request != null) {
258 try {
259 request.waitForCompletion();
260 } catch (InterruptedException e) {
261 // ignore
262 }
73005152
BH
263 }
264 }
265
fec1ac0b
BH
266 /**
267 * Handler for the trace opened signal.
268 * @param signal The trace opened signal
269 * @since 2.0
270 */
271 @TmfSignalHandler
272 public void traceOpened(TmfTraceOpenedSignal signal) {
273 fTrace = signal.getTrace();
274 loadTrace();
275 }
276
277
73005152 278 /**
faa38350 279 * Signal handler for the trace selected signal.
a55887ca 280 *
faa38350 281 * Spawns a request to index the trace (checkpoints creation) as well as it fills
73005152 282 * the first page.
a55887ca 283 *
faa38350
PT
284 * @param signal The trace selected signal
285 * @since 2.0
73005152 286 */
73005152 287 @TmfSignalHandler
faa38350 288 public void traceSelected(TmfTraceSelectedSignal signal) {
fec1ac0b
BH
289 // Update the trace reference
290 ITmfTrace trace = signal.getTrace();
291 if (!trace.equals(fTrace)) {
292 fTrace = trace;
293 }
294 loadTrace();
295 }
bfc779a0 296
fec1ac0b
BH
297 /**
298 * Method for loading the current selected trace into the view.
299 * Sub-class need to override this method to add the view specific implementation.
300 * @since 2.0
301 */
302 protected void loadTrace() {
e5d31efe 303 ITmfEventRequest indexRequest = null;
a55887ca 304 fLock.lock();
faa38350 305
fec1ac0b 306 try {
77ab0271
BH
307 final Job job = new IndexingJob("Indexing " + getName() + "..."); //$NON-NLS-1$ //$NON-NLS-2$
308 job.setUser(false);
309 job.schedule();
73005152 310
77ab0271
BH
311 indexRequest = fIndexRequest;
312
313 cancelOngoingRequests();
73005152 314
77ab0271 315 TmfTimeRange window = TmfTimeRange.ETERNITY;
73005152 316
77ab0271 317 fIndexRequest = new TmfEventRequest(ITmfEvent.class, window, TmfDataRequest.ALL_DATA, DEFAULT_BLOCK_SIZE, ITmfDataRequest.ExecutionType.BACKGROUND) {
73005152 318
77ab0271
BH
319 private ITmfTimestamp fFirstTime = null;
320 private ITmfTimestamp fLastTime = null;
321 private int fNbSeqEvents = 0;
322 private final List<ITmfSyncSequenceDiagramEvent> fSdEvents = new ArrayList<ITmfSyncSequenceDiagramEvent>(MAX_NUM_OF_MSG);
73005152 323
77ab0271
BH
324 @Override
325 public void handleData(ITmfEvent event) {
326 super.handleData(event);
13e157b1 327
77ab0271
BH
328 ITmfSyncSequenceDiagramEvent sdEvent = getSequenceDiagramEvent(event);
329
330 if (sdEvent != null) {
331 ++fNbSeqEvents;
332
333 if (fFirstTime == null) {
334 fFirstTime = event.getTimestamp();
335 }
73005152 336
77ab0271
BH
337 fLastTime = event.getTimestamp();
338
339 if ((fNbSeqEvents % MAX_NUM_OF_MSG) == 0) {
340 fLock.lock();
341 try {
342 fCheckPoints.add(new TmfTimeRange(fFirstTime, fLastTime));
343 if (fView != null) {
344 fView.updateCoolBar();
345 }
346 } finally {
347 fLock.unlock();
348 }
349 fFirstTime = null;
350
351 }
352
353 if (fNbSeqEvents > MAX_NUM_OF_MSG) {
354 // page is full
355 return;
356 }
73005152 357
77ab0271 358 fSdEvents.add(sdEvent);
73005152 359
77ab0271
BH
360 if (fNbSeqEvents == MAX_NUM_OF_MSG) {
361 fillCurrentPage(fSdEvents);
362 }
73005152 363 }
77ab0271 364 }
73005152 365
77ab0271
BH
366 @Override
367 public void handleSuccess() {
368 if ((fFirstTime != null) && (fLastTime != null)) {
73005152
BH
369
370 fLock.lock();
371 try {
372 fCheckPoints.add(new TmfTimeRange(fFirstTime, fLastTime));
373 if (fView != null) {
374 fView.updateCoolBar();
375 }
376 } finally {
377 fLock.unlock();
378 }
379 }
380
77ab0271 381 if (fNbSeqEvents <= MAX_NUM_OF_MSG) {
fec1ac0b
BH
382 fillCurrentPage(fSdEvents);
383 }
73005152 384
77ab0271
BH
385 super.handleSuccess();
386 }
fec1ac0b 387
77ab0271
BH
388 @Override
389 public void handleCompleted() {
390 if (fEvents.isEmpty()) {
391 fFrame = new Frame();
392 // make sure that view is not null when setting frame
393 SDView sdView;
394 fLock.lock();
395 try {
396 sdView = fView;
397 } finally {
398 fLock.unlock();
399 }
400 if (sdView != null) {
401 sdView.setFrameSync(fFrame);
fec1ac0b 402 }
73005152 403 }
77ab0271
BH
404 super.handleCompleted();
405 job.cancel();
73005152 406 }
77ab0271 407 };
73005152 408
77ab0271
BH
409 } finally {
410 fLock.unlock();
411 }
412 if (indexRequest != null && !indexRequest.isCompleted()) {
413 indexRequest.cancel();
414 }
415 resetLoader();
416 fTrace.sendRequest(fIndexRequest);
73005152
BH
417 }
418
419 /**
faa38350 420 * Signal handler for the trace closed signal.
a55887ca 421 *
faa38350
PT
422 * @param signal The trace closed signal
423 * @since 2.0
73005152 424 */
13e157b1 425 @TmfSignalHandler
faa38350
PT
426 public void traceClosed(TmfTraceClosedSignal signal) {
427 if (signal.getTrace() != fTrace) {
828e5592
PT
428 return;
429 }
e5d31efe 430 ITmfEventRequest indexRequest = null;
13e157b1 431 fLock.lock();
73005152 432 try {
d10e93a2
PT
433 indexRequest = fIndexRequest;
434 fIndexRequest = null;
73005152
BH
435
436 cancelOngoingRequests();
437
438 if (fFilterCriteria != null) {
439 fFilterCriteria.clear();
440 }
441
442 FilterListDialog.deactivateSavedGlobalFilters();
73005152 443 } finally {
faa38350 444 fTrace = null;
73005152
BH
445 fLock.unlock();
446 }
d10e93a2
PT
447 if (indexRequest != null && !indexRequest.isCompleted()) {
448 indexRequest.cancel();
449 }
450
451 resetLoader();
73005152
BH
452 }
453
454 /**
455 * Moves to the page that contains the time provided by the signal. The messages will be selected
456 * if the provided time is the time of a message.
13e157b1 457 *
73005152
BH
458 * @param signal The Time synch signal.
459 */
460 @TmfSignalHandler
461 public void synchToTime(TmfTimeSynchSignal signal) {
462 fLock.lock();
463 try {
aa63fb03 464 if ((signal.getSource() != this) && (fFrame != null) && (fCheckPoints.size() > 0)) {
73005152
BH
465 fCurrentTime = signal.getCurrentTime();
466 fIsSelect = true;
467 moveToMessage();
468 }
469 } finally {
470 fLock.unlock();
471 }
472 }
473
474 /**
a55887ca
AM
475 * Moves to the page that contains the current time provided by signal.
476 * No message will be selected however the focus will be set to the message
73005152 477 * if the provided time is the time of a message.
a55887ca 478 *
73005152
BH
479 * @param signal The time range sync signal
480 */
481 @TmfSignalHandler
482 public void synchToTimeRange(TmfRangeSynchSignal signal) {
483 fLock.lock();
484 try {
aa63fb03 485 if ((signal.getSource() != this) && (fFrame != null) && !fIsSignalSent && (fCheckPoints.size() > 0)) {
73005152 486 TmfTimeRange newTimeRange = signal.getCurrentRange();
73005152
BH
487
488 fIsSelect = false;
7d1ef69c 489 fCurrentTime = newTimeRange.getStartTime();
73005152
BH
490
491 moveToMessage();
492 }
493 } finally {
494 fLock.unlock();
495 }
496
497 }
13e157b1 498
73005152
BH
499 @Override
500 public void setViewer(SDView viewer) {
13e157b1
MK
501
502 fLock.lock();
73005152
BH
503 try {
504 fView = viewer;
505 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
506 fView.setSDFindProvider(this);
507 fView.setSDPagingProvider(this);
508 fView.setSDFilterProvider(this);
509
510 resetLoader();
f28d404e 511 IEditorPart editor = fView.getSite().getPage().getActiveEditor();
faa38350
PT
512 if (editor instanceof ITmfTraceEditor) {
513 ITmfTrace trace = ((ITmfTraceEditor) editor).getTrace();
514 if (trace != null) {
515 traceSelected(new TmfTraceSelectedSignal(this, trace));
516 }
73005152
BH
517 }
518 } finally {
519 fLock.unlock();
520 }
521 }
522
73005152
BH
523 @Override
524 public String getTitleString() {
525 return getName();
526 }
527
73005152
BH
528 @Override
529 public void dispose() {
530 super.dispose();
e5d31efe 531 ITmfEventRequest indexRequest = null;
13e157b1 532 fLock.lock();
73005152 533 try {
526d9026
BH
534 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
535 // During Eclipse shutdown the active workbench window is null
536 if (window != null) {
537 window.getSelectionService().removePostSelectionListener(this);
538 }
4b4a1525 539
d10e93a2
PT
540 indexRequest = fIndexRequest;
541 fIndexRequest = null;
4b4a1525
BH
542 cancelOngoingRequests();
543
73005152
BH
544 fView.setSDFindProvider(null);
545 fView.setSDPagingProvider(null);
546 fView.setSDFilterProvider(null);
547 fView = null;
548 } finally {
549 fLock.unlock();
550 }
d10e93a2
PT
551 if (indexRequest != null && !indexRequest.isCompleted()) {
552 indexRequest.cancel();
553 }
73005152
BH
554 }
555
73005152
BH
556 @Override
557 public boolean isNodeSupported(int nodeType) {
558 switch (nodeType) {
559 case ISDGraphNodeSupporter.LIFELINE:
560 case ISDGraphNodeSupporter.SYNCMESSAGE:
561 return true;
562
563 default:
564 break;
565 }
566 return false;
567 }
568
73005152
BH
569 @Override
570 public String getNodeName(int nodeType, String loaderClassName) {
571 switch (nodeType) {
572 case ISDGraphNodeSupporter.LIFELINE:
573 return Messages.TmfUml2SDSyncLoader_CategoryLifeline;
574 case ISDGraphNodeSupporter.SYNCMESSAGE:
575 return Messages.TmfUml2SDSyncLoader_CategoryMessage;
abbdd66a
AM
576 default:
577 break;
73005152
BH
578 }
579 return ""; //$NON-NLS-1$
580 }
581
73005152
BH
582 @Override
583 public void selectionChanged(IWorkbenchPart part, ISelection selection) {
584 ISelection sel = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
13e157b1 585 if ((sel != null) && (sel instanceof StructuredSelection)) {
73005152
BH
586 StructuredSelection stSel = (StructuredSelection) sel;
587 if (stSel.getFirstElement() instanceof TmfSyncMessage) {
588 TmfSyncMessage syncMsg = ((TmfSyncMessage) stSel.getFirstElement());
589 broadcast(new TmfTimeSynchSignal(this, syncMsg.getStartTime()));
590 }
591 }
592 }
593
73005152
BH
594 @Override
595 public boolean find(Criteria toSearch) {
596 fLock.lock();
597 try {
598 if (fFrame == null) {
599 return false;
600 }
601
13e157b1 602 if ((fFindResults == null) || (fFindCriteria == null) || !fFindCriteria.compareTo(toSearch)) {
73005152
BH
603 fFindResults = new CopyOnWriteArrayList<GraphNode>();
604 fFindCriteria = toSearch;
605 if (fFindCriteria.isLifeLineSelected()) {
606 for (int i = 0; i < fFrame.lifeLinesCount(); i++) {
607 if (fFindCriteria.matches(fFrame.getLifeline(i).getName())) {
608 fFindResults.add(fFrame.getLifeline(i));
609 }
610 }
611 }
612
613 ArrayList<GraphNode> msgs = new ArrayList<GraphNode>();
614 if (fFindCriteria.isSyncMessageSelected()) {
615 for (int i = 0; i < fFrame.syncMessageCount(); i++) {
616 if (fFindCriteria.matches(fFrame.getSyncMessage(i).getName())) {
617 msgs.add(fFrame.getSyncMessage(i));
618 }
619 }
620 }
621
eb63f5ff 622 if (!msgs.isEmpty()) {
73005152
BH
623 fFindResults.addAll(msgs);
624 }
625
626 @SuppressWarnings("rawtypes")
627 List selection = fView.getSDWidget().getSelection();
13e157b1 628 if ((selection != null) && (selection.size() == 1)) {
73005152 629 fCurrentFindIndex = fFindResults.indexOf(selection.get(0)) + 1;
13e157b1 630 } else {
73005152 631 fCurrentFindIndex = 0;
13e157b1 632 }
73005152
BH
633 } else {
634 fCurrentFindIndex++;
635 }
636
637 if (fFindResults.size() > fCurrentFindIndex) {
13e157b1 638 GraphNode current = fFindResults.get(fCurrentFindIndex);
73005152
BH
639 fView.getSDWidget().moveTo(current);
640 return true;
73005152 641 }
abbdd66a
AM
642 fFindResults = null;
643 fCurrentFindIndex =0;
644 return findInNextPages(fFindCriteria); // search in other page
73005152
BH
645 } finally {
646 fLock.unlock();
647 }
648 }
649
73005152
BH
650 @Override
651 public void cancel() {
652 cancelOngoingRequests();
653 }
654
73005152
BH
655 @SuppressWarnings("unchecked")
656 @Override
657 public boolean filter(List<?> filters) {
658 fLock.lock();
659 try {
660 cancelOngoingRequests();
661
1ef1189a
BH
662 if (filters == null) {
663 fFilterCriteria = new ArrayList<FilterCriteria>();
664 } else {
665 List<FilterCriteria> list = (List<FilterCriteria>)filters;
666 fFilterCriteria = new ArrayList<FilterCriteria>(list);
667 }
73005152
BH
668
669 fillCurrentPage(fEvents);
670
671 } finally {
672 fLock.unlock();
673 }
674 return true;
675 }
13e157b1 676
73005152
BH
677 @Override
678 public boolean hasNextPage() {
679 fLock.lock();
680 try {
681 int size = fCheckPoints.size();
682 if (size > 0) {
13e157b1 683 return fCurrentPage < (size - 1);
73005152
BH
684 }
685 } finally {
686 fLock.unlock();
687 }
688 return false;
689 }
690
73005152
BH
691 @Override
692 public boolean hasPrevPage() {
693 fLock.lock();
694 try {
695 return fCurrentPage > 0;
696 } finally {
697 fLock.unlock();
698 }
699 }
700
73005152
BH
701 @Override
702 public void nextPage() {
703 fLock.lock();
704 try {
705 // Safety check
13e157b1 706 if (fCurrentPage >= (fCheckPoints.size() - 1)) {
73005152 707 return;
13e157b1 708 }
73005152
BH
709
710 cancelOngoingRequests();
711 fCurrentTime = null;
712 fCurrentPage++;
713 moveToPage();
714 } finally {
715 fLock.unlock();
716 }
717 }
718
73005152
BH
719 @Override
720 public void prevPage() {
721 fLock.lock();
722 try {
723 // Safety check
13e157b1 724 if (fCurrentPage <= 0) {
73005152 725 return;
13e157b1 726 }
73005152
BH
727
728 cancelOngoingRequests();
729 fCurrentTime = null;
730 fCurrentPage--;
731 moveToPage();
732 } finally {
733 fLock.unlock();
734 }
735 }
13e157b1 736
73005152
BH
737 @Override
738 public void firstPage() {
739 fLock.lock();
740 try {
741
742 cancelOngoingRequests();
743 fCurrentTime = null;
744 fCurrentPage = 0;
745 moveToPage();
746 } finally {
747 fLock.unlock();
748 }
749 }
13e157b1 750
73005152
BH
751 @Override
752 public void lastPage() {
753 fLock.lock();
754 try {
755 cancelOngoingRequests();
756 fCurrentTime = null;
757 fCurrentPage = fCheckPoints.size() - 1;
758 moveToPage();
759 } finally {
760 fLock.unlock();
761 }
762 }
763
73005152
BH
764 @Override
765 public int currentPage() {
766 fLock.lock();
767 try {
768 return fCurrentPage;
769 } finally {
770 fLock.unlock();
771 }
772 }
773
73005152
BH
774 @Override
775 public int pagesCount() {
776 fLock.lock();
777 try {
778 return fCheckPoints.size();
779 } finally {
780 fLock.unlock();
781 }
782 }
783
73005152 784 @Override
eb63f5ff
BH
785 public void pageNumberChanged(int pagenNumber) {
786 int localPageNumber = pagenNumber;
a55887ca 787
73005152
BH
788 fLock.lock();
789 try {
790 cancelOngoingRequests();
791
eb63f5ff
BH
792 if (localPageNumber < 0) {
793 localPageNumber = 0;
73005152
BH
794 }
795 int size = fCheckPoints.size();
eb63f5ff
BH
796 if (localPageNumber > (size - 1)) {
797 localPageNumber = size - 1;
73005152 798 }
eb63f5ff 799 fCurrentPage = localPageNumber;
73005152
BH
800 moveToPage();
801 } finally {
802 fLock.unlock();
803 }
804 }
805
73005152
BH
806 @Override
807 public void broadcast(TmfSignal signal) {
808 fIsSignalSent = true;
809 super.broadcast(signal);
810 fIsSignalSent = false;
811 }
812
813 /**
814 * Cancels any ongoing find operation
815 */
816 protected void cancelOngoingRequests() {
13e157b1 817 fLock.lock();
e5d31efe 818 ITmfEventRequest pageRequest = null;
73005152
BH
819 try {
820 // Cancel the search thread
821 if (fFindJob != null) {
822 fFindJob.cancel();
823 }
df0b8ff4 824
73005152
BH
825 fFindResults = null;
826 fFindCriteria = null;
827 fCurrentFindIndex = 0;
828
d10e93a2
PT
829 pageRequest = fPageRequest;
830 fPageRequest = null;
73005152
BH
831 } finally {
832 fLock.unlock();
833 }
d10e93a2
PT
834 if (pageRequest != null && !pageRequest.isCompleted()) {
835 pageRequest.cancel();
836 }
73005152
BH
837 }
838
839 /**
840 * Resets loader attributes
841 */
842 protected void resetLoader() {
843 fLock.lock();
844 try {
845 fCurrentTime = null;
846 fEvents.clear();
847 fCheckPoints.clear();
848 fCurrentPage = 0;
849 fCurrentFindIndex = 0;
850 fFindCriteria = null;
851 fFindResults = null;
73005152
BH
852 fView.setFrameSync(new Frame());
853 fFrame = null;
854 }
855 finally {
856 fLock.unlock();
857 }
858
859 }
860
861 /**
862 * Fills current page with sequence diagram content.
a55887ca 863 *
73005152
BH
864 * @param events sequence diagram events
865 */
866 protected void fillCurrentPage(List<ITmfSyncSequenceDiagramEvent> events) {
867
868 fLock.lock();
869 try {
870 fEvents = new ArrayList<ITmfSyncSequenceDiagramEvent>(events);
faa38350 871 if (fView != null && !events.isEmpty()) {
73005152
BH
872 fView.toggleWaitCursorAsync(true);
873 }
874 } finally {
875 fLock.unlock();
876 }
13e157b1 877
73005152 878 final Frame frame = new Frame();
73005152 879
eb63f5ff
BH
880 if (!events.isEmpty()) {
881 Map<String, Lifeline> nodeToLifelineMap = new HashMap<String, Lifeline>();
73005152
BH
882
883 frame.setName(Messages.TmfUml2SDSyncLoader_FrameName);
884
885 for (int i = 0; i < events.size(); i++) {
886
887 ITmfSyncSequenceDiagramEvent sdEvent = events.get(i);
888
889 if ((nodeToLifelineMap.get(sdEvent.getSender()) == null) && (!filterLifeLine(sdEvent.getSender()))) {
890 Lifeline lifeline = new Lifeline();
891 lifeline.setName(sdEvent.getSender());
892 nodeToLifelineMap.put(sdEvent.getSender(), lifeline);
893 frame.addLifeLine(lifeline);
894 }
895
896 if ((nodeToLifelineMap.get(sdEvent.getReceiver()) == null) && (!filterLifeLine(sdEvent.getReceiver()))) {
897 Lifeline lifeline = new Lifeline();
898 lifeline.setName(sdEvent.getReceiver());
899 nodeToLifelineMap.put(sdEvent.getReceiver(), lifeline);
900 frame.addLifeLine(lifeline);
901 }
902 }
903
904 int eventOccurence = 1;
905
906 for (int i = 0; i < events.size(); i++) {
13e157b1 907 ITmfSyncSequenceDiagramEvent sdEvent = events.get(i);
73005152
BH
908
909 // Check message filter
910 if (filterMessage(sdEvent)) {
911 continue;
912 }
913
914 // Set the message sender and receiver
13e157b1
MK
915 Lifeline startLifeline = nodeToLifelineMap.get(sdEvent.getSender());
916 Lifeline endLifeline = nodeToLifelineMap.get(sdEvent.getReceiver());
73005152 917
13e157b1
MK
918 // Check if any of the lifelines were filtered
919 if ((startLifeline == null) || (endLifeline == null)) {
73005152
BH
920 continue;
921 }
922
923 int tmp = Math.max(startLifeline.getEventOccurrence(), endLifeline.getEventOccurrence());
924 eventOccurence = Math.max(eventOccurence, tmp);
13e157b1 925
73005152
BH
926 startLifeline.setCurrentEventOccurrence(eventOccurence);
927 endLifeline.setCurrentEventOccurrence(eventOccurence);
13e157b1 928
73005152 929 TmfSyncMessage message = new TmfSyncMessage(sdEvent, eventOccurence++);
13e157b1 930
73005152
BH
931 message.setStartLifeline(startLifeline);
932 message.setEndLifeline(endLifeline);
933
934 message.setTime(sdEvent.getStartTime());
935
936 // add the message to the frame
937 frame.addMessage(message);
13e157b1 938
73005152
BH
939 }
940 fLock.lock();
941 try {
942 if (!fView.getSDWidget().isDisposed()) {
943 fView.getSDWidget().getDisplay().asyncExec(new Runnable() {
944
945 @Override
946 public void run() {
947
948 fLock.lock();
949 try {
950 // check if view was disposed in the meanwhile
951 if ((fView != null) && (!fView.getSDWidget().isDisposed())) {
952 fFrame = frame;
953 fView.setFrame(fFrame);
954
955 if (fCurrentTime != null) {
956 moveToMessageInPage();
957 }
958
959 if (fFindCriteria != null) {
960 find(fFindCriteria);
961 }
13e157b1 962
73005152
BH
963 fView.toggleWaitCursorAsync(false);
964 }
965 } finally {
966 fLock.unlock();
967 }
968
969 }
970 });
971 }
972 }
973 finally {
974 fLock.unlock();
975 }
976 }
977 }
978
979 /**
980 * Moves to a certain message defined by timestamp (across pages)
981 */
982 protected void moveToMessage() {
983 int page = 0;
984
985 fLock.lock();
986 try {
987 page = getPage(fCurrentTime);
988
989 if (page == fCurrentPage) {
990 moveToMessageInPage();
991 return;
992 }
993 fCurrentPage = page;
994 moveToPage(false);
995 } finally {
996 fLock.unlock();
997 }
998 }
999
1000 /**
1001 * Moves to a certain message defined by timestamp in current page
1002 */
1003 protected void moveToMessageInPage() {
1004 fLock.lock();
1005 try {
de7ddc02
BH
1006 if (!fView.getSDWidget().isDisposed()) {
1007 // Check for GUI thread
1008 if(Display.getCurrent() != null) {
1009 // Already in GUI thread - execute directly
1010 TmfSyncMessage prevMessage = null;
1011 TmfSyncMessage syncMessage = null;
1012 boolean isExactTime = false;
1013 for (int i = 0; i < fFrame.syncMessageCount(); i++) {
1014 if (fFrame.getSyncMessage(i) instanceof TmfSyncMessage) {
1015 syncMessage = (TmfSyncMessage) fFrame.getSyncMessage(i);
1016 if (syncMessage.getStartTime().compareTo(fCurrentTime, false) == 0) {
1017 isExactTime = true;
1018 break;
eb63f5ff
BH
1019 } else if ((syncMessage.getStartTime().compareTo(fCurrentTime, false) > 0) && (prevMessage != null)) {
1020 syncMessage = prevMessage;
1021 break;
de7ddc02
BH
1022 }
1023 prevMessage = syncMessage;
1024 }
1025 }
1026 if (fIsSelect && isExactTime) {
1027 fView.getSDWidget().moveTo(syncMessage);
1028 }
1029 else {
1030 fView.getSDWidget().ensureVisible(syncMessage);
1031 fView.getSDWidget().clearSelection();
1032 fView.getSDWidget().redraw();
1033 }
1034 }
1035 else {
13e157b1 1036 // Not in GUI thread - queue action in GUI thread.
de7ddc02
BH
1037 fView.getSDWidget().getDisplay().asyncExec(new Runnable() {
1038 @Override
1039 public void run() {
1040 moveToMessageInPage();
1041 }
1042 });
1043 }
1044 }
73005152
BH
1045 }
1046 finally {
1047 fLock.unlock();
1048 }
1049 }
13e157b1 1050
73005152
BH
1051 /**
1052 * Moves to a certain message defined by timestamp (across pages)
1053 */
1054 protected void moveToPage() {
1055 moveToPage(true);
1056 }
1057
1058 /**
1059 * Moves to a certain page.
a55887ca 1060 *
73005152
BH
1061 * @param notifyAll true to broadcast time range signal to other signal handlers else false
1062 */
1063 protected void moveToPage(boolean notifyAll) {
1064
eb63f5ff 1065 TmfTimeRange window = null;
73005152
BH
1066
1067 fLock.lock();
1068 try {
1069 // Safety check
1070 if (fCurrentPage > fCheckPoints.size()) {
1071 return;
1072 }
1073 window = fCheckPoints.get(fCurrentPage);
1074 } finally {
1075 fLock.unlock();
1076 }
1077
eb63f5ff
BH
1078 if (window == null) {
1079 window = TmfTimeRange.ETERNITY;
1080 }
1081
6256d8ad 1082 fPageRequest = new TmfEventRequest(ITmfEvent.class, window, TmfDataRequest.ALL_DATA, 1, ITmfDataRequest.ExecutionType.FOREGROUND) {
13e157b1 1083 private final List<ITmfSyncSequenceDiagramEvent> fSdEvent = new ArrayList<ITmfSyncSequenceDiagramEvent>();
73005152
BH
1084
1085 @Override
5419a136
AM
1086 public void handleData(ITmfEvent event) {
1087 super.handleData(event);
73005152 1088
9a43af17 1089 ITmfSyncSequenceDiagramEvent sdEvent = getSequenceDiagramEvent(event);
73005152
BH
1090
1091 if (sdEvent != null) {
1092 fSdEvent.add(sdEvent);
1093 }
1094 }
1095
1096 @Override
1097 public void handleSuccess() {
1098 fillCurrentPage(fSdEvent);
1099 super.handleSuccess();
1100 }
13e157b1 1101
73005152
BH
1102 };
1103
faa38350 1104 fTrace.sendRequest(fPageRequest);
73005152
BH
1105
1106 if (notifyAll) {
1107 TmfTimeRange timeRange = getSignalTimeRange(window.getStartTime());
1108 broadcast(new TmfRangeSynchSignal(this, timeRange, timeRange.getStartTime()));
1109 }
1110 }
1111
1112 /**
1113 * Gets page that contains timestamp
a55887ca 1114 *
73005152
BH
1115 * @param time The timestamp
1116 * @return page that contains the time
3bd46eef 1117 * @since 2.0
73005152 1118 */
4df4581d 1119 protected int getPage(ITmfTimestamp time) {
73005152
BH
1120 int page;
1121 int size;
1122 fLock.lock();
1123 try {
1124 size = fCheckPoints.size();
13e157b1 1125 for (page = 0; page < size; page++) {
73005152
BH
1126 TmfTimeRange timeRange = fCheckPoints.get(page);
1127 if (timeRange.getEndTime().compareTo(time, false) >= 0) {
1128 break;
1129 }
1130 }
1131 if (page >= size) {
1132 page = size - 1;
1133 }
1134 return page;
1135 } finally {
1136 fLock.unlock();
1137 }
1138 }
13e157b1 1139
73005152
BH
1140 /**
1141 * Background search in trace for expression in criteria.
a55887ca 1142 *
73005152
BH
1143 * @param findCriteria The find criteria
1144 * @return true if background request was started else false
1145 */
1146 protected boolean findInNextPages(Criteria findCriteria) {
1147 fLock.lock();
1148 try {
1149 if (fFindJob != null) {
1150 return true;
1151 }
1152
1153 int nextPage = fCurrentPage + 1;
1154
1155 if ((nextPage) >= fCheckPoints.size()) {
1156 // we are at the end
1157 return false;
1158 }
1159
4593bd5b 1160 TmfTimeRange window = new TmfTimeRange(fCheckPoints.get(nextPage).getStartTime(), fCheckPoints.get(fCheckPoints.size()-1).getEndTime());
73005152
BH
1161 fFindJob = new SearchJob(findCriteria, window);
1162 fFindJob.schedule();
1163 fView.toggleWaitCursorAsync(true);
1164 } finally {
1165 fLock.unlock();
1166 }
1167 return true;
1168 }
1169
1170 /**
1171 * Gets time range for time range signal.
a55887ca 1172 *
73005152 1173 * @param startTime The start time of time range.
0d9a6d76 1174 * @return the time range
3bd46eef 1175 * @since 2.0
73005152 1176 */
4df4581d 1177 protected TmfTimeRange getSignalTimeRange(ITmfTimestamp startTime) {
73005152
BH
1178 fLock.lock();
1179 try {
248af329
AM
1180 TmfTimeRange currentRange = TmfTraceManager.getInstance().getCurrentRange();
1181 long offset = fTrace == null ? 0 : currentRange.getEndTime().getDelta(currentRange.getStartTime()).normalize(0, startTime.getScale()).getValue();
d7ee91bb 1182 TmfTimestamp initialEndOfWindow = new TmfTimestamp(startTime.getValue() + offset, startTime.getScale(), startTime.getPrecision());
73005152
BH
1183 return new TmfTimeRange(startTime, initialEndOfWindow);
1184 }
1185 finally {
1186 fLock.unlock();
1187 }
1188 }
1189
1190 /**
13e157b1 1191 * Checks if filter criteria matches the message name in given SD event.
a55887ca 1192 *
73005152
BH
1193 * @param sdEvent The SD event to check
1194 * @return true if match else false.
1195 */
1196 protected boolean filterMessage(ITmfSyncSequenceDiagramEvent sdEvent) {
1197 fLock.lock();
1198 try {
1199 if (fFilterCriteria != null) {
1200 for(FilterCriteria criteria : fFilterCriteria) {
eb63f5ff
BH
1201 if (criteria.isActive() && criteria.getCriteria().isSyncMessageSelected() && criteria.getCriteria().matches(sdEvent.getName())) {
1202 return true;
73005152
BH
1203 }
1204 }
1205 }
1206 } finally {
1207 fLock.unlock();
1208 }
1209 return false;
1210 }
1211
1212 /**
13e157b1 1213 * Checks if filter criteria matches a lifeline name (sender or receiver) in given SD event.
a55887ca 1214 *
0d9a6d76 1215 * @param lifeline the message receiver
73005152
BH
1216 * @return true if match else false.
1217 */
1218 protected boolean filterLifeLine(String lifeline) {
1219 fLock.lock();
1220 try {
1221 if (fFilterCriteria != null) {
1222 for(FilterCriteria criteria : fFilterCriteria) {
eb63f5ff
BH
1223 if (criteria.isActive() && criteria.getCriteria().isLifeLineSelected() && criteria.getCriteria().matches(lifeline)) {
1224 return true;
73005152
BH
1225 }
1226 }
1227 }
1228 } finally {
1229 fLock.unlock();
1230 }
1231 return false;
1232 }
1233
1234 /**
13e157b1 1235 * Job to search in trace for given time range.
73005152
BH
1236 */
1237 protected class SearchJob extends Job {
1238
df0b8ff4 1239 /**
a55887ca 1240 * The search event request.
df0b8ff4 1241 */
f26e290b 1242 protected final SearchEventRequest fSearchRequest;
13e157b1 1243
73005152
BH
1244 /**
1245 * Constructor
13e157b1 1246 *
73005152
BH
1247 * @param findCriteria The search criteria
1248 * @param window Time range to search in
3bd46eef 1249 * @since 2.0
73005152
BH
1250 */
1251 public SearchJob(Criteria findCriteria, TmfTimeRange window) {
1252 super(Messages.TmfUml2SDSyncLoader_SearchJobDescrition);
1253 fSearchRequest = new SearchEventRequest(window, TmfDataRequest.ALL_DATA, 1, ITmfDataRequest.ExecutionType.FOREGROUND, findCriteria);
1254 }
1255
73005152
BH
1256 @Override
1257 protected IStatus run(IProgressMonitor monitor) {
1258 fSearchRequest.setMonitor(monitor);
13e157b1 1259
faa38350 1260 fTrace.sendRequest(fSearchRequest);
73005152
BH
1261
1262 try {
1263 fSearchRequest.waitForCompletion();
1264 } catch (InterruptedException e) {
8fd82db5 1265 Activator.getDefault().logError("Search request interrupted!", e); //$NON-NLS-1$
73005152
BH
1266 }
1267
13e157b1
MK
1268 IStatus status = Status.OK_STATUS;
1269 if (fSearchRequest.isFound() && (fSearchRequest.getFoundTime() != null)) {
73005152 1270 fCurrentTime = fSearchRequest.getFoundTime();
13e157b1 1271
73005152
BH
1272 // Avoid double-selection. Selection will be done when calling find(criteria)
1273 // after moving to relevant page
13e157b1 1274 fIsSelect = false;
73005152
BH
1275 if (!fView.getSDWidget().isDisposed()) {
1276 fView.getSDWidget().getDisplay().asyncExec(new Runnable() {
1277
1278 @Override
1279 public void run() {
1280 moveToMessage();
1281 }
1282 });
1283 }
1284 }
1285 else {
1286 if (monitor.isCanceled()) {
1287 status = Status.CANCEL_STATUS;
1288 }
1289 else {
1290 // String was not found
abbdd66a 1291 status = new Status(IStatus.WARNING, Activator.PLUGIN_ID, Messages.TmfUml2SDSyncLoader_SearchNotFound);
73005152
BH
1292 }
1293 setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);
1294 }
1295 monitor.done();
1296
1297 fLock.lock();
1298 try {
1299 fView.toggleWaitCursorAsync(false);
1300 fFindJob = null;
1301 } finally {
1302 fLock.unlock();
1303 }
1304
1305 return status;
1306 }
13e157b1 1307
73005152
BH
1308 @Override
1309 protected void canceling() {
1310 fSearchRequest.cancel();
1311 fLock.lock();
1312 try {
1313 fFindJob = null;
1314 } finally {
1315 fLock.unlock();
1316 }
1317 }
1318 }
1319
1320 /**
13e157b1 1321 * TMF event request for searching within trace.
73005152 1322 */
6256d8ad 1323 protected class SearchEventRequest extends TmfEventRequest {
73005152 1324
df0b8ff4
BH
1325 /**
1326 * The find criteria.
1327 */
f26e290b 1328 private final Criteria fCriteria;
df0b8ff4
BH
1329 /**
1330 * A progress monitor
1331 */
73005152 1332 private IProgressMonitor fMonitor;
df0b8ff4
BH
1333 /**
1334 * Flag to indicate that node was found according the criteria .
1335 */
73005152 1336 private boolean fIsFound = false;
df0b8ff4
BH
1337 /**
1338 * Time stamp of found item.
1339 */
4df4581d 1340 private ITmfTimestamp fFoundTime = null;
73005152
BH
1341
1342 /**
13e157b1 1343 * Constructor
73005152
BH
1344 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1345 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1346 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1347 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...)
1348 * @param criteria The search criteria
1349 */
1350 public SearchEventRequest(TmfTimeRange range, int nbRequested, int blockSize, ExecutionType execType, Criteria criteria) {
1351 this(range, nbRequested, blockSize, execType, criteria, null);
1352 }
1353
1354 /**
1355 * Constructor
1356 * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
13e157b1 1357 * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
73005152
BH
1358 * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1359 * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...)
1360 * @param criteria The search criteria
1361 * @param monitor progress monitor
1362 */
1363 public SearchEventRequest(TmfTimeRange range, int nbRequested, int blockSize, ExecutionType execType, Criteria criteria, IProgressMonitor monitor) {
13e157b1 1364 super(ITmfEvent.class, range, nbRequested, blockSize, execType);
73005152
BH
1365 fCriteria = new Criteria(criteria);
1366 fMonitor = monitor;
1367 }
13e157b1 1368
73005152 1369 @Override
5419a136
AM
1370 public void handleData(ITmfEvent event) {
1371 super.handleData(event);
73005152
BH
1372
1373 if ((fMonitor!= null) && fMonitor.isCanceled()) {
e6ace8bb 1374 super.cancel();
73005152
BH
1375 return;
1376 }
1377
9a43af17 1378 ITmfSyncSequenceDiagramEvent sdEvent = getSequenceDiagramEvent(event);
13e157b1 1379
73005152
BH
1380 if (sdEvent != null) {
1381
1382 if (fCriteria.isLifeLineSelected()) {
1383 if (fCriteria.matches(sdEvent.getSender())) {
4593bd5b 1384 fFoundTime = event.getTimestamp();
73005152
BH
1385 fIsFound = true;
1386 super.cancel();
1387 }
1388
1389 if (fCriteria.matches(sdEvent.getReceiver())) {
4593bd5b 1390 fFoundTime = event.getTimestamp();
73005152
BH
1391 fIsFound = true;
1392 super.cancel();
1393 }
1394 }
1395
eb63f5ff 1396 if (fCriteria.isSyncMessageSelected() && fCriteria.matches(sdEvent.getName())) {
4593bd5b 1397 fFoundTime = event.getTimestamp();
eb63f5ff
BH
1398 fIsFound = true;
1399 super.cancel();
73005152
BH
1400 }
1401 }
1402 }
1403
73005152
BH
1404 /**
1405 * Set progress monitor.
a55887ca
AM
1406 *
1407 * @param monitor The monitor to assign
73005152
BH
1408 */
1409 public void setMonitor(IProgressMonitor monitor) {
1410 fMonitor = monitor;
1411 }
1412
1413 /**
1414 * Check if find criteria was met.
a55887ca 1415 *
73005152
BH
1416 * @return true if find criteria was met.
1417 */
1418 public boolean isFound() {
1419 return fIsFound;
1420 }
1421
1422 /**
df0b8ff4 1423 * Returns timestamp of found time.
a55887ca 1424 *
73005152 1425 * @return timestamp of found time.
3bd46eef 1426 * @since 2.0
73005152 1427 */
4df4581d 1428 public ITmfTimestamp getFoundTime() {
73005152
BH
1429 return fFoundTime;
1430 }
1431 }
1432
3145ec83 1433 /**
a55887ca
AM
1434 * Job class to provide progress monitor feedback.
1435 *
3145ec83
BH
1436 * @version 1.0
1437 * @author Bernd Hufmann
1438 *
1439 */
1440 protected static class IndexingJob extends Job {
1441
4b4a1525
BH
1442 /**
1443 * @param name The job name
1444 */
3145ec83
BH
1445 public IndexingJob(String name) {
1446 super(name);
1447 }
1448
1449 @Override
1450 protected IStatus run(IProgressMonitor monitor) {
1451 while (!monitor.isCanceled()) {
1452 try {
f26e290b 1453 Thread.sleep(INDEXING_THREAD_SLEEP_VALUE);
3145ec83
BH
1454 } catch (InterruptedException e) {
1455 return Status.OK_STATUS;
1456 }
1457 }
1458 monitor.done();
1459 return Status.OK_STATUS;
1460 }
1461 }
1462
a55887ca 1463
73005152 1464 /**
df0b8ff4 1465 * Returns sequence diagram event if details in given event are available else null.
a55887ca 1466 *
73005152
BH
1467 * @param tmfEvent Event to parse for sequence diagram event details
1468 * @return sequence diagram event if details are available else null
9a43af17 1469 * @since 2.0
73005152 1470 */
9a43af17 1471 protected ITmfSyncSequenceDiagramEvent getSequenceDiagramEvent(ITmfEvent tmfEvent){
73005152
BH
1472 //type = .*RECEIVE.* or .*SEND.*
1473 //content = sender:<sender name>:receiver:<receiver name>,signal:<signal name>
1474 String eventType = tmfEvent.getType().toString();
9a43af17
BH
1475 if (eventType.contains(Messages.TmfUml2SDSyncLoader_EventTypeSend) || eventType.contains(Messages.TmfUml2SDSyncLoader_EventTypeReceive)) {
1476 Object sender = tmfEvent.getContent().getField(Messages.TmfUml2SDSyncLoader_FieldSender);
1477 Object receiver = tmfEvent.getContent().getField(Messages.TmfUml2SDSyncLoader_FieldReceiver);
1478 Object name = tmfEvent.getContent().getField(Messages.TmfUml2SDSyncLoader_FieldSignal);
13e157b1 1479 if ((sender instanceof ITmfEventField) && (receiver instanceof ITmfEventField) && (name instanceof ITmfEventField)) {
4c564a2d 1480 ITmfSyncSequenceDiagramEvent sdEvent = new TmfSyncSequenceDiagramEvent(tmfEvent,
13e157b1
MK
1481 ((ITmfEventField) sender).getValue().toString(),
1482 ((ITmfEventField) receiver).getValue().toString(),
1483 ((ITmfEventField) name).getValue().toString());
4c564a2d
FC
1484
1485 return sdEvent;
1486 }
73005152
BH
1487 }
1488 return null;
1489 }
1490}
This page took 0.11748 seconds and 5 git commands to generate.