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