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