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