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