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