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