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 | */ | |
13e157b1 | 129 | protected TmfExperiment<ITmfEvent> fExperiment = null; |
df0b8ff4 BH |
130 | /** |
131 | * The current indexing event request. | |
132 | */ | |
13e157b1 | 133 | protected ITmfEventRequest<ITmfEvent> fIndexRequest = null; |
df0b8ff4 BH |
134 | /** |
135 | * The current request to fill a page. | |
136 | */ | |
13e157b1 | 137 | protected ITmfEventRequest<ITmfEvent> 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(); | |
13e157b1 | 253 | ITmfEventRequest<ITmfEvent> 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 |
13e157b1 | 273 | public void experimentSelected(TmfExperimentSelectedSignal<ITmfEvent> 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 | |
13e157b1 | 282 | TmfExperiment<ITmfEvent> exp = (TmfExperiment<ITmfEvent>) signal.getExperiment(); |
73005152 BH |
283 | if (!exp.equals(fExperiment)) { |
284 | fExperiment = exp; | |
285 | } | |
286 | ||
a4115405 | 287 | TmfTimeRange window = TmfTimeRange.ETERNITY; |
73005152 | 288 | |
13e157b1 | 289 | fIndexRequest = new TmfEventRequest<ITmfEvent>(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 |
df0b8ff4 | 396 | public void experimentDisposed(TmfExperimentDisposedSignal<ITmfEvent> 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 { | |
431 | if ((signal.getSource() != this) && (fFrame != null)) { | |
432 | ||
433 | fCurrentTime = signal.getCurrentTime(); | |
434 | fIsSelect = true; | |
435 | moveToMessage(); | |
436 | } | |
437 | } finally { | |
438 | fLock.unlock(); | |
439 | } | |
440 | } | |
441 | ||
442 | /** | |
a55887ca AM |
443 | * Moves to the page that contains the current time provided by signal. |
444 | * No message will be selected however the focus will be set to the message | |
73005152 | 445 | * if the provided time is the time of a message. |
a55887ca | 446 | * |
73005152 BH |
447 | * @param signal The time range sync signal |
448 | */ | |
449 | @TmfSignalHandler | |
450 | public void synchToTimeRange(TmfRangeSynchSignal signal) { | |
451 | fLock.lock(); | |
452 | try { | |
453 | if ((signal.getSource() != this) && (fFrame != null) && !fIsSignalSent) { | |
454 | TmfTimeRange newTimeRange = signal.getCurrentRange(); | |
13e157b1 | 455 | ITmfTimestamp delta = newTimeRange.getEndTime().getDelta(newTimeRange.getStartTime()); |
73005152 BH |
456 | fInitialWindow = delta.getValue(); |
457 | ||
458 | fIsSelect = false; | |
7d1ef69c | 459 | fCurrentTime = newTimeRange.getStartTime(); |
73005152 BH |
460 | |
461 | moveToMessage(); | |
462 | } | |
463 | } finally { | |
464 | fLock.unlock(); | |
465 | } | |
466 | ||
467 | } | |
13e157b1 | 468 | |
73005152 BH |
469 | /* |
470 | * (non-Javadoc) | |
471 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#setViewer(org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView) | |
472 | */ | |
73005152 BH |
473 | @Override |
474 | public void setViewer(SDView viewer) { | |
13e157b1 MK |
475 | |
476 | fLock.lock(); | |
73005152 BH |
477 | try { |
478 | fView = viewer; | |
479 | PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addPostSelectionListener(this); | |
480 | fView.setSDFindProvider(this); | |
481 | fView.setSDPagingProvider(this); | |
482 | fView.setSDFilterProvider(this); | |
483 | ||
484 | resetLoader(); | |
485 | ||
13e157b1 | 486 | fExperiment = (TmfExperiment<ITmfEvent>) TmfExperiment.getCurrentExperiment(); |
73005152 | 487 | if (fExperiment != null) { |
13e157b1 | 488 | experimentSelected(new TmfExperimentSelectedSignal<ITmfEvent>(this, fExperiment)); |
73005152 BH |
489 | } |
490 | } finally { | |
491 | fLock.unlock(); | |
492 | } | |
493 | } | |
494 | ||
495 | /* | |
496 | * (non-Javadoc) | |
497 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader#getTitleString() | |
498 | */ | |
499 | @Override | |
500 | public String getTitleString() { | |
501 | return getName(); | |
502 | } | |
503 | ||
504 | /* | |
505 | * (non-Javadoc) | |
506 | * @see org.eclipse.linuxtools.tmf.component.TmfComponent#dispose() | |
507 | */ | |
508 | @Override | |
509 | public void dispose() { | |
510 | super.dispose(); | |
13e157b1 | 511 | fLock.lock(); |
73005152 | 512 | try { |
526d9026 BH |
513 | IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
514 | // During Eclipse shutdown the active workbench window is null | |
515 | if (window != null) { | |
516 | window.getSelectionService().removePostSelectionListener(this); | |
517 | } | |
73005152 BH |
518 | fView.setSDFindProvider(null); |
519 | fView.setSDPagingProvider(null); | |
520 | fView.setSDFilterProvider(null); | |
521 | fView = null; | |
522 | } finally { | |
523 | fLock.unlock(); | |
524 | } | |
525 | } | |
526 | ||
527 | /* | |
528 | * (non-Javadoc) | |
529 | * @see org.eclipse.hyades.uml2sd.ui.actions.provider.ISDGraphNodeSupporter#isNodeSupported(int) | |
530 | */ | |
531 | @Override | |
532 | public boolean isNodeSupported(int nodeType) { | |
533 | switch (nodeType) { | |
534 | case ISDGraphNodeSupporter.LIFELINE: | |
535 | case ISDGraphNodeSupporter.SYNCMESSAGE: | |
536 | return true; | |
537 | ||
538 | default: | |
539 | break; | |
540 | } | |
541 | return false; | |
542 | } | |
543 | ||
544 | /* | |
545 | * (non-Javadoc) | |
546 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter#getNodeName(int, java.lang.String) | |
547 | */ | |
548 | @Override | |
549 | public String getNodeName(int nodeType, String loaderClassName) { | |
550 | switch (nodeType) { | |
551 | case ISDGraphNodeSupporter.LIFELINE: | |
552 | return Messages.TmfUml2SDSyncLoader_CategoryLifeline; | |
553 | case ISDGraphNodeSupporter.SYNCMESSAGE: | |
554 | return Messages.TmfUml2SDSyncLoader_CategoryMessage; | |
abbdd66a AM |
555 | default: |
556 | break; | |
73005152 BH |
557 | } |
558 | return ""; //$NON-NLS-1$ | |
559 | } | |
560 | ||
561 | /* | |
562 | * (non-Javadoc) | |
563 | * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) | |
564 | */ | |
565 | @Override | |
566 | public void selectionChanged(IWorkbenchPart part, ISelection selection) { | |
567 | ISelection sel = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection(); | |
13e157b1 | 568 | if ((sel != null) && (sel instanceof StructuredSelection)) { |
73005152 BH |
569 | StructuredSelection stSel = (StructuredSelection) sel; |
570 | if (stSel.getFirstElement() instanceof TmfSyncMessage) { | |
571 | TmfSyncMessage syncMsg = ((TmfSyncMessage) stSel.getFirstElement()); | |
572 | broadcast(new TmfTimeSynchSignal(this, syncMsg.getStartTime())); | |
573 | } | |
574 | } | |
575 | } | |
576 | ||
577 | /* | |
578 | * (non-Javadoc) | |
579 | * @see | |
580 | * org.eclipse.hyades.uml2sd.ui.actions.provider.ISDFindProvider#find(org.eclipse.hyades.uml2sd.ui.actions.widgets.Criteria) | |
581 | */ | |
582 | @Override | |
583 | public boolean find(Criteria toSearch) { | |
584 | fLock.lock(); | |
585 | try { | |
586 | if (fFrame == null) { | |
587 | return false; | |
588 | } | |
589 | ||
13e157b1 | 590 | if ((fFindResults == null) || (fFindCriteria == null) || !fFindCriteria.compareTo(toSearch)) { |
73005152 BH |
591 | fFindResults = new CopyOnWriteArrayList<GraphNode>(); |
592 | fFindCriteria = toSearch; | |
593 | if (fFindCriteria.isLifeLineSelected()) { | |
594 | for (int i = 0; i < fFrame.lifeLinesCount(); i++) { | |
595 | if (fFindCriteria.matches(fFrame.getLifeline(i).getName())) { | |
596 | fFindResults.add(fFrame.getLifeline(i)); | |
597 | } | |
598 | } | |
599 | } | |
600 | ||
601 | ArrayList<GraphNode> msgs = new ArrayList<GraphNode>(); | |
602 | if (fFindCriteria.isSyncMessageSelected()) { | |
603 | for (int i = 0; i < fFrame.syncMessageCount(); i++) { | |
604 | if (fFindCriteria.matches(fFrame.getSyncMessage(i).getName())) { | |
605 | msgs.add(fFrame.getSyncMessage(i)); | |
606 | } | |
607 | } | |
608 | } | |
609 | ||
eb63f5ff | 610 | if (!msgs.isEmpty()) { |
73005152 BH |
611 | fFindResults.addAll(msgs); |
612 | } | |
613 | ||
614 | @SuppressWarnings("rawtypes") | |
615 | List selection = fView.getSDWidget().getSelection(); | |
13e157b1 | 616 | if ((selection != null) && (selection.size() == 1)) { |
73005152 | 617 | fCurrentFindIndex = fFindResults.indexOf(selection.get(0)) + 1; |
13e157b1 | 618 | } else { |
73005152 | 619 | fCurrentFindIndex = 0; |
13e157b1 | 620 | } |
73005152 BH |
621 | } else { |
622 | fCurrentFindIndex++; | |
623 | } | |
624 | ||
625 | if (fFindResults.size() > fCurrentFindIndex) { | |
13e157b1 | 626 | GraphNode current = fFindResults.get(fCurrentFindIndex); |
73005152 BH |
627 | fView.getSDWidget().moveTo(current); |
628 | return true; | |
73005152 | 629 | } |
abbdd66a AM |
630 | fFindResults = null; |
631 | fCurrentFindIndex =0; | |
632 | return findInNextPages(fFindCriteria); // search in other page | |
73005152 BH |
633 | } finally { |
634 | fLock.unlock(); | |
635 | } | |
636 | } | |
637 | ||
638 | /* | |
639 | * (non-Javadoc) | |
640 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFindProvider#cancel() | |
641 | */ | |
642 | @Override | |
643 | public void cancel() { | |
644 | cancelOngoingRequests(); | |
645 | } | |
646 | ||
647 | /* | |
648 | * (non-Javadoc) | |
649 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDFilterProvider#filter(java.util.List) | |
650 | */ | |
651 | @SuppressWarnings("unchecked") | |
652 | @Override | |
653 | public boolean filter(List<?> filters) { | |
654 | fLock.lock(); | |
655 | try { | |
656 | cancelOngoingRequests(); | |
657 | ||
658 | List<FilterCriteria> list = (List<FilterCriteria>)filters; | |
659 | fFilterCriteria = new ArrayList<FilterCriteria>(list); | |
660 | ||
661 | fillCurrentPage(fEvents); | |
662 | ||
663 | } finally { | |
664 | fLock.unlock(); | |
665 | } | |
666 | return true; | |
667 | } | |
13e157b1 | 668 | |
73005152 BH |
669 | /* |
670 | * (non-Javadoc) | |
671 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasNextPage() | |
672 | */ | |
673 | @Override | |
674 | public boolean hasNextPage() { | |
675 | fLock.lock(); | |
676 | try { | |
677 | int size = fCheckPoints.size(); | |
678 | if (size > 0) { | |
13e157b1 | 679 | return fCurrentPage < (size - 1); |
73005152 BH |
680 | } |
681 | } finally { | |
682 | fLock.unlock(); | |
683 | } | |
684 | return false; | |
685 | } | |
686 | ||
687 | /* | |
688 | * (non-Javadoc) | |
689 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#hasPrevPage() | |
690 | */ | |
691 | @Override | |
692 | public boolean hasPrevPage() { | |
693 | fLock.lock(); | |
694 | try { | |
695 | return fCurrentPage > 0; | |
696 | } finally { | |
697 | fLock.unlock(); | |
698 | } | |
699 | } | |
700 | ||
701 | /* | |
702 | * (non-Javadoc) | |
703 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#nextPage() | |
704 | */ | |
705 | @Override | |
706 | public void nextPage() { | |
707 | fLock.lock(); | |
708 | try { | |
709 | // Safety check | |
13e157b1 | 710 | if (fCurrentPage >= (fCheckPoints.size() - 1)) { |
73005152 | 711 | return; |
13e157b1 | 712 | } |
73005152 BH |
713 | |
714 | cancelOngoingRequests(); | |
715 | fCurrentTime = null; | |
716 | fCurrentPage++; | |
717 | moveToPage(); | |
718 | } finally { | |
719 | fLock.unlock(); | |
720 | } | |
721 | } | |
722 | ||
723 | /* | |
724 | * (non-Javadoc) | |
725 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#prevPage() | |
726 | */ | |
727 | @Override | |
728 | public void prevPage() { | |
729 | fLock.lock(); | |
730 | try { | |
731 | // Safety check | |
13e157b1 | 732 | if (fCurrentPage <= 0) { |
73005152 | 733 | return; |
13e157b1 | 734 | } |
73005152 BH |
735 | |
736 | cancelOngoingRequests(); | |
737 | fCurrentTime = null; | |
738 | fCurrentPage--; | |
739 | moveToPage(); | |
740 | } finally { | |
741 | fLock.unlock(); | |
742 | } | |
743 | } | |
13e157b1 | 744 | |
73005152 BH |
745 | /* |
746 | * (non-Javadoc) | |
747 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#firstPage() | |
748 | */ | |
749 | @Override | |
750 | public void firstPage() { | |
751 | fLock.lock(); | |
752 | try { | |
753 | ||
754 | cancelOngoingRequests(); | |
755 | fCurrentTime = null; | |
756 | fCurrentPage = 0; | |
757 | moveToPage(); | |
758 | } finally { | |
759 | fLock.unlock(); | |
760 | } | |
761 | } | |
13e157b1 | 762 | |
73005152 BH |
763 | /* |
764 | * (non-Javadoc) | |
765 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDPagingProvider#lastPage() | |
766 | */ | |
767 | @Override | |
768 | public void lastPage() { | |
769 | fLock.lock(); | |
770 | try { | |
771 | cancelOngoingRequests(); | |
772 | fCurrentTime = null; | |
773 | fCurrentPage = fCheckPoints.size() - 1; | |
774 | moveToPage(); | |
775 | } finally { | |
776 | fLock.unlock(); | |
777 | } | |
778 | } | |
779 | ||
780 | /* | |
781 | * (non-Javadoc) | |
782 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#currentPage() | |
783 | */ | |
784 | @Override | |
785 | public int currentPage() { | |
786 | fLock.lock(); | |
787 | try { | |
788 | return fCurrentPage; | |
789 | } finally { | |
790 | fLock.unlock(); | |
791 | } | |
792 | } | |
793 | ||
794 | /* | |
795 | * (non-Javadoc) | |
796 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pagesCount() | |
797 | */ | |
798 | @Override | |
799 | public int pagesCount() { | |
800 | fLock.lock(); | |
801 | try { | |
802 | return fCheckPoints.size(); | |
803 | } finally { | |
804 | fLock.unlock(); | |
805 | } | |
806 | } | |
807 | ||
808 | /* | |
809 | * (non-Javadoc) | |
810 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider#pageNumberChanged(int) | |
811 | */ | |
812 | @Override | |
eb63f5ff BH |
813 | public void pageNumberChanged(int pagenNumber) { |
814 | int localPageNumber = pagenNumber; | |
a55887ca | 815 | |
73005152 BH |
816 | fLock.lock(); |
817 | try { | |
818 | cancelOngoingRequests(); | |
819 | ||
eb63f5ff BH |
820 | if (localPageNumber < 0) { |
821 | localPageNumber = 0; | |
73005152 BH |
822 | } |
823 | int size = fCheckPoints.size(); | |
eb63f5ff BH |
824 | if (localPageNumber > (size - 1)) { |
825 | localPageNumber = size - 1; | |
73005152 | 826 | } |
eb63f5ff | 827 | fCurrentPage = localPageNumber; |
73005152 BH |
828 | moveToPage(); |
829 | } finally { | |
830 | fLock.unlock(); | |
831 | } | |
832 | } | |
833 | ||
834 | /* | |
835 | * (non-Javadoc) | |
836 | * @see org.eclipse.linuxtools.tmf.component.TmfComponent#broadcast(org.eclipse.linuxtools.tmf.signal.TmfSignal) | |
837 | */ | |
838 | @Override | |
839 | public void broadcast(TmfSignal signal) { | |
840 | fIsSignalSent = true; | |
841 | super.broadcast(signal); | |
842 | fIsSignalSent = false; | |
843 | } | |
844 | ||
845 | /** | |
846 | * Cancels any ongoing find operation | |
847 | */ | |
848 | protected void cancelOngoingRequests() { | |
13e157b1 | 849 | fLock.lock(); |
73005152 BH |
850 | try { |
851 | // Cancel the search thread | |
852 | if (fFindJob != null) { | |
853 | fFindJob.cancel(); | |
854 | } | |
df0b8ff4 | 855 | |
73005152 BH |
856 | fFindResults = null; |
857 | fFindCriteria = null; | |
858 | fCurrentFindIndex = 0; | |
859 | ||
860 | if ((fPageRequest != null) && !fPageRequest.isCompleted()) { | |
861 | fPageRequest.cancel(); | |
862 | fPageRequest = null; | |
13e157b1 | 863 | } |
73005152 BH |
864 | } finally { |
865 | fLock.unlock(); | |
866 | } | |
867 | } | |
868 | ||
869 | /** | |
870 | * Resets loader attributes | |
871 | */ | |
872 | protected void resetLoader() { | |
873 | fLock.lock(); | |
874 | try { | |
875 | fCurrentTime = null; | |
876 | fEvents.clear(); | |
877 | fCheckPoints.clear(); | |
878 | fCurrentPage = 0; | |
879 | fCurrentFindIndex = 0; | |
880 | fFindCriteria = null; | |
881 | fFindResults = null; | |
882 | fInitialWindow = INITIAL_WINDOW_OFFSET; | |
883 | fView.setFrameSync(new Frame()); | |
884 | fFrame = null; | |
885 | } | |
886 | finally { | |
887 | fLock.unlock(); | |
888 | } | |
889 | ||
890 | } | |
891 | ||
892 | /** | |
893 | * Fills current page with sequence diagram content. | |
a55887ca | 894 | * |
73005152 BH |
895 | * @param events sequence diagram events |
896 | */ | |
897 | protected void fillCurrentPage(List<ITmfSyncSequenceDiagramEvent> events) { | |
898 | ||
899 | fLock.lock(); | |
900 | try { | |
901 | fEvents = new ArrayList<ITmfSyncSequenceDiagramEvent>(events); | |
902 | if (fView != null) { | |
903 | fView.toggleWaitCursorAsync(true); | |
904 | } | |
905 | } finally { | |
906 | fLock.unlock(); | |
907 | } | |
13e157b1 | 908 | |
73005152 | 909 | final Frame frame = new Frame(); |
73005152 | 910 | |
eb63f5ff BH |
911 | if (!events.isEmpty()) { |
912 | Map<String, Lifeline> nodeToLifelineMap = new HashMap<String, Lifeline>(); | |
73005152 BH |
913 | |
914 | frame.setName(Messages.TmfUml2SDSyncLoader_FrameName); | |
915 | ||
916 | for (int i = 0; i < events.size(); i++) { | |
917 | ||
918 | ITmfSyncSequenceDiagramEvent sdEvent = events.get(i); | |
919 | ||
920 | if ((nodeToLifelineMap.get(sdEvent.getSender()) == null) && (!filterLifeLine(sdEvent.getSender()))) { | |
921 | Lifeline lifeline = new Lifeline(); | |
922 | lifeline.setName(sdEvent.getSender()); | |
923 | nodeToLifelineMap.put(sdEvent.getSender(), lifeline); | |
924 | frame.addLifeLine(lifeline); | |
925 | } | |
926 | ||
927 | if ((nodeToLifelineMap.get(sdEvent.getReceiver()) == null) && (!filterLifeLine(sdEvent.getReceiver()))) { | |
928 | Lifeline lifeline = new Lifeline(); | |
929 | lifeline.setName(sdEvent.getReceiver()); | |
930 | nodeToLifelineMap.put(sdEvent.getReceiver(), lifeline); | |
931 | frame.addLifeLine(lifeline); | |
932 | } | |
933 | } | |
934 | ||
935 | int eventOccurence = 1; | |
936 | ||
937 | for (int i = 0; i < events.size(); i++) { | |
13e157b1 | 938 | ITmfSyncSequenceDiagramEvent sdEvent = events.get(i); |
73005152 BH |
939 | |
940 | // Check message filter | |
941 | if (filterMessage(sdEvent)) { | |
942 | continue; | |
943 | } | |
944 | ||
945 | // Set the message sender and receiver | |
13e157b1 MK |
946 | Lifeline startLifeline = nodeToLifelineMap.get(sdEvent.getSender()); |
947 | Lifeline endLifeline = nodeToLifelineMap.get(sdEvent.getReceiver()); | |
73005152 | 948 | |
13e157b1 MK |
949 | // Check if any of the lifelines were filtered |
950 | if ((startLifeline == null) || (endLifeline == null)) { | |
73005152 BH |
951 | continue; |
952 | } | |
953 | ||
954 | int tmp = Math.max(startLifeline.getEventOccurrence(), endLifeline.getEventOccurrence()); | |
955 | eventOccurence = Math.max(eventOccurence, tmp); | |
13e157b1 | 956 | |
73005152 BH |
957 | startLifeline.setCurrentEventOccurrence(eventOccurence); |
958 | endLifeline.setCurrentEventOccurrence(eventOccurence); | |
13e157b1 | 959 | |
73005152 | 960 | TmfSyncMessage message = new TmfSyncMessage(sdEvent, eventOccurence++); |
13e157b1 | 961 | |
73005152 BH |
962 | message.setStartLifeline(startLifeline); |
963 | message.setEndLifeline(endLifeline); | |
964 | ||
965 | message.setTime(sdEvent.getStartTime()); | |
966 | ||
967 | // add the message to the frame | |
968 | frame.addMessage(message); | |
13e157b1 | 969 | |
73005152 BH |
970 | } |
971 | fLock.lock(); | |
972 | try { | |
973 | if (!fView.getSDWidget().isDisposed()) { | |
974 | fView.getSDWidget().getDisplay().asyncExec(new Runnable() { | |
975 | ||
976 | @Override | |
977 | public void run() { | |
978 | ||
979 | fLock.lock(); | |
980 | try { | |
981 | // check if view was disposed in the meanwhile | |
982 | if ((fView != null) && (!fView.getSDWidget().isDisposed())) { | |
983 | fFrame = frame; | |
984 | fView.setFrame(fFrame); | |
985 | ||
986 | if (fCurrentTime != null) { | |
987 | moveToMessageInPage(); | |
988 | } | |
989 | ||
990 | if (fFindCriteria != null) { | |
991 | find(fFindCriteria); | |
992 | } | |
13e157b1 | 993 | |
73005152 BH |
994 | fView.toggleWaitCursorAsync(false); |
995 | } | |
996 | } finally { | |
997 | fLock.unlock(); | |
998 | } | |
999 | ||
1000 | } | |
1001 | }); | |
1002 | } | |
1003 | } | |
1004 | finally { | |
1005 | fLock.unlock(); | |
1006 | } | |
1007 | } | |
1008 | } | |
1009 | ||
1010 | /** | |
1011 | * Moves to a certain message defined by timestamp (across pages) | |
1012 | */ | |
1013 | protected void moveToMessage() { | |
1014 | int page = 0; | |
1015 | ||
1016 | fLock.lock(); | |
1017 | try { | |
1018 | page = getPage(fCurrentTime); | |
1019 | ||
1020 | if (page == fCurrentPage) { | |
1021 | moveToMessageInPage(); | |
1022 | return; | |
1023 | } | |
1024 | fCurrentPage = page; | |
1025 | moveToPage(false); | |
1026 | } finally { | |
1027 | fLock.unlock(); | |
1028 | } | |
1029 | } | |
1030 | ||
1031 | /** | |
1032 | * Moves to a certain message defined by timestamp in current page | |
1033 | */ | |
1034 | protected void moveToMessageInPage() { | |
1035 | fLock.lock(); | |
1036 | try { | |
de7ddc02 BH |
1037 | if (!fView.getSDWidget().isDisposed()) { |
1038 | // Check for GUI thread | |
1039 | if(Display.getCurrent() != null) { | |
1040 | // Already in GUI thread - execute directly | |
1041 | TmfSyncMessage prevMessage = null; | |
1042 | TmfSyncMessage syncMessage = null; | |
1043 | boolean isExactTime = false; | |
1044 | for (int i = 0; i < fFrame.syncMessageCount(); i++) { | |
1045 | if (fFrame.getSyncMessage(i) instanceof TmfSyncMessage) { | |
1046 | syncMessage = (TmfSyncMessage) fFrame.getSyncMessage(i); | |
1047 | if (syncMessage.getStartTime().compareTo(fCurrentTime, false) == 0) { | |
1048 | isExactTime = true; | |
1049 | break; | |
eb63f5ff BH |
1050 | } else if ((syncMessage.getStartTime().compareTo(fCurrentTime, false) > 0) && (prevMessage != null)) { |
1051 | syncMessage = prevMessage; | |
1052 | break; | |
de7ddc02 BH |
1053 | } |
1054 | prevMessage = syncMessage; | |
1055 | } | |
1056 | } | |
1057 | if (fIsSelect && isExactTime) { | |
1058 | fView.getSDWidget().moveTo(syncMessage); | |
1059 | } | |
1060 | else { | |
1061 | fView.getSDWidget().ensureVisible(syncMessage); | |
1062 | fView.getSDWidget().clearSelection(); | |
1063 | fView.getSDWidget().redraw(); | |
1064 | } | |
1065 | } | |
1066 | else { | |
13e157b1 | 1067 | // Not in GUI thread - queue action in GUI thread. |
de7ddc02 BH |
1068 | fView.getSDWidget().getDisplay().asyncExec(new Runnable() { |
1069 | @Override | |
1070 | public void run() { | |
1071 | moveToMessageInPage(); | |
1072 | } | |
1073 | }); | |
1074 | } | |
1075 | } | |
73005152 BH |
1076 | } |
1077 | finally { | |
1078 | fLock.unlock(); | |
1079 | } | |
1080 | } | |
13e157b1 | 1081 | |
73005152 BH |
1082 | /** |
1083 | * Moves to a certain message defined by timestamp (across pages) | |
1084 | */ | |
1085 | protected void moveToPage() { | |
1086 | moveToPage(true); | |
1087 | } | |
1088 | ||
1089 | /** | |
1090 | * Moves to a certain page. | |
a55887ca | 1091 | * |
73005152 BH |
1092 | * @param notifyAll true to broadcast time range signal to other signal handlers else false |
1093 | */ | |
1094 | protected void moveToPage(boolean notifyAll) { | |
1095 | ||
eb63f5ff | 1096 | TmfTimeRange window = null; |
73005152 BH |
1097 | |
1098 | fLock.lock(); | |
1099 | try { | |
1100 | // Safety check | |
1101 | if (fCurrentPage > fCheckPoints.size()) { | |
1102 | return; | |
1103 | } | |
1104 | window = fCheckPoints.get(fCurrentPage); | |
1105 | } finally { | |
1106 | fLock.unlock(); | |
1107 | } | |
1108 | ||
eb63f5ff BH |
1109 | if (window == null) { |
1110 | window = TmfTimeRange.ETERNITY; | |
1111 | } | |
1112 | ||
13e157b1 MK |
1113 | fPageRequest = new TmfEventRequest<ITmfEvent>(ITmfEvent.class, window, TmfDataRequest.ALL_DATA, 1, ITmfDataRequest.ExecutionType.FOREGROUND) { |
1114 | private final List<ITmfSyncSequenceDiagramEvent> fSdEvent = new ArrayList<ITmfSyncSequenceDiagramEvent>(); | |
73005152 BH |
1115 | |
1116 | @Override | |
13e157b1 | 1117 | public void handleData(ITmfEvent event) { |
73005152 BH |
1118 | super.handleData(event); |
1119 | ||
1120 | ITmfSyncSequenceDiagramEvent sdEvent = getSequnceDiagramEvent(event); | |
1121 | ||
1122 | if (sdEvent != null) { | |
1123 | fSdEvent.add(sdEvent); | |
1124 | } | |
1125 | } | |
1126 | ||
1127 | @Override | |
1128 | public void handleSuccess() { | |
1129 | fillCurrentPage(fSdEvent); | |
1130 | super.handleSuccess(); | |
1131 | } | |
13e157b1 | 1132 | |
73005152 BH |
1133 | }; |
1134 | ||
13e157b1 | 1135 | fExperiment.sendRequest(fPageRequest); |
73005152 BH |
1136 | |
1137 | if (notifyAll) { | |
1138 | TmfTimeRange timeRange = getSignalTimeRange(window.getStartTime()); | |
1139 | broadcast(new TmfRangeSynchSignal(this, timeRange, timeRange.getStartTime())); | |
1140 | } | |
1141 | } | |
1142 | ||
1143 | /** | |
1144 | * Gets page that contains timestamp | |
a55887ca | 1145 | * |
73005152 BH |
1146 | * @param time The timestamp |
1147 | * @return page that contains the time | |
1148 | */ | |
4df4581d | 1149 | protected int getPage(ITmfTimestamp time) { |
73005152 BH |
1150 | int page; |
1151 | int size; | |
1152 | fLock.lock(); | |
1153 | try { | |
1154 | size = fCheckPoints.size(); | |
13e157b1 | 1155 | for (page = 0; page < size; page++) { |
73005152 BH |
1156 | TmfTimeRange timeRange = fCheckPoints.get(page); |
1157 | if (timeRange.getEndTime().compareTo(time, false) >= 0) { | |
1158 | break; | |
1159 | } | |
1160 | } | |
1161 | if (page >= size) { | |
1162 | page = size - 1; | |
1163 | } | |
1164 | return page; | |
1165 | } finally { | |
1166 | fLock.unlock(); | |
1167 | } | |
1168 | } | |
13e157b1 | 1169 | |
73005152 BH |
1170 | /** |
1171 | * Background search in trace for expression in criteria. | |
a55887ca | 1172 | * |
73005152 BH |
1173 | * @param findCriteria The find criteria |
1174 | * @return true if background request was started else false | |
1175 | */ | |
1176 | protected boolean findInNextPages(Criteria findCriteria) { | |
1177 | fLock.lock(); | |
1178 | try { | |
1179 | if (fFindJob != null) { | |
1180 | return true; | |
1181 | } | |
1182 | ||
1183 | int nextPage = fCurrentPage + 1; | |
1184 | ||
1185 | if ((nextPage) >= fCheckPoints.size()) { | |
1186 | // we are at the end | |
1187 | return false; | |
1188 | } | |
1189 | ||
1190 | TmfTimeRange window = new TmfTimeRange(fCheckPoints.get(nextPage).getStartTime().clone(), fCheckPoints.get(fCheckPoints.size()-1).getEndTime().clone()); | |
1191 | fFindJob = new SearchJob(findCriteria, window); | |
1192 | fFindJob.schedule(); | |
1193 | fView.toggleWaitCursorAsync(true); | |
1194 | } finally { | |
1195 | fLock.unlock(); | |
1196 | } | |
1197 | return true; | |
1198 | } | |
1199 | ||
1200 | /** | |
1201 | * Gets time range for time range signal. | |
a55887ca | 1202 | * |
73005152 | 1203 | * @param startTime The start time of time range. |
0d9a6d76 | 1204 | * @return the time range |
73005152 | 1205 | */ |
4df4581d | 1206 | protected TmfTimeRange getSignalTimeRange(ITmfTimestamp startTime) { |
73005152 BH |
1207 | fLock.lock(); |
1208 | try { | |
1209 | TmfTimestamp initialEndOfWindow = new TmfTimestamp(startTime.getValue() + fInitialWindow, startTime.getScale(), startTime.getPrecision()); | |
1210 | return new TmfTimeRange(startTime, initialEndOfWindow); | |
1211 | } | |
1212 | finally { | |
1213 | fLock.unlock(); | |
1214 | } | |
1215 | } | |
1216 | ||
1217 | /** | |
13e157b1 | 1218 | * Checks if filter criteria matches the message name in given SD event. |
a55887ca | 1219 | * |
73005152 BH |
1220 | * @param sdEvent The SD event to check |
1221 | * @return true if match else false. | |
1222 | */ | |
1223 | protected boolean filterMessage(ITmfSyncSequenceDiagramEvent sdEvent) { | |
1224 | fLock.lock(); | |
1225 | try { | |
1226 | if (fFilterCriteria != null) { | |
1227 | for(FilterCriteria criteria : fFilterCriteria) { | |
eb63f5ff BH |
1228 | if (criteria.isActive() && criteria.getCriteria().isSyncMessageSelected() && criteria.getCriteria().matches(sdEvent.getName())) { |
1229 | return true; | |
73005152 BH |
1230 | } |
1231 | } | |
1232 | } | |
1233 | } finally { | |
1234 | fLock.unlock(); | |
1235 | } | |
1236 | return false; | |
1237 | } | |
1238 | ||
1239 | /** | |
13e157b1 | 1240 | * Checks if filter criteria matches a lifeline name (sender or receiver) in given SD event. |
a55887ca | 1241 | * |
0d9a6d76 | 1242 | * @param lifeline the message receiver |
73005152 BH |
1243 | * @return true if match else false. |
1244 | */ | |
1245 | protected boolean filterLifeLine(String lifeline) { | |
1246 | fLock.lock(); | |
1247 | try { | |
1248 | if (fFilterCriteria != null) { | |
1249 | for(FilterCriteria criteria : fFilterCriteria) { | |
eb63f5ff BH |
1250 | if (criteria.isActive() && criteria.getCriteria().isLifeLineSelected() && criteria.getCriteria().matches(lifeline)) { |
1251 | return true; | |
73005152 BH |
1252 | } |
1253 | } | |
1254 | } | |
1255 | } finally { | |
1256 | fLock.unlock(); | |
1257 | } | |
1258 | return false; | |
1259 | } | |
1260 | ||
1261 | /** | |
13e157b1 | 1262 | * Job to search in trace for given time range. |
73005152 BH |
1263 | */ |
1264 | protected class SearchJob extends Job { | |
1265 | ||
df0b8ff4 | 1266 | /** |
a55887ca | 1267 | * The search event request. |
df0b8ff4 | 1268 | */ |
73005152 | 1269 | final protected SearchEventRequest fSearchRequest; |
13e157b1 | 1270 | |
73005152 BH |
1271 | /** |
1272 | * Constructor | |
13e157b1 | 1273 | * |
73005152 BH |
1274 | * @param findCriteria The search criteria |
1275 | * @param window Time range to search in | |
1276 | */ | |
1277 | public SearchJob(Criteria findCriteria, TmfTimeRange window) { | |
1278 | super(Messages.TmfUml2SDSyncLoader_SearchJobDescrition); | |
1279 | fSearchRequest = new SearchEventRequest(window, TmfDataRequest.ALL_DATA, 1, ITmfDataRequest.ExecutionType.FOREGROUND, findCriteria); | |
1280 | } | |
1281 | ||
1282 | /* | |
1283 | * (non-Javadoc) | |
1284 | * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) | |
1285 | */ | |
1286 | @Override | |
1287 | protected IStatus run(IProgressMonitor monitor) { | |
1288 | fSearchRequest.setMonitor(monitor); | |
13e157b1 MK |
1289 | |
1290 | fExperiment.sendRequest(fSearchRequest); | |
73005152 BH |
1291 | |
1292 | try { | |
1293 | fSearchRequest.waitForCompletion(); | |
1294 | } catch (InterruptedException e) { | |
8fd82db5 | 1295 | Activator.getDefault().logError("Search request interrupted!", e); //$NON-NLS-1$ |
73005152 BH |
1296 | } |
1297 | ||
13e157b1 MK |
1298 | IStatus status = Status.OK_STATUS; |
1299 | if (fSearchRequest.isFound() && (fSearchRequest.getFoundTime() != null)) { | |
73005152 | 1300 | fCurrentTime = fSearchRequest.getFoundTime(); |
13e157b1 | 1301 | |
73005152 BH |
1302 | // Avoid double-selection. Selection will be done when calling find(criteria) |
1303 | // after moving to relevant page | |
13e157b1 | 1304 | fIsSelect = false; |
73005152 BH |
1305 | if (!fView.getSDWidget().isDisposed()) { |
1306 | fView.getSDWidget().getDisplay().asyncExec(new Runnable() { | |
1307 | ||
1308 | @Override | |
1309 | public void run() { | |
1310 | moveToMessage(); | |
1311 | } | |
1312 | }); | |
1313 | } | |
1314 | } | |
1315 | else { | |
1316 | if (monitor.isCanceled()) { | |
1317 | status = Status.CANCEL_STATUS; | |
1318 | } | |
1319 | else { | |
1320 | // String was not found | |
abbdd66a | 1321 | status = new Status(IStatus.WARNING, Activator.PLUGIN_ID, Messages.TmfUml2SDSyncLoader_SearchNotFound); |
73005152 BH |
1322 | } |
1323 | setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE); | |
1324 | } | |
1325 | monitor.done(); | |
1326 | ||
1327 | fLock.lock(); | |
1328 | try { | |
1329 | fView.toggleWaitCursorAsync(false); | |
1330 | fFindJob = null; | |
1331 | } finally { | |
1332 | fLock.unlock(); | |
1333 | } | |
1334 | ||
1335 | return status; | |
1336 | } | |
13e157b1 | 1337 | |
73005152 BH |
1338 | /* |
1339 | * (non-Javadoc) | |
1340 | * @see org.eclipse.core.runtime.jobs.Job#canceling() | |
1341 | */ | |
1342 | @Override | |
1343 | protected void canceling() { | |
1344 | fSearchRequest.cancel(); | |
1345 | fLock.lock(); | |
1346 | try { | |
1347 | fFindJob = null; | |
1348 | } finally { | |
1349 | fLock.unlock(); | |
1350 | } | |
1351 | } | |
1352 | } | |
1353 | ||
1354 | /** | |
13e157b1 | 1355 | * TMF event request for searching within trace. |
73005152 | 1356 | */ |
13e157b1 | 1357 | protected class SearchEventRequest extends TmfEventRequest<ITmfEvent> { |
73005152 | 1358 | |
df0b8ff4 BH |
1359 | /** |
1360 | * The find criteria. | |
1361 | */ | |
73005152 | 1362 | final private Criteria fCriteria; |
df0b8ff4 BH |
1363 | /** |
1364 | * A progress monitor | |
1365 | */ | |
73005152 | 1366 | private IProgressMonitor fMonitor; |
df0b8ff4 BH |
1367 | /** |
1368 | * Flag to indicate that node was found according the criteria . | |
1369 | */ | |
73005152 | 1370 | private boolean fIsFound = false; |
df0b8ff4 BH |
1371 | /** |
1372 | * Time stamp of found item. | |
1373 | */ | |
4df4581d | 1374 | private ITmfTimestamp fFoundTime = null; |
73005152 BH |
1375 | |
1376 | /** | |
13e157b1 | 1377 | * Constructor |
73005152 BH |
1378 | * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...) |
1379 | * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...) | |
1380 | * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...) | |
1381 | * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#handleData(...) | |
1382 | * @param criteria The search criteria | |
1383 | */ | |
1384 | public SearchEventRequest(TmfTimeRange range, int nbRequested, int blockSize, ExecutionType execType, Criteria criteria) { | |
1385 | this(range, nbRequested, blockSize, execType, criteria, null); | |
1386 | } | |
1387 | ||
1388 | /** | |
1389 | * Constructor | |
1390 | * @param range @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...) | |
13e157b1 | 1391 | * @param nbRequested @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...) |
73005152 BH |
1392 | * @param blockSize @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...) |
1393 | * @param execType @see org.eclipse.linuxtools.tmf.request.TmfEventRequest#TmfEventRequest(...) | |
1394 | * @param criteria The search criteria | |
1395 | * @param monitor progress monitor | |
1396 | */ | |
1397 | public SearchEventRequest(TmfTimeRange range, int nbRequested, int blockSize, ExecutionType execType, Criteria criteria, IProgressMonitor monitor) { | |
13e157b1 | 1398 | super(ITmfEvent.class, range, nbRequested, blockSize, execType); |
73005152 BH |
1399 | fCriteria = new Criteria(criteria); |
1400 | fMonitor = monitor; | |
1401 | } | |
13e157b1 | 1402 | |
73005152 BH |
1403 | /* |
1404 | * (non-Javadoc) | |
1405 | * @see org.eclipse.linuxtools.tmf.request.TmfDataRequest#handleData(org.eclipse.linuxtools.tmf.event.TmfData) | |
1406 | */ | |
1407 | @Override | |
13e157b1 | 1408 | public void handleData(ITmfEvent event) { |
73005152 BH |
1409 | super.handleData(event); |
1410 | ||
1411 | if ((fMonitor!= null) && fMonitor.isCanceled()) { | |
e6ace8bb | 1412 | super.cancel(); |
73005152 BH |
1413 | return; |
1414 | } | |
1415 | ||
1416 | ITmfSyncSequenceDiagramEvent sdEvent = getSequnceDiagramEvent(event); | |
13e157b1 | 1417 | |
73005152 BH |
1418 | if (sdEvent != null) { |
1419 | ||
1420 | if (fCriteria.isLifeLineSelected()) { | |
1421 | if (fCriteria.matches(sdEvent.getSender())) { | |
1422 | fFoundTime = event.getTimestamp().clone(); | |
1423 | fIsFound = true; | |
1424 | super.cancel(); | |
1425 | } | |
1426 | ||
1427 | if (fCriteria.matches(sdEvent.getReceiver())) { | |
1428 | fFoundTime = event.getTimestamp().clone(); | |
1429 | fIsFound = true; | |
1430 | super.cancel(); | |
1431 | } | |
1432 | } | |
1433 | ||
eb63f5ff BH |
1434 | if (fCriteria.isSyncMessageSelected() && fCriteria.matches(sdEvent.getName())) { |
1435 | fFoundTime = event.getTimestamp().clone(); | |
1436 | fIsFound = true; | |
1437 | super.cancel(); | |
73005152 BH |
1438 | } |
1439 | } | |
1440 | } | |
1441 | ||
73005152 BH |
1442 | /** |
1443 | * Set progress monitor. | |
a55887ca AM |
1444 | * |
1445 | * @param monitor The monitor to assign | |
73005152 BH |
1446 | */ |
1447 | public void setMonitor(IProgressMonitor monitor) { | |
1448 | fMonitor = monitor; | |
1449 | } | |
1450 | ||
1451 | /** | |
1452 | * Check if find criteria was met. | |
a55887ca | 1453 | * |
73005152 BH |
1454 | * @return true if find criteria was met. |
1455 | */ | |
1456 | public boolean isFound() { | |
1457 | return fIsFound; | |
1458 | } | |
1459 | ||
1460 | /** | |
df0b8ff4 | 1461 | * Returns timestamp of found time. |
a55887ca | 1462 | * |
73005152 BH |
1463 | * @return timestamp of found time. |
1464 | */ | |
4df4581d | 1465 | public ITmfTimestamp getFoundTime() { |
73005152 BH |
1466 | return fFoundTime; |
1467 | } | |
1468 | } | |
1469 | ||
3145ec83 | 1470 | /** |
a55887ca AM |
1471 | * Job class to provide progress monitor feedback. |
1472 | * | |
3145ec83 BH |
1473 | * @version 1.0 |
1474 | * @author Bernd Hufmann | |
1475 | * | |
1476 | */ | |
1477 | protected static class IndexingJob extends Job { | |
1478 | ||
1479 | public IndexingJob(String name) { | |
1480 | super(name); | |
1481 | } | |
1482 | ||
1483 | @Override | |
1484 | protected IStatus run(IProgressMonitor monitor) { | |
1485 | while (!monitor.isCanceled()) { | |
1486 | try { | |
1487 | Thread.sleep(100); | |
1488 | } catch (InterruptedException e) { | |
1489 | return Status.OK_STATUS; | |
1490 | } | |
1491 | } | |
1492 | monitor.done(); | |
1493 | return Status.OK_STATUS; | |
1494 | } | |
1495 | } | |
1496 | ||
a55887ca | 1497 | |
73005152 | 1498 | /** |
df0b8ff4 | 1499 | * Returns sequence diagram event if details in given event are available else null. |
a55887ca | 1500 | * |
73005152 BH |
1501 | * @param tmfEvent Event to parse for sequence diagram event details |
1502 | * @return sequence diagram event if details are available else null | |
1503 | */ | |
13e157b1 | 1504 | protected ITmfSyncSequenceDiagramEvent getSequnceDiagramEvent(ITmfEvent tmfEvent){ |
73005152 BH |
1505 | //type = .*RECEIVE.* or .*SEND.* |
1506 | //content = sender:<sender name>:receiver:<receiver name>,signal:<signal name> | |
1507 | String eventType = tmfEvent.getType().toString(); | |
4c564a2d FC |
1508 | if (eventType.contains(Messages.TmfUml2SDSyncCloader_EventTypeSend) || eventType.contains(Messages.TmfUml2SDSyncCloader_EventTypeReceive)) { |
1509 | Object sender = tmfEvent.getContent().getField(Messages.TmfUml2SDSyncCloader_FieldSender); | |
1510 | Object receiver = tmfEvent.getContent().getField(Messages.TmfUml2SDSyncCloader_FieldReceiver); | |
1511 | Object name = tmfEvent.getContent().getField(Messages.TmfUml2SDSyncCloader_FieldSignal); | |
13e157b1 | 1512 | if ((sender instanceof ITmfEventField) && (receiver instanceof ITmfEventField) && (name instanceof ITmfEventField)) { |
4c564a2d | 1513 | ITmfSyncSequenceDiagramEvent sdEvent = new TmfSyncSequenceDiagramEvent(tmfEvent, |
13e157b1 MK |
1514 | ((ITmfEventField) sender).getValue().toString(), |
1515 | ((ITmfEventField) receiver).getValue().toString(), | |
1516 | ((ITmfEventField) name).getValue().toString()); | |
4c564a2d FC |
1517 | |
1518 | return sdEvent; | |
1519 | } | |
73005152 BH |
1520 | } |
1521 | return null; | |
1522 | } | |
1523 | } |