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