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