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