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 | } | |
73005152 BH |
537 | fView.setSDFindProvider(null); |
538 | fView.setSDPagingProvider(null); | |
539 | fView.setSDFilterProvider(null); | |
540 | fView = null; | |
541 | } finally { | |
542 | fLock.unlock(); | |
543 | } | |
544 | } | |
545 | ||
546 | /* | |
547 | * (non-Javadoc) | |
548 | * @see org.eclipse.hyades.uml2sd.ui.actions.provider.ISDGraphNodeSupporter#isNodeSupported(int) | |
549 | */ | |
550 | @Override | |
551 | public boolean isNodeSupported(int nodeType) { | |
552 | switch (nodeType) { | |
553 | case ISDGraphNodeSupporter.LIFELINE: | |
554 | case ISDGraphNodeSupporter.SYNCMESSAGE: | |
555 | return true; | |
556 | ||
557 | default: | |
558 | break; | |
559 | } | |
560 | return false; | |
561 | } | |
562 | ||
563 | /* | |
564 | * (non-Javadoc) | |
565 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter#getNodeName(int, java.lang.String) | |
566 | */ | |
567 | @Override | |
568 | public String getNodeName(int nodeType, String loaderClassName) { | |
569 | switch (nodeType) { | |
570 | case ISDGraphNodeSupporter.LIFELINE: | |
571 | return Messages.TmfUml2SDSyncLoader_CategoryLifeline; | |
572 | case ISDGraphNodeSupporter.SYNCMESSAGE: | |
573 | return Messages.TmfUml2SDSyncLoader_CategoryMessage; | |
abbdd66a AM |
574 | default: |
575 | break; | |
73005152 BH |
576 | } |
577 | return ""; //$NON-NLS-1$ | |
578 | } | |
579 | ||
580 | /* | |
581 | * (non-Javadoc) | |
582 | * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) | |
583 | */ | |
584 | @Override | |
585 | public void selectionChanged(IWorkbenchPart part, ISelection selection) { | |
586 | ISelection sel = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection(); | |
13e157b1 | 587 | if ((sel != null) && (sel instanceof StructuredSelection)) { |
73005152 BH |
588 | StructuredSelection stSel = (StructuredSelection) sel; |
589 | if (stSel.getFirstElement() instanceof TmfSyncMessage) { | |
590 | TmfSyncMessage syncMsg = ((TmfSyncMessage) stSel.getFirstElement()); | |
591 | broadcast(new TmfTimeSynchSignal(this, syncMsg.getStartTime())); | |
592 | } | |
593 | } | |
594 | } | |
595 | ||
596 | /* | |
597 | * (non-Javadoc) | |
598 | * @see | |
599 | * org.eclipse.hyades.uml2sd.ui.actions.provider.ISDFindProvider#find(org.eclipse.hyades.uml2sd.ui.actions.widgets.Criteria) | |
600 | */ | |
601 | @Override | |
602 | public boolean find(Criteria toSearch) { | |
603 | fLock.lock(); | |
604 | try { | |
605 | if (fFrame == null) { | |
606 | return false; | |
607 | } | |
608 | ||
13e157b1 | 609 | if ((fFindResults == null) || (fFindCriteria == null) || !fFindCriteria.compareTo(toSearch)) { |
73005152 BH |
610 | fFindResults = new CopyOnWriteArrayList<GraphNode>(); |
611 | fFindCriteria = toSearch; | |
612 | if (fFindCriteria.isLifeLineSelected()) { | |
613 | for (int i = 0; i < fFrame.lifeLinesCount(); i++) { | |
614 | if (fFindCriteria.matches(fFrame.getLifeline(i).getName())) { | |
615 | fFindResults.add(fFrame.getLifeline(i)); | |
616 | } | |
617 | } | |
618 | } | |
619 | ||
620 | ArrayList<GraphNode> msgs = new ArrayList<GraphNode>(); | |
621 | if (fFindCriteria.isSyncMessageSelected()) { | |
622 | for (int i = 0; i < fFrame.syncMessageCount(); i++) { | |
623 | if (fFindCriteria.matches(fFrame.getSyncMessage(i).getName())) { | |
624 | msgs.add(fFrame.getSyncMessage(i)); | |
625 | } | |
626 | } | |
627 | } | |
628 | ||
eb63f5ff | 629 | if (!msgs.isEmpty()) { |
73005152 BH |
630 | fFindResults.addAll(msgs); |
631 | } | |
632 | ||
633 | @SuppressWarnings("rawtypes") | |
634 | List selection = fView.getSDWidget().getSelection(); | |
13e157b1 | 635 | if ((selection != null) && (selection.size() == 1)) { |
73005152 | 636 | fCurrentFindIndex = fFindResults.indexOf(selection.get(0)) + 1; |
13e157b1 | 637 | } else { |
73005152 | 638 | fCurrentFindIndex = 0; |
13e157b1 | 639 | } |
73005152 BH |
640 | } else { |
641 | fCurrentFindIndex++; | |
642 | } | |
643 | ||
644 | if (fFindResults.size() > fCurrentFindIndex) { | |
13e157b1 | 645 | GraphNode current = fFindResults.get(fCurrentFindIndex); |
73005152 BH |
646 | fView.getSDWidget().moveTo(current); |
647 | return true; | |
73005152 | 648 | } |
abbdd66a AM |
649 | fFindResults = null; |
650 | fCurrentFindIndex =0; | |
651 | return findInNextPages(fFindCriteria); // search in other page | |
73005152 BH |
652 | } finally { |
653 | fLock.unlock(); | |
654 | } | |
655 | } | |
656 | ||
657 | /* | |
658 | * (non-Javadoc) | |
659 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFindProvider#cancel() | |
660 | */ | |
661 | @Override | |
662 | public void cancel() { | |
663 | cancelOngoingRequests(); | |
664 | } | |
665 | ||
666 | /* | |
667 | * (non-Javadoc) | |
668 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFilterProvider#filter(java.util.List) | |
669 | */ | |
670 | @SuppressWarnings("unchecked") | |
671 | @Override | |
672 | public boolean filter(List<?> filters) { | |
673 | fLock.lock(); | |
674 | try { | |
675 | cancelOngoingRequests(); | |
676 | ||
1ef1189a BH |
677 | if (filters == null) { |
678 | fFilterCriteria = new ArrayList<FilterCriteria>(); | |
679 | } else { | |
680 | List<FilterCriteria> list = (List<FilterCriteria>)filters; | |
681 | fFilterCriteria = new ArrayList<FilterCriteria>(list); | |
682 | } | |
73005152 BH |
683 | |
684 | fillCurrentPage(fEvents); | |
685 | ||
686 | } finally { | |
687 | fLock.unlock(); | |
688 | } | |
689 | return true; | |
690 | } | |
13e157b1 | 691 | |
73005152 BH |
692 | /* |
693 | * (non-Javadoc) | |
694 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasNextPage() | |
695 | */ | |
696 | @Override | |
697 | public boolean hasNextPage() { | |
698 | fLock.lock(); | |
699 | try { | |
700 | int size = fCheckPoints.size(); | |
701 | if (size > 0) { | |
13e157b1 | 702 | return fCurrentPage < (size - 1); |
73005152 BH |
703 | } |
704 | } finally { | |
705 | fLock.unlock(); | |
706 | } | |
707 | return false; | |
708 | } | |
709 | ||
710 | /* | |
711 | * (non-Javadoc) | |
712 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasPrevPage() | |
713 | */ | |
714 | @Override | |
715 | public boolean hasPrevPage() { | |
716 | fLock.lock(); | |
717 | try { | |
718 | return fCurrentPage > 0; | |
719 | } finally { | |
720 | fLock.unlock(); | |
721 | } | |
722 | } | |
723 | ||
724 | /* | |
725 | * (non-Javadoc) | |
726 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#nextPage() | |
727 | */ | |
728 | @Override | |
729 | public void nextPage() { | |
730 | fLock.lock(); | |
731 | try { | |
732 | // Safety check | |
13e157b1 | 733 | if (fCurrentPage >= (fCheckPoints.size() - 1)) { |
73005152 | 734 | return; |
13e157b1 | 735 | } |
73005152 BH |
736 | |
737 | cancelOngoingRequests(); | |
738 | fCurrentTime = null; | |
739 | fCurrentPage++; | |
740 | moveToPage(); | |
741 | } finally { | |
742 | fLock.unlock(); | |
743 | } | |
744 | } | |
745 | ||
746 | /* | |
747 | * (non-Javadoc) | |
748 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#prevPage() | |
749 | */ | |
750 | @Override | |
751 | public void prevPage() { | |
752 | fLock.lock(); | |
753 | try { | |
754 | // Safety check | |
13e157b1 | 755 | if (fCurrentPage <= 0) { |
73005152 | 756 | return; |
13e157b1 | 757 | } |
73005152 BH |
758 | |
759 | cancelOngoingRequests(); | |
760 | fCurrentTime = null; | |
761 | fCurrentPage--; | |
762 | moveToPage(); | |
763 | } finally { | |
764 | fLock.unlock(); | |
765 | } | |
766 | } | |
13e157b1 | 767 | |
73005152 BH |
768 | /* |
769 | * (non-Javadoc) | |
770 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#firstPage() | |
771 | */ | |
772 | @Override | |
773 | public void firstPage() { | |
774 | fLock.lock(); | |
775 | try { | |
776 | ||
777 | cancelOngoingRequests(); | |
778 | fCurrentTime = null; | |
779 | fCurrentPage = 0; | |
780 | moveToPage(); | |
781 | } finally { | |
782 | fLock.unlock(); | |
783 | } | |
784 | } | |
13e157b1 | 785 | |
73005152 BH |
786 | /* |
787 | * (non-Javadoc) | |
788 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#lastPage() | |
789 | */ | |
790 | @Override | |
791 | public void lastPage() { | |
792 | fLock.lock(); | |
793 | try { | |
794 | cancelOngoingRequests(); | |
795 | fCurrentTime = null; | |
796 | fCurrentPage = fCheckPoints.size() - 1; | |
797 | moveToPage(); | |
798 | } finally { | |
799 | fLock.unlock(); | |
800 | } | |
801 | } | |
802 | ||
803 | /* | |
804 | * (non-Javadoc) | |
805 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#currentPage() | |
806 | */ | |
807 | @Override | |
808 | public int currentPage() { | |
809 | fLock.lock(); | |
810 | try { | |
811 | return fCurrentPage; | |
812 | } finally { | |
813 | fLock.unlock(); | |
814 | } | |
815 | } | |
816 | ||
817 | /* | |
818 | * (non-Javadoc) | |
819 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pagesCount() | |
820 | */ | |
821 | @Override | |
822 | public int pagesCount() { | |
823 | fLock.lock(); | |
824 | try { | |
825 | return fCheckPoints.size(); | |
826 | } finally { | |
827 | fLock.unlock(); | |
828 | } | |
829 | } | |
830 | ||
831 | /* | |
832 | * (non-Javadoc) | |
833 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pageNumberChanged(int) | |
834 | */ | |
835 | @Override | |
eb63f5ff BH |
836 | public void pageNumberChanged(int pagenNumber) { |
837 | int localPageNumber = pagenNumber; | |
a55887ca | 838 | |
73005152 BH |
839 | fLock.lock(); |
840 | try { | |
841 | cancelOngoingRequests(); | |
842 | ||
eb63f5ff BH |
843 | if (localPageNumber < 0) { |
844 | localPageNumber = 0; | |
73005152 BH |
845 | } |
846 | int size = fCheckPoints.size(); | |
eb63f5ff BH |
847 | if (localPageNumber > (size - 1)) { |
848 | localPageNumber = size - 1; | |
73005152 | 849 | } |
eb63f5ff | 850 | fCurrentPage = localPageNumber; |
73005152 BH |
851 | moveToPage(); |
852 | } finally { | |
853 | fLock.unlock(); | |
854 | } | |
855 | } | |
856 | ||
857 | /* | |
858 | * (non-Javadoc) | |
859 | * @see org.eclipse.linuxtools.tmf.component.TmfComponent#broadcast(org.eclipse.linuxtools.tmf.signal.TmfSignal) | |
860 | */ | |
861 | @Override | |
862 | public void broadcast(TmfSignal signal) { | |
863 | fIsSignalSent = true; | |
864 | super.broadcast(signal); | |
865 | fIsSignalSent = false; | |
866 | } | |
867 | ||
868 | /** | |
869 | * Cancels any ongoing find operation | |
870 | */ | |
871 | protected void cancelOngoingRequests() { | |
13e157b1 | 872 | fLock.lock(); |
73005152 BH |
873 | try { |
874 | // Cancel the search thread | |
875 | if (fFindJob != null) { | |
876 | fFindJob.cancel(); | |
877 | } | |
df0b8ff4 | 878 | |
73005152 BH |
879 | fFindResults = null; |
880 | fFindCriteria = null; | |
881 | fCurrentFindIndex = 0; | |
882 | ||
faa38350 PT |
883 | if (fPageRequest != null) { |
884 | if (!fPageRequest.isCompleted()) { | |
885 | fPageRequest.cancel(); | |
886 | } | |
73005152 | 887 | fPageRequest = null; |
13e157b1 | 888 | } |
73005152 BH |
889 | } finally { |
890 | fLock.unlock(); | |
891 | } | |
892 | } | |
893 | ||
894 | /** | |
895 | * Resets loader attributes | |
896 | */ | |
897 | protected void resetLoader() { | |
898 | fLock.lock(); | |
899 | try { | |
900 | fCurrentTime = null; | |
901 | fEvents.clear(); | |
902 | fCheckPoints.clear(); | |
903 | fCurrentPage = 0; | |
904 | fCurrentFindIndex = 0; | |
905 | fFindCriteria = null; | |
906 | fFindResults = null; | |
907 | fInitialWindow = INITIAL_WINDOW_OFFSET; | |
908 | fView.setFrameSync(new Frame()); | |
909 | fFrame = null; | |
910 | } | |
911 | finally { | |
912 | fLock.unlock(); | |
913 | } | |
914 | ||
915 | } | |
916 | ||
917 | /** | |
918 | * Fills current page with sequence diagram content. | |
a55887ca | 919 | * |
73005152 BH |
920 | * @param events sequence diagram events |
921 | */ | |
922 | protected void fillCurrentPage(List<ITmfSyncSequenceDiagramEvent> events) { | |
923 | ||
924 | fLock.lock(); | |
925 | try { | |
926 | fEvents = new ArrayList<ITmfSyncSequenceDiagramEvent>(events); | |
faa38350 | 927 | if (fView != null && !events.isEmpty()) { |
73005152 BH |
928 | fView.toggleWaitCursorAsync(true); |
929 | } | |
930 | } finally { | |
931 | fLock.unlock(); | |
932 | } | |
13e157b1 | 933 | |
73005152 | 934 | final Frame frame = new Frame(); |
73005152 | 935 | |
eb63f5ff BH |
936 | if (!events.isEmpty()) { |
937 | Map<String, Lifeline> nodeToLifelineMap = new HashMap<String, Lifeline>(); | |
73005152 BH |
938 | |
939 | frame.setName(Messages.TmfUml2SDSyncLoader_FrameName); | |
940 | ||
941 | for (int i = 0; i < events.size(); i++) { | |
942 | ||
943 | ITmfSyncSequenceDiagramEvent sdEvent = events.get(i); | |
944 | ||
945 | if ((nodeToLifelineMap.get(sdEvent.getSender()) == null) && (!filterLifeLine(sdEvent.getSender()))) { | |
946 | Lifeline lifeline = new Lifeline(); | |
947 | lifeline.setName(sdEvent.getSender()); | |
948 | nodeToLifelineMap.put(sdEvent.getSender(), lifeline); | |
949 | frame.addLifeLine(lifeline); | |
950 | } | |
951 | ||
952 | if ((nodeToLifelineMap.get(sdEvent.getReceiver()) == null) && (!filterLifeLine(sdEvent.getReceiver()))) { | |
953 | Lifeline lifeline = new Lifeline(); | |
954 | lifeline.setName(sdEvent.getReceiver()); | |
955 | nodeToLifelineMap.put(sdEvent.getReceiver(), lifeline); | |
956 | frame.addLifeLine(lifeline); | |
957 | } | |
958 | } | |
959 | ||
960 | int eventOccurence = 1; | |
961 | ||
962 | for (int i = 0; i < events.size(); i++) { | |
13e157b1 | 963 | ITmfSyncSequenceDiagramEvent sdEvent = events.get(i); |
73005152 BH |
964 | |
965 | // Check message filter | |
966 | if (filterMessage(sdEvent)) { | |
967 | continue; | |
968 | } | |
969 | ||
970 | // Set the message sender and receiver | |
13e157b1 MK |
971 | Lifeline startLifeline = nodeToLifelineMap.get(sdEvent.getSender()); |
972 | Lifeline endLifeline = nodeToLifelineMap.get(sdEvent.getReceiver()); | |
73005152 | 973 | |
13e157b1 MK |
974 | // Check if any of the lifelines were filtered |
975 | if ((startLifeline == null) || (endLifeline == null)) { | |
73005152 BH |
976 | continue; |
977 | } | |
978 | ||
979 | int tmp = Math.max(startLifeline.getEventOccurrence(), endLifeline.getEventOccurrence()); | |
980 | eventOccurence = Math.max(eventOccurence, tmp); | |
13e157b1 | 981 | |
73005152 BH |
982 | startLifeline.setCurrentEventOccurrence(eventOccurence); |
983 | endLifeline.setCurrentEventOccurrence(eventOccurence); | |
13e157b1 | 984 | |
73005152 | 985 | TmfSyncMessage message = new TmfSyncMessage(sdEvent, eventOccurence++); |
13e157b1 | 986 | |
73005152 BH |
987 | message.setStartLifeline(startLifeline); |
988 | message.setEndLifeline(endLifeline); | |
989 | ||
990 | message.setTime(sdEvent.getStartTime()); | |
991 | ||
992 | // add the message to the frame | |
993 | frame.addMessage(message); | |
13e157b1 | 994 | |
73005152 BH |
995 | } |
996 | fLock.lock(); | |
997 | try { | |
998 | if (!fView.getSDWidget().isDisposed()) { | |
999 | fView.getSDWidget().getDisplay().asyncExec(new Runnable() { | |
1000 | ||
1001 | @Override | |
1002 | public void run() { | |
1003 | ||
1004 | fLock.lock(); | |
1005 | try { | |
1006 | // check if view was disposed in the meanwhile | |
1007 | if ((fView != null) && (!fView.getSDWidget().isDisposed())) { | |
1008 | fFrame = frame; | |
1009 | fView.setFrame(fFrame); | |
1010 | ||
1011 | if (fCurrentTime != null) { | |
1012 | moveToMessageInPage(); | |
1013 | } | |
1014 | ||
1015 | if (fFindCriteria != null) { | |
1016 | find(fFindCriteria); | |
1017 | } | |
13e157b1 | 1018 | |
73005152 BH |
1019 | fView.toggleWaitCursorAsync(false); |
1020 | } | |
1021 | } finally { | |
1022 | fLock.unlock(); | |
1023 | } | |
1024 | ||
1025 | } | |
1026 | }); | |
1027 | } | |
1028 | } | |
1029 | finally { | |
1030 | fLock.unlock(); | |
1031 | } | |
1032 | } | |
1033 | } | |
1034 | ||
1035 | /** | |
1036 | * Moves to a certain message defined by timestamp (across pages) | |
1037 | */ | |
1038 | protected void moveToMessage() { | |
1039 | int page = 0; | |
1040 | ||
1041 | fLock.lock(); | |
1042 | try { | |
1043 | page = getPage(fCurrentTime); | |
1044 | ||
1045 | if (page == fCurrentPage) { | |
1046 | moveToMessageInPage(); | |
1047 | return; | |
1048 | } | |
1049 | fCurrentPage = page; | |
1050 | moveToPage(false); | |
1051 | } finally { | |
1052 | fLock.unlock(); | |
1053 | } | |
1054 | } | |
1055 | ||
1056 | /** | |
1057 | * Moves to a certain message defined by timestamp in current page | |
1058 | */ | |
1059 | protected void moveToMessageInPage() { | |
1060 | fLock.lock(); | |
1061 | try { | |
de7ddc02 BH |
1062 | if (!fView.getSDWidget().isDisposed()) { |
1063 | // Check for GUI thread | |
1064 | if(Display.getCurrent() != null) { | |
1065 | // Already in GUI thread - execute directly | |
1066 | TmfSyncMessage prevMessage = null; | |
1067 | TmfSyncMessage syncMessage = null; | |
1068 | boolean isExactTime = false; | |
1069 | for (int i = 0; i < fFrame.syncMessageCount(); i++) { | |
1070 | if (fFrame.getSyncMessage(i) instanceof TmfSyncMessage) { | |
1071 | syncMessage = (TmfSyncMessage) fFrame.getSyncMessage(i); | |
1072 | if (syncMessage.getStartTime().compareTo(fCurrentTime, false) == 0) { | |
1073 | isExactTime = true; | |
1074 | break; | |
eb63f5ff BH |
1075 | } else if ((syncMessage.getStartTime().compareTo(fCurrentTime, false) > 0) && (prevMessage != null)) { |
1076 | syncMessage = prevMessage; | |
1077 | break; | |
de7ddc02 BH |
1078 | } |
1079 | prevMessage = syncMessage; | |
1080 | } | |
1081 | } | |
1082 | if (fIsSelect && isExactTime) { | |
1083 | fView.getSDWidget().moveTo(syncMessage); | |
1084 | } | |
1085 | else { | |
1086 | fView.getSDWidget().ensureVisible(syncMessage); | |
1087 | fView.getSDWidget().clearSelection(); | |
1088 | fView.getSDWidget().redraw(); | |
1089 | } | |
1090 | } | |
1091 | else { | |
13e157b1 | 1092 | // Not in GUI thread - queue action in GUI thread. |
de7ddc02 BH |
1093 | fView.getSDWidget().getDisplay().asyncExec(new Runnable() { |
1094 | @Override | |
1095 | public void run() { | |
1096 | moveToMessageInPage(); | |
1097 | } | |
1098 | }); | |
1099 | } | |
1100 | } | |
73005152 BH |
1101 | } |
1102 | finally { | |
1103 | fLock.unlock(); | |
1104 | } | |
1105 | } | |
13e157b1 | 1106 | |
73005152 BH |
1107 | /** |
1108 | * Moves to a certain message defined by timestamp (across pages) | |
1109 | */ | |
1110 | protected void moveToPage() { | |
1111 | moveToPage(true); | |
1112 | } | |
1113 | ||
1114 | /** | |
1115 | * Moves to a certain page. | |
a55887ca | 1116 | * |
73005152 BH |
1117 | * @param notifyAll true to broadcast time range signal to other signal handlers else false |
1118 | */ | |
1119 | protected void moveToPage(boolean notifyAll) { | |
1120 | ||
eb63f5ff | 1121 | TmfTimeRange window = null; |
73005152 BH |
1122 | |
1123 | fLock.lock(); | |
1124 | try { | |
1125 | // Safety check | |
1126 | if (fCurrentPage > fCheckPoints.size()) { | |
1127 | return; | |
1128 | } | |
1129 | window = fCheckPoints.get(fCurrentPage); | |
1130 | } finally { | |
1131 | fLock.unlock(); | |
1132 | } | |
1133 | ||
eb63f5ff BH |
1134 | if (window == null) { |
1135 | window = TmfTimeRange.ETERNITY; | |
1136 | } | |
1137 | ||
6256d8ad | 1138 | fPageRequest = new TmfEventRequest(ITmfEvent.class, window, TmfDataRequest.ALL_DATA, 1, ITmfDataRequest.ExecutionType.FOREGROUND) { |
13e157b1 | 1139 | private final List<ITmfSyncSequenceDiagramEvent> fSdEvent = new ArrayList<ITmfSyncSequenceDiagramEvent>(); |
73005152 BH |
1140 | |
1141 | @Override | |
13e157b1 | 1142 | public void handleData(ITmfEvent event) { |
73005152 BH |
1143 | super.handleData(event); |
1144 | ||
1145 | ITmfSyncSequenceDiagramEvent sdEvent = getSequnceDiagramEvent(event); | |
1146 | ||
1147 | if (sdEvent != null) { | |
1148 | fSdEvent.add(sdEvent); | |
1149 | } | |
1150 | } | |
1151 | ||
1152 | @Override | |
1153 | public void handleSuccess() { | |
1154 | fillCurrentPage(fSdEvent); | |
1155 | super.handleSuccess(); | |
1156 | } | |
13e157b1 | 1157 | |
73005152 BH |
1158 | }; |
1159 | ||
faa38350 | 1160 | fTrace.sendRequest(fPageRequest); |
73005152 BH |
1161 | |
1162 | if (notifyAll) { | |
1163 | TmfTimeRange timeRange = getSignalTimeRange(window.getStartTime()); | |
1164 | broadcast(new TmfRangeSynchSignal(this, timeRange, timeRange.getStartTime())); | |
1165 | } | |
1166 | } | |
1167 | ||
1168 | /** | |
1169 | * Gets page that contains timestamp | |
a55887ca | 1170 | * |
73005152 BH |
1171 | * @param time The timestamp |
1172 | * @return page that contains the time | |
1173 | */ | |
4df4581d | 1174 | protected int getPage(ITmfTimestamp time) { |
73005152 BH |
1175 | int page; |
1176 | int size; | |
1177 | fLock.lock(); | |
1178 | try { | |
1179 | size = fCheckPoints.size(); | |
13e157b1 | 1180 | for (page = 0; page < size; page++) { |
73005152 BH |
1181 | TmfTimeRange timeRange = fCheckPoints.get(page); |
1182 | if (timeRange.getEndTime().compareTo(time, false) >= 0) { | |
1183 | break; | |
1184 | } | |
1185 | } | |
1186 | if (page >= size) { | |
1187 | page = size - 1; | |
1188 | } | |
1189 | return page; | |
1190 | } finally { | |
1191 | fLock.unlock(); | |
1192 | } | |
1193 | } | |
13e157b1 | 1194 | |
73005152 BH |
1195 | /** |
1196 | * Background search in trace for expression in criteria. | |
a55887ca | 1197 | * |
73005152 BH |
1198 | * @param findCriteria The find criteria |
1199 | * @return true if background request was started else false | |
1200 | */ | |
1201 | protected boolean findInNextPages(Criteria findCriteria) { | |
1202 | fLock.lock(); | |
1203 | try { | |
1204 | if (fFindJob != null) { | |
1205 | return true; | |
1206 | } | |
1207 | ||
1208 | int nextPage = fCurrentPage + 1; | |
1209 | ||
1210 | if ((nextPage) >= fCheckPoints.size()) { | |
1211 | // we are at the end | |
1212 | return false; | |
1213 | } | |
1214 | ||
4593bd5b | 1215 | TmfTimeRange window = new TmfTimeRange(fCheckPoints.get(nextPage).getStartTime(), fCheckPoints.get(fCheckPoints.size()-1).getEndTime()); |
73005152 BH |
1216 | fFindJob = new SearchJob(findCriteria, window); |
1217 | fFindJob.schedule(); | |
1218 | fView.toggleWaitCursorAsync(true); | |
1219 | } finally { | |
1220 | fLock.unlock(); | |
1221 | } | |
1222 | return true; | |
1223 | } | |
1224 | ||
1225 | /** | |
1226 | * Gets time range for time range signal. | |
a55887ca | 1227 | * |
73005152 | 1228 | * @param startTime The start time of time range. |
0d9a6d76 | 1229 | * @return the time range |
73005152 | 1230 | */ |
4df4581d | 1231 | protected TmfTimeRange getSignalTimeRange(ITmfTimestamp startTime) { |
73005152 BH |
1232 | fLock.lock(); |
1233 | try { | |
1234 | TmfTimestamp initialEndOfWindow = new TmfTimestamp(startTime.getValue() + fInitialWindow, startTime.getScale(), startTime.getPrecision()); | |
1235 | return new TmfTimeRange(startTime, initialEndOfWindow); | |
1236 | } | |
1237 | finally { | |
1238 | fLock.unlock(); | |
1239 | } | |
1240 | } | |
1241 | ||
1242 | /** | |
13e157b1 | 1243 | * Checks if filter criteria matches the message name in given SD event. |
a55887ca | 1244 | * |
73005152 BH |
1245 | * @param sdEvent The SD event to check |
1246 | * @return true if match else false. | |
1247 | */ | |
1248 | protected boolean filterMessage(ITmfSyncSequenceDiagramEvent sdEvent) { | |
1249 | fLock.lock(); | |
1250 | try { | |
1251 | if (fFilterCriteria != null) { | |
1252 | for(FilterCriteria criteria : fFilterCriteria) { | |
eb63f5ff BH |
1253 | if (criteria.isActive() && criteria.getCriteria().isSyncMessageSelected() && criteria.getCriteria().matches(sdEvent.getName())) { |
1254 | return true; | |
73005152 BH |
1255 | } |
1256 | } | |
1257 | } | |
1258 | } finally { | |
1259 | fLock.unlock(); | |
1260 | } | |
1261 | return false; | |
1262 | } | |
1263 | ||
1264 | /** | |
13e157b1 | 1265 | * Checks if filter criteria matches a lifeline name (sender or receiver) in given SD event. |
a55887ca | 1266 | * |
0d9a6d76 | 1267 | * @param lifeline the message receiver |
73005152 BH |
1268 | * @return true if match else false. |
1269 | */ | |
1270 | protected boolean filterLifeLine(String lifeline) { | |
1271 | fLock.lock(); | |
1272 | try { | |
1273 | if (fFilterCriteria != null) { | |
1274 | for(FilterCriteria criteria : fFilterCriteria) { | |
eb63f5ff BH |
1275 | if (criteria.isActive() && criteria.getCriteria().isLifeLineSelected() && criteria.getCriteria().matches(lifeline)) { |
1276 | return true; | |
73005152 BH |
1277 | } |
1278 | } | |
1279 | } | |
1280 | } finally { | |
1281 | fLock.unlock(); | |
1282 | } | |
1283 | return false; | |
1284 | } | |
1285 | ||
1286 | /** | |
13e157b1 | 1287 | * Job to search in trace for given time range. |
73005152 BH |
1288 | */ |
1289 | protected class SearchJob extends Job { | |
1290 | ||
df0b8ff4 | 1291 | /** |
a55887ca | 1292 | * The search event request. |
df0b8ff4 | 1293 | */ |
73005152 | 1294 | final protected SearchEventRequest fSearchRequest; |
13e157b1 | 1295 | |
73005152 BH |
1296 | /** |
1297 | * Constructor | |
13e157b1 | 1298 | * |
73005152 BH |
1299 | * @param findCriteria The search criteria |
1300 | * @param window Time range to search in | |
1301 | */ | |
1302 | public SearchJob(Criteria findCriteria, TmfTimeRange window) { | |
1303 | super(Messages.TmfUml2SDSyncLoader_SearchJobDescrition); | |
1304 | fSearchRequest = new SearchEventRequest(window, TmfDataRequest.ALL_DATA, 1, ITmfDataRequest.ExecutionType.FOREGROUND, findCriteria); | |
1305 | } | |
1306 | ||
1307 | /* | |
1308 | * (non-Javadoc) | |
1309 | * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) | |
1310 | */ | |
1311 | @Override | |
1312 | protected IStatus run(IProgressMonitor monitor) { | |
1313 | fSearchRequest.setMonitor(monitor); | |
13e157b1 | 1314 | |
faa38350 | 1315 | fTrace.sendRequest(fSearchRequest); |
73005152 BH |
1316 | |
1317 | try { | |
1318 | fSearchRequest.waitForCompletion(); | |
1319 | } catch (InterruptedException e) { | |
8fd82db5 | 1320 | Activator.getDefault().logError("Search request interrupted!", e); //$NON-NLS-1$ |
73005152 BH |
1321 | } |
1322 | ||
13e157b1 MK |
1323 | IStatus status = Status.OK_STATUS; |
1324 | if (fSearchRequest.isFound() && (fSearchRequest.getFoundTime() != null)) { | |
73005152 | 1325 | fCurrentTime = fSearchRequest.getFoundTime(); |
13e157b1 | 1326 | |
73005152 BH |
1327 | // Avoid double-selection. Selection will be done when calling find(criteria) |
1328 | // after moving to relevant page | |
13e157b1 | 1329 | fIsSelect = false; |
73005152 BH |
1330 | if (!fView.getSDWidget().isDisposed()) { |
1331 | fView.getSDWidget().getDisplay().asyncExec(new Runnable() { | |
1332 | ||
1333 | @Override | |
1334 | public void run() { | |
1335 | moveToMessage(); | |
1336 | } | |
1337 | }); | |
1338 | } | |
1339 | } | |
1340 | else { | |
1341 | if (monitor.isCanceled()) { | |
1342 | status = Status.CANCEL_STATUS; | |
1343 | } | |
1344 | else { | |
1345 | // String was not found | |
abbdd66a | 1346 | status = new Status(IStatus.WARNING, Activator.PLUGIN_ID, Messages.TmfUml2SDSyncLoader_SearchNotFound); |
73005152 BH |
1347 | } |
1348 | setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE); | |
1349 | } | |
1350 | monitor.done(); | |
1351 | ||
1352 | fLock.lock(); | |
1353 | try { | |
1354 | fView.toggleWaitCursorAsync(false); | |
1355 | fFindJob = null; | |
1356 | } finally { | |
1357 | fLock.unlock(); | |
1358 | } | |
1359 | ||
1360 | return status; | |
1361 | } | |
13e157b1 | 1362 | |
73005152 BH |
1363 | /* |
1364 | * (non-Javadoc) | |
1365 | * @see org.eclipse.core.runtime.jobs.Job#canceling() | |
1366 | */ | |
1367 | @Override | |
1368 | protected void canceling() { | |
1369 | fSearchRequest.cancel(); | |
1370 | fLock.lock(); | |
1371 | try { | |
1372 | fFindJob = null; | |
1373 | } finally { | |
1374 | fLock.unlock(); | |
1375 | } | |
1376 | } | |
1377 | } | |
1378 | ||
1379 | /** | |
13e157b1 | 1380 | * TMF event request for searching within trace. |
73005152 | 1381 | */ |
6256d8ad | 1382 | protected class SearchEventRequest extends TmfEventRequest { |
73005152 | 1383 | |
df0b8ff4 BH |
1384 | /** |
1385 | * The find criteria. | |
1386 | */ | |
73005152 | 1387 | final private Criteria fCriteria; |
df0b8ff4 BH |
1388 | /** |
1389 | * A progress monitor | |
1390 | */ | |
73005152 | 1391 | private IProgressMonitor fMonitor; |
df0b8ff4 BH |
1392 | /** |
1393 | * Flag to indicate that node was found according the criteria . | |
1394 | */ | |
73005152 | 1395 | private boolean fIsFound = false; |
df0b8ff4 BH |
1396 | /** |
1397 | * Time stamp of found item. | |
1398 | */ | |
4df4581d | 1399 | private ITmfTimestamp fFoundTime = null; |
73005152 BH |
1400 | |
1401 | /** | |
13e157b1 | 1402 | * Constructor |
73005152 BH |
1403 | * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...) |
1404 | * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...) | |
1405 | * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...) | |
1406 | * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...) | |
1407 | * @param criteria The search criteria | |
1408 | */ | |
1409 | public SearchEventRequest(TmfTimeRange range, int nbRequested, int blockSize, ExecutionType execType, Criteria criteria) { | |
1410 | this(range, nbRequested, blockSize, execType, criteria, null); | |
1411 | } | |
1412 | ||
1413 | /** | |
1414 | * Constructor | |
1415 | * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...) | |
13e157b1 | 1416 | * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...) |
73005152 BH |
1417 | * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...) |
1418 | * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...) | |
1419 | * @param criteria The search criteria | |
1420 | * @param monitor progress monitor | |
1421 | */ | |
1422 | public SearchEventRequest(TmfTimeRange range, int nbRequested, int blockSize, ExecutionType execType, Criteria criteria, IProgressMonitor monitor) { | |
13e157b1 | 1423 | super(ITmfEvent.class, range, nbRequested, blockSize, execType); |
73005152 BH |
1424 | fCriteria = new Criteria(criteria); |
1425 | fMonitor = monitor; | |
1426 | } | |
13e157b1 | 1427 | |
73005152 BH |
1428 | /* |
1429 | * (non-Javadoc) | |
1430 | * @see org.eclipse.linuxtools.tmf.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.event.TmfData) | |
1431 | */ | |
1432 | @Override | |
13e157b1 | 1433 | public void handleData(ITmfEvent event) { |
73005152 BH |
1434 | super.handleData(event); |
1435 | ||
1436 | if ((fMonitor!= null) && fMonitor.isCanceled()) { | |
e6ace8bb | 1437 | super.cancel(); |
73005152 BH |
1438 | return; |
1439 | } | |
1440 | ||
1441 | ITmfSyncSequenceDiagramEvent sdEvent = getSequnceDiagramEvent(event); | |
13e157b1 | 1442 | |
73005152 BH |
1443 | if (sdEvent != null) { |
1444 | ||
1445 | if (fCriteria.isLifeLineSelected()) { | |
1446 | if (fCriteria.matches(sdEvent.getSender())) { | |
4593bd5b | 1447 | fFoundTime = event.getTimestamp(); |
73005152 BH |
1448 | fIsFound = true; |
1449 | super.cancel(); | |
1450 | } | |
1451 | ||
1452 | if (fCriteria.matches(sdEvent.getReceiver())) { | |
4593bd5b | 1453 | fFoundTime = event.getTimestamp(); |
73005152 BH |
1454 | fIsFound = true; |
1455 | super.cancel(); | |
1456 | } | |
1457 | } | |
1458 | ||
eb63f5ff | 1459 | if (fCriteria.isSyncMessageSelected() && fCriteria.matches(sdEvent.getName())) { |
4593bd5b | 1460 | fFoundTime = event.getTimestamp(); |
eb63f5ff BH |
1461 | fIsFound = true; |
1462 | super.cancel(); | |
73005152 BH |
1463 | } |
1464 | } | |
1465 | } | |
1466 | ||
73005152 BH |
1467 | /** |
1468 | * Set progress monitor. | |
a55887ca AM |
1469 | * |
1470 | * @param monitor The monitor to assign | |
73005152 BH |
1471 | */ |
1472 | public void setMonitor(IProgressMonitor monitor) { | |
1473 | fMonitor = monitor; | |
1474 | } | |
1475 | ||
1476 | /** | |
1477 | * Check if find criteria was met. | |
a55887ca | 1478 | * |
73005152 BH |
1479 | * @return true if find criteria was met. |
1480 | */ | |
1481 | public boolean isFound() { | |
1482 | return fIsFound; | |
1483 | } | |
1484 | ||
1485 | /** | |
df0b8ff4 | 1486 | * Returns timestamp of found time. |
a55887ca | 1487 | * |
73005152 BH |
1488 | * @return timestamp of found time. |
1489 | */ | |
4df4581d | 1490 | public ITmfTimestamp getFoundTime() { |
73005152 BH |
1491 | return fFoundTime; |
1492 | } | |
1493 | } | |
1494 | ||
3145ec83 | 1495 | /** |
a55887ca AM |
1496 | * Job class to provide progress monitor feedback. |
1497 | * | |
3145ec83 BH |
1498 | * @version 1.0 |
1499 | * @author Bernd Hufmann | |
1500 | * | |
1501 | */ | |
1502 | protected static class IndexingJob extends Job { | |
1503 | ||
1504 | public IndexingJob(String name) { | |
1505 | super(name); | |
1506 | } | |
1507 | ||
1508 | @Override | |
1509 | protected IStatus run(IProgressMonitor monitor) { | |
1510 | while (!monitor.isCanceled()) { | |
1511 | try { | |
1512 | Thread.sleep(100); | |
1513 | } catch (InterruptedException e) { | |
1514 | return Status.OK_STATUS; | |
1515 | } | |
1516 | } | |
1517 | monitor.done(); | |
1518 | return Status.OK_STATUS; | |
1519 | } | |
1520 | } | |
1521 | ||
a55887ca | 1522 | |
73005152 | 1523 | /** |
df0b8ff4 | 1524 | * Returns sequence diagram event if details in given event are available else null. |
a55887ca | 1525 | * |
73005152 BH |
1526 | * @param tmfEvent Event to parse for sequence diagram event details |
1527 | * @return sequence diagram event if details are available else null | |
1528 | */ | |
13e157b1 | 1529 | protected ITmfSyncSequenceDiagramEvent getSequnceDiagramEvent(ITmfEvent tmfEvent){ |
73005152 BH |
1530 | //type = .*RECEIVE.* or .*SEND.* |
1531 | //content = sender:<sender name>:receiver:<receiver name>,signal:<signal name> | |
1532 | String eventType = tmfEvent.getType().toString(); | |
4c564a2d FC |
1533 | if (eventType.contains(Messages.TmfUml2SDSyncCloader_EventTypeSend) || eventType.contains(Messages.TmfUml2SDSyncCloader_EventTypeReceive)) { |
1534 | Object sender = tmfEvent.getContent().getField(Messages.TmfUml2SDSyncCloader_FieldSender); | |
1535 | Object receiver = tmfEvent.getContent().getField(Messages.TmfUml2SDSyncCloader_FieldReceiver); | |
1536 | Object name = tmfEvent.getContent().getField(Messages.TmfUml2SDSyncCloader_FieldSignal); | |
13e157b1 | 1537 | if ((sender instanceof ITmfEventField) && (receiver instanceof ITmfEventField) && (name instanceof ITmfEventField)) { |
4c564a2d | 1538 | ITmfSyncSequenceDiagramEvent sdEvent = new TmfSyncSequenceDiagramEvent(tmfEvent, |
13e157b1 MK |
1539 | ((ITmfEventField) sender).getValue().toString(), |
1540 | ((ITmfEventField) receiver).getValue().toString(), | |
1541 | ((ITmfEventField) name).getValue().toString()); | |
4c564a2d FC |
1542 | |
1543 | return sdEvent; | |
1544 | } | |
73005152 BH |
1545 | } |
1546 | return null; | |
1547 | } | |
1548 | } |