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