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