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