tmf: extract UpdateJob class and introduce TmfPieChartViewer
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / viewers / statistics / TmfStatisticsViewer.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2015 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 * Mathieu Denis <mathieu.denis@polymtl.ca> - Initial API and implementation
11 * Alexandre Montplaisir - Port to ITmfStatistics provider
12 * Patrick Tasse - Support selection range
13 * Bernd Hufmann - Fix range selection updates
14 *******************************************************************************/
15
16 package org.eclipse.tracecompass.tmf.ui.viewers.statistics;
17
18 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
19
20 import java.util.Collection;
21 import java.util.HashMap;
22 import java.util.List;
23 import java.util.Map;
24
25 import org.eclipse.core.runtime.jobs.Job;
26 import org.eclipse.jface.viewers.TreeViewer;
27 import org.eclipse.jface.viewers.TreeViewerColumn;
28 import org.eclipse.jface.viewers.Viewer;
29 import org.eclipse.jface.viewers.ViewerComparator;
30 import org.eclipse.swt.SWT;
31 import org.eclipse.swt.custom.SashForm;
32 import org.eclipse.swt.events.SelectionAdapter;
33 import org.eclipse.swt.events.SelectionEvent;
34 import org.eclipse.swt.graphics.Color;
35 import org.eclipse.swt.graphics.Cursor;
36 import org.eclipse.swt.widgets.Composite;
37 import org.eclipse.swt.widgets.Control;
38 import org.eclipse.swt.widgets.Display;
39 import org.eclipse.swt.widgets.Event;
40 import org.eclipse.swt.widgets.Listener;
41 import org.eclipse.tracecompass.tmf.core.component.TmfComponent;
42 import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
43 import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
44 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
45 import org.eclipse.tracecompass.tmf.core.signal.TmfTraceRangeUpdatedSignal;
46 import org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsModule;
47 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
48 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
49 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
50 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceContext;
51 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
52 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
53 import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
54 import org.eclipse.tracecompass.tmf.ui.viewers.TmfViewer;
55 import org.eclipse.tracecompass.tmf.ui.viewers.piecharts.TmfPieChartViewer;
56 import org.eclipse.tracecompass.tmf.ui.viewers.piecharts.model.TmfPieChartStatisticsModel;
57 import org.eclipse.tracecompass.tmf.ui.viewers.statistics.model.TmfBaseColumnData;
58 import org.eclipse.tracecompass.tmf.ui.viewers.statistics.model.TmfBaseColumnDataProvider;
59 import org.eclipse.tracecompass.tmf.ui.viewers.statistics.model.TmfStatisticsFormatter;
60 import org.eclipse.tracecompass.tmf.ui.viewers.statistics.model.TmfStatisticsTree;
61 import org.eclipse.tracecompass.tmf.ui.viewers.statistics.model.TmfStatisticsTreeManager;
62 import org.eclipse.tracecompass.tmf.ui.viewers.statistics.model.TmfStatisticsTreeNode;
63 import org.eclipse.tracecompass.tmf.ui.viewers.statistics.model.TmfTreeContentProvider;
64
65 /**
66 * A basic viewer to display statistics in the statistics view.
67 *
68 * It is linked to a single ITmfTrace until its disposal.
69 *
70 * @author Mathieu Denis
71 */
72 public class TmfStatisticsViewer extends TmfViewer {
73
74 /** The actual tree viewer to display */
75 private TreeViewer fTreeViewer;
76
77 /** Update range synchronization object */
78 private final Object fStatisticsRangeUpdateSyncObj = new Object();
79
80 /** The statistics tree linked to this viewer */
81 private TmfStatisticsTree fStatisticsData;
82
83 /** The trace that is displayed by this viewer */
84 private ITmfTrace fTrace;
85
86 /** Indicates to process all events */
87 private boolean fProcessAll;
88
89 /** View instance counter (for multiple statistics views) */
90 private static int fCountInstance = 0;
91
92 /** Number of this instance. Used as an instance ID. */
93 private int fInstanceNb;
94
95 /** Object to store the cursor while waiting for the trace to load */
96 private Cursor fWaitCursor = null;
97
98 /**
99 * Counts the number of times waitCursor() has been called. It avoids
100 * removing the waiting cursor, since there may be multiple requests running
101 * at the same time.
102 */
103 private int fWaitCursorCount = 0;
104
105 /** Tells to send a time range request when the trace gets updated. */
106 private boolean fSendRangeRequest = true;
107
108 private final Map<ITmfTrace, Job> fUpdateJobsPartial = new HashMap<>();
109 private final Map<ITmfTrace, Job> fUpdateJobsGlobal = new HashMap<>();
110
111 private TmfPieChartViewer fPieChartViewer;
112
113 private SashForm fSash;
114
115 private TmfPieChartStatisticsModel fPieChartModel;
116
117 /**
118 * Create a basic statistics viewer. To be used in conjunction with
119 * {@link TmfStatisticsViewer#init(Composite, String, ITmfTrace)}
120 *
121 * @param parent
122 * The parent composite that will hold the viewer
123 * @param viewerName
124 * The name that will be assigned to this viewer
125 * @param trace
126 * The trace that is displayed by this viewer
127 * @see TmfComponent
128 */
129 public TmfStatisticsViewer(Composite parent, String viewerName, ITmfTrace trace) {
130 init(parent, viewerName, trace);
131 }
132
133 /**
134 * Initialize the statistics viewer.
135 *
136 * @param parent
137 * The parent component of the viewer.
138 * @param viewerName
139 * The name to give to the viewer.
140 * @param trace
141 * The trace that will be displayed by the viewer.
142 */
143 public void init(Composite parent, String viewerName, ITmfTrace trace) {
144 super.init(parent, viewerName);
145 // Increment a counter to make sure the tree ID is unique.
146 fCountInstance++;
147 fInstanceNb = fCountInstance;
148 fTrace = trace;
149
150 // The viewer will process all events if he is assigned to an experiment
151 fProcessAll = (trace instanceof TmfExperiment);
152
153 initContent(parent);
154 initInput();
155 }
156
157 @Override
158 public void dispose() {
159 super.dispose();
160 if (fWaitCursor != null) {
161 fWaitCursor.dispose();
162 }
163
164 for (Job j : fUpdateJobsGlobal.values()) {
165 j.cancel();
166 }
167
168 for (Job j : fUpdateJobsPartial.values()) {
169 j.cancel();
170 }
171
172 // Clean the model for this viewer
173 TmfStatisticsTreeManager.removeStatTreeRoot(getTreeID());
174 fPieChartViewer.reinitializeCharts();
175 }
176
177 // ------------------------------------------------------------------------
178 // Signal handlers
179 // ------------------------------------------------------------------------
180
181 /**
182 * Handles the signal about new trace range.
183 *
184 * @param signal
185 * The trace range updated signal
186 */
187 @TmfSignalHandler
188 public void traceRangeUpdated(TmfTraceRangeUpdatedSignal signal) {
189 ITmfTrace trace = signal.getTrace();
190 // validate
191 if (!isListeningTo(trace)) {
192 return;
193 }
194
195 synchronized (fStatisticsRangeUpdateSyncObj) {
196 // Sends the time range request only once from this method.
197 if (fSendRangeRequest) {
198 fSendRangeRequest = false;
199
200 TmfTraceContext ctx = TmfTraceManager.getInstance().getCurrentTraceContext();
201 TmfTimeRange timeRange = ctx.getSelectionRange();
202 requestTimeRangeData(trace, timeRange);
203 }
204 }
205 requestData(trace, signal.getRange());
206 }
207
208 /**
209 * Handles the time synch updated signal. It updates the time range
210 * statistics.
211 *
212 * @param signal
213 * Contains the information about the new selected time range.
214 * @since 1.0
215 */
216 @TmfSignalHandler
217 public void timeSynchUpdated(TmfSelectionRangeUpdatedSignal signal) {
218 if (fTrace == null) {
219 return;
220 }
221 ITmfTimestamp begin = signal.getBeginTime();
222 ITmfTimestamp end = signal.getEndTime();
223 TmfTimeRange timeRange = new TmfTimeRange(begin, end);
224 requestTimeRangeData(fTrace, timeRange);
225 }
226
227 // ------------------------------------------------------------------------
228 // Class methods
229 // ------------------------------------------------------------------------
230
231 /*
232 * Returns the primary control associated with this viewer.
233 *
234 * @return the SWT control which displays this viewer's content
235 */
236 @Override
237 public Control getControl() {
238 return fSash;
239 }
240
241 /**
242 * Get the input of the viewer.
243 *
244 * @return an object representing the input of the statistics viewer.
245 */
246 public Object getInput() {
247 return fTreeViewer.getInput();
248 }
249
250 /**
251 * This method can be overridden to implement another way of representing
252 * the statistics data and to retrieve the information for display.
253 *
254 * @return a TmfStatisticsData object.
255 */
256 public TmfStatisticsTree getStatisticData() {
257 if (fStatisticsData == null) {
258 fStatisticsData = new TmfStatisticsTree();
259 }
260 return fStatisticsData;
261 }
262
263 /**
264 * @return the model of the piecharts in this viewer
265 * @since 2.0
266 */
267 public TmfPieChartStatisticsModel getPieChartModel(){
268 if (fPieChartModel == null) {
269 fPieChartModel = new TmfPieChartStatisticsModel();
270 }
271 return fPieChartModel;
272 }
273
274 /**
275 * Returns a unique ID based on name to be associated with the statistics
276 * tree for this viewer. For a same name, it will always return the same ID.
277 *
278 * @return a unique statistics tree ID.
279 */
280 public String getTreeID() {
281 return getName() + fInstanceNb;
282 }
283
284 @Override
285 public void refresh() {
286 final Control viewerControl = getControl();
287 // Ignore update if disposed
288 if (viewerControl.isDisposed()) {
289 return;
290 }
291 refreshTree();
292 refreshPieCharts(true, true);
293 }
294
295 /**
296 * Only refreshes the Tree viewer
297 */
298 private void refreshTree(){
299 final Control viewerControl = getControl();
300 // Ignore update if disposed
301 if (viewerControl.isDisposed()) {
302 return;
303 }
304
305 Display.getDefault().asyncExec(new Runnable() {
306 @Override
307 public void run() {
308 if (!viewerControl.isDisposed()) {
309 fTreeViewer.refresh();
310 }
311 }
312 });
313 }
314
315 /**
316 * Only refreshes the piecharts depending on the parameters
317 * @param refreshGlobal if we have to refresh the global piechart
318 * @param refreshSelection if we have to refresh the selection piechart
319 * @since 2.0
320 */
321 protected void refreshPieCharts(final boolean refreshGlobal, final boolean refreshSelection) {
322 final Control viewerControl = getControl();
323 // Ignore update if disposed
324 if (viewerControl.isDisposed()) {
325 return;
326 }
327
328 Display.getDefault().asyncExec(new Runnable() {
329 @Override
330 public void run() {
331 if (!viewerControl.isDisposed()) {
332 fPieChartViewer.refresh(refreshGlobal, refreshSelection);
333 }
334 }
335 });
336 }
337
338 /**
339 * Will force a request on the partial event count if one is needed.
340 */
341 public void sendPartialRequestOnNextUpdate() {
342 synchronized (fStatisticsRangeUpdateSyncObj) {
343 fSendRangeRequest = true;
344 }
345 }
346
347 /**
348 * Focus on the statistics tree of the viewer
349 */
350 public void setFocus() {
351 fTreeViewer.getTree().setFocus();
352 }
353
354 /**
355 * Cancels the request if it is not already completed
356 *
357 * @param request
358 * The request to be canceled
359 */
360 protected void cancelOngoingRequest(ITmfEventRequest request) {
361 if (request != null && !request.isCompleted()) {
362 request.cancel();
363 }
364 }
365
366 /**
367 * This method can be overridden to change the representation of the data in
368 * the columns.
369 *
370 * @return An object of type {@link TmfBaseColumnDataProvider}.
371 */
372 protected TmfBaseColumnDataProvider getColumnDataProvider() {
373 return new TmfBaseColumnDataProvider();
374 }
375
376 /**
377 * Initialize the content that will be drawn in this viewer
378 *
379 * @param parent
380 * The parent of the control to create
381 */
382 protected void initContent(Composite parent) {
383
384 final List<TmfBaseColumnData> columnDataList = getColumnDataProvider().getColumnData();
385
386 fSash = new SashForm(parent, SWT.HORIZONTAL );
387
388 fTreeViewer = new TreeViewer(fSash, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
389 fPieChartViewer = new TmfPieChartViewer(fSash);
390 fSash.setWeights(new int[]{100,100});
391
392 fTreeViewer.setContentProvider(new TmfTreeContentProvider());
393 fTreeViewer.getTree().setHeaderVisible(true);
394 fTreeViewer.setUseHashlookup(true);
395
396 // Creates the columns defined by the column data provider
397 for (final TmfBaseColumnData columnData : columnDataList) {
398 final TreeViewerColumn treeColumn = new TreeViewerColumn(fTreeViewer, columnData.getAlignment());
399 treeColumn.getColumn().setText(columnData.getHeader());
400 treeColumn.getColumn().setWidth(columnData.getWidth());
401 treeColumn.getColumn().setToolTipText(columnData.getTooltip());
402
403 // If is dummy column
404 if (columnData == columnDataList.get(TmfBaseColumnDataProvider.StatsColumn.DUMMY.getIndex())) {
405 treeColumn.getColumn().setResizable(false);
406 }
407
408 // A comparator is defined.
409 if (columnData.getComparator() != null) {
410 // Adds a listener on the columns header for sorting purpose.
411 treeColumn.getColumn().addSelectionListener(new SelectionAdapter() {
412
413 private ViewerComparator reverseComparator;
414
415 @Override
416 public void widgetSelected(SelectionEvent e) {
417 // Initializes the reverse comparator once.
418 if (reverseComparator == null) {
419 reverseComparator = new ViewerComparator() {
420 @Override
421 public int compare(Viewer viewer, Object e1, Object e2) {
422 return -1 * columnData.getComparator().compare(viewer, e1, e2);
423 }
424 };
425 }
426
427 if (fTreeViewer.getTree().getSortDirection() == SWT.UP
428 || fTreeViewer.getTree().getSortColumn() != treeColumn.getColumn()) {
429 /*
430 * Puts the descendant order if the old order was up
431 * or if the selected column has changed.
432 */
433 fTreeViewer.setComparator(columnData.getComparator());
434 fTreeViewer.getTree().setSortDirection(SWT.DOWN);
435 } else {
436 /*
437 * Puts the ascendant ordering if the selected
438 * column hasn't changed.
439 */
440 fTreeViewer.setComparator(reverseComparator);
441 fTreeViewer.getTree().setSortDirection(SWT.UP);
442 }
443 fTreeViewer.getTree().setSortColumn(treeColumn.getColumn());
444 }
445 });
446 }
447 treeColumn.setLabelProvider(columnData.getLabelProvider());
448 }
449
450 // Handler that will draw the percentages and the bar charts.
451 fTreeViewer.getTree().addListener(SWT.EraseItem, new Listener() {
452 @Override
453 public void handleEvent(Event event) {
454 if (columnDataList.get(event.index).getPercentageProvider() != null) {
455
456 TmfStatisticsTreeNode node = (TmfStatisticsTreeNode) event.item.getData();
457
458 // If node is hidden, exit immediately.
459 if (TmfBaseColumnDataProvider.HIDDEN_FOLDER_LEVELS.contains(node.getName())) {
460 return;
461 }
462
463 // Otherwise, get percentage and draw bar and text if applicable.
464 double percentage = columnDataList.get(event.index).getPercentageProvider().getPercentage(node);
465
466 // The item is selected.
467 if ((event.detail & SWT.SELECTED) > 0) {
468 // Draws our own background to avoid overwriting the bar.
469 event.gc.fillRectangle(event.x, event.y, event.width, event.height);
470 event.detail &= ~SWT.SELECTED;
471 }
472
473 // Drawing the percentage text
474 // if events are present in top node
475 // and the current node is not the top node
476 // and if is total or partial events column.
477 // If not, exit the method.
478 if (!((event.index == TmfBaseColumnDataProvider.StatsColumn.TOTAL.getIndex() || event.index == TmfBaseColumnDataProvider.StatsColumn.PARTIAL.getIndex())
479 && node != node.getTop())) {
480 return;
481 }
482
483 long eventValue = event.index == TmfBaseColumnDataProvider.StatsColumn.TOTAL.getIndex() ?
484 node.getTop().getValues().getTotal() : node.getTop().getValues().getPartial();
485
486 if (eventValue != 0) {
487
488 int oldAlpha = event.gc.getAlpha();
489 Color oldForeground = event.gc.getForeground();
490 Color oldBackground = event.gc.getBackground();
491
492 // Bar to draw
493 if (percentage != 0) {
494 /*
495 * Draws a transparent gradient rectangle from the
496 * color of foreground and background.
497 */
498 int barWidth = (int) ((fTreeViewer.getTree().getColumn(event.index).getWidth() - 8) * percentage);
499 event.gc.setAlpha(64);
500 event.gc.setForeground(event.item.getDisplay().getSystemColor(SWT.COLOR_BLUE));
501 event.gc.setBackground(event.item.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
502 event.gc.fillGradientRectangle(event.x, event.y, barWidth, event.height, true);
503 event.gc.drawRectangle(event.x, event.y, barWidth, event.height);
504
505 // Restore old values
506 event.gc.setBackground(oldBackground);
507 event.gc.setAlpha(oldAlpha);
508 event.detail &= ~SWT.BACKGROUND;
509
510 }
511
512 String percentageText = TmfStatisticsFormatter.toPercentageText(percentage);
513 String absoluteNumberText = TmfStatisticsFormatter.toColumnData(node, TmfBaseColumnDataProvider.StatsColumn.getColumn(event.index));
514
515 if (event.width > event.gc.stringExtent(percentageText).x + event.gc.stringExtent(absoluteNumberText).x) {
516 int textHeight = event.gc.stringExtent(percentageText).y;
517 event.gc.setForeground(event.item.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
518 event.gc.drawText(percentageText, event.x, event.y + (event.height - textHeight) / 2, true);
519 }
520
521 // Restores old values
522 event.gc.setForeground(oldForeground);
523
524 }
525 }
526 }
527
528 });
529
530 // Initializes the comparator parameters
531 fTreeViewer.setComparator(columnDataList.get(0).getComparator());
532 fTreeViewer.getTree().setSortColumn(fTreeViewer.getTree().getColumn(0));
533 fTreeViewer.getTree().setSortDirection(SWT.DOWN);
534 }
535
536 /**
537 * Initializes the input for the tree viewer.
538 */
539 protected void initInput() {
540 String treeID = getTreeID();
541 TmfStatisticsTreeNode statisticsTreeNode;
542 if (TmfStatisticsTreeManager.containsTreeRoot(treeID)) {
543 // The statistics root is already present
544 statisticsTreeNode = TmfStatisticsTreeManager.getStatTreeRoot(treeID);
545
546 // Checks if the trace is already in the statistics tree.
547 int numNodeTraces = statisticsTreeNode.getNbChildren();
548
549 Collection<ITmfTrace> traces = TmfTraceManager.getTraceSet(fTrace);
550 int numTraces = traces.size();
551
552 if (numTraces == numNodeTraces) {
553 boolean same = true;
554 /*
555 * Checks if the experiment contains the same traces as when
556 * previously selected.
557 */
558 for (ITmfTrace trace : traces) {
559 String traceName = trace.getName();
560 if (!statisticsTreeNode.containsChild(traceName)) {
561 same = false;
562 break;
563 }
564 }
565
566 if (same) {
567 // No need to reload data, all traces are already loaded
568 fTreeViewer.setInput(statisticsTreeNode);
569 return;
570 }
571 // Clears the old content to start over
572 statisticsTreeNode.reset();
573 }
574 } else {
575 // Creates a new tree
576 statisticsTreeNode = TmfStatisticsTreeManager.addStatsTreeRoot(treeID, getStatisticData());
577 }
578
579 // Sets the input to a clean data model
580 fTreeViewer.setInput(statisticsTreeNode);
581 /* Set a new model for the piecharts and keep a reference */
582 fPieChartViewer.setInput(getPieChartModel());
583 }
584
585 /**
586 * Tells if the viewer is listening to a trace.
587 *
588 * @param trace
589 * The trace that the viewer may be listening
590 * @return true if the viewer is listening to the trace, false otherwise
591 */
592 protected boolean isListeningTo(ITmfTrace trace) {
593 if (fProcessAll || trace == fTrace) {
594 return true;
595 }
596 return false;
597 }
598
599 /**
600 * Called when an trace request has been completed successfully.
601 *
602 * @param global
603 * Tells if the request is a global or time range (partial)
604 * request.
605 */
606 protected void modelComplete(boolean global) {
607 refreshTree();
608 waitCursor(false);
609 }
610
611 /**
612 * Sends the request to the trace for the whole trace
613 *
614 * @param trace
615 * The trace used to send the request
616 * @param timeRange
617 * The range to request to the trace
618 */
619 protected void requestData(final ITmfTrace trace, final TmfTimeRange timeRange) {
620 buildStatisticsTree(trace, timeRange, true);
621 }
622
623 /**
624 * Sends the time range request from the trace
625 *
626 * @param trace
627 * The trace used to send the request
628 * @param timeRange
629 * The range to request to the trace
630 */
631 protected void requestTimeRangeData(final ITmfTrace trace, final TmfTimeRange timeRange) {
632 buildStatisticsTree(trace, timeRange, false);
633 }
634
635 /**
636 * Requests all the data of the trace to the state system which contains
637 * information about the statistics.
638 *
639 * Since the viewer may be listening to multiple traces, it may receive an
640 * experiment rather than a single trace. The filtering is done with the
641 * method {@link #isListeningTo(String trace)}.
642 *
643 * @param trace
644 * The trace for which a request must be done
645 * @param timeRange
646 * The time range that will be requested to the state system
647 * @param isGlobal
648 * Tells if the request is for the global event count or the
649 * partial one.
650 */
651 private void buildStatisticsTree(final ITmfTrace trace, final TmfTimeRange timeRange, final boolean isGlobal) {
652 final TmfStatisticsTree statsData = TmfStatisticsTreeManager.getStatTree(getTreeID());
653 if (statsData == null) {
654 return;
655 }
656
657 Map<ITmfTrace, Job> updateJobs;
658 if (isGlobal) {
659 updateJobs = fUpdateJobsGlobal;
660 } else {
661 updateJobs = fUpdateJobsPartial;
662 }
663
664 for (ITmfTrace aTrace : TmfTraceManager.getTraceSet(trace)) {
665 aTrace = checkNotNull(aTrace);
666 if (!isListeningTo(aTrace)) {
667 continue;
668 }
669
670 /* Retrieve the statistics object */
671 final TmfStatisticsModule statsMod = TmfTraceUtils.getAnalysisModuleOfClass(aTrace, TmfStatisticsModule.class, TmfStatisticsModule.ID);
672 if (statsMod == null) {
673 /* No statistics module available for this trace */
674 continue;
675 }
676
677 Job job = updateJobs.get(aTrace);
678 if (job == null) {
679 job = new StatisticsUpdateJob("Statistics update", aTrace, isGlobal, timeRange, statsMod, this); //$NON-NLS-1$
680 updateJobs.put(aTrace, job);
681 job.setSystem(true);
682 job.schedule();
683 }
684 }
685 }
686
687 /**
688 * Resets the number of events within the time range
689 */
690 protected void resetTimeRangeValue() {
691 TmfStatisticsTreeNode treeModelRoot = TmfStatisticsTreeManager.getStatTreeRoot(getTreeID());
692 if (treeModelRoot != null && treeModelRoot.hasChildren()) {
693 treeModelRoot.resetTimeRangeValue();
694 }
695 }
696
697 /**
698 * When the trace is loading the cursor will be different so the user knows
699 * that the processing is not finished yet.
700 *
701 * Calls to this method are stacked.
702 *
703 * @param waitRequested
704 * Indicates if we need to show the waiting cursor, or the
705 * default one.
706 */
707 protected void waitCursor(final boolean waitRequested) {
708 if ((fTreeViewer == null) || (fTreeViewer.getTree().isDisposed())) {
709 return;
710 }
711
712 boolean needsUpdate = false;
713 Display display = fTreeViewer.getControl().getDisplay();
714 if (waitRequested) {
715 fWaitCursorCount++;
716 if (fWaitCursor == null) { // The cursor hasn't been initialized yet
717 fWaitCursor = new Cursor(display, SWT.CURSOR_WAIT);
718 }
719 if (fWaitCursorCount == 1) { // The cursor is not in waiting mode
720 needsUpdate = true;
721 }
722 } else {
723 if (fWaitCursorCount > 0) { // The cursor is in waiting mode
724 fWaitCursorCount--;
725 if (fWaitCursorCount == 0) { // No more reason to wait
726 // Put back the default cursor
727 needsUpdate = true;
728 }
729 }
730 }
731
732 if (needsUpdate) {
733 // Performs the updates on the UI thread
734 display.asyncExec(new Runnable() {
735 @Override
736 public void run() {
737 if ((fTreeViewer != null)
738 && (!fTreeViewer.getTree().isDisposed())) {
739 Cursor cursor = null; // indicates default
740 if (waitRequested) {
741 cursor = fWaitCursor;
742 }
743 fTreeViewer.getControl().setCursor(cursor);
744 }
745 }
746 });
747 }
748 }
749
750 /**
751 * @param isGlobal if the job to remove is global or partial
752 * @param jobTrace The trace
753 */
754 void removeFromJobs(boolean isGlobal, ITmfTrace jobTrace) {
755 Map<ITmfTrace, Job> updateJobs = isGlobal ? fUpdateJobsGlobal : fUpdateJobsPartial;
756 Job job = updateJobs.remove(jobTrace);
757 if (job != null) {
758 job.cancel();
759 }
760 }
761 }
This page took 0.054013 seconds and 5 git commands to generate.