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