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