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