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