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