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