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