~ubuntu-branches/ubuntu/vivid/eclipse-linuxtools/vivid-proposed

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramView.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam, Jakub Adam, tony mancill
  • Date: 2014-10-11 11:44:05 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20141011114405-yazjvxfzzhmi5sgj
Tags: 3.1.0-1
[ Jakub Adam ]
* New upstream release (Closes: #761524).
* Refreshed d/patches.
* Don't build removed feature org.eclipse.linuxtools.tools.launch
  - merged into org.eclipse.linuxtools.profiling.
* Use javac target 1.7.
* Build new feature org.eclipse.linuxtools.dataviewers.feature
  - required by Valgrind integration.
* Build-depend on eclipse-remote-services-api and eclipse-cdt-autotools.
* Bump Standards-Version to 3.9.6.
* Override incompatible-java-bytecode-format - linuxtools needs Java 7.
* Remove unused codeless-jar override.

[ tony mancill ]
* Tweak short package description to make lintian happy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 *   Francois Chouinard - Cleanup and refactoring
15
15
 *   Francois Chouinard - Moved from LTTng to TMF
16
16
 *   Patrick Tasse - Update for mouse wheel zoom
 
17
 *   Xavier Raynaud - Support multi-trace coloring
17
18
 *******************************************************************************/
18
19
 
19
20
package org.eclipse.linuxtools.tmf.ui.views.histogram;
20
21
 
 
22
import org.eclipse.jdt.annotation.NonNull;
21
23
import org.eclipse.jface.action.Action;
22
24
import org.eclipse.jface.action.IAction;
23
25
import org.eclipse.jface.action.Separator;
24
26
import org.eclipse.linuxtools.internal.tmf.ui.Activator;
25
27
import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants;
26
 
import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest.ExecutionType;
27
 
import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
 
28
import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
 
29
import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest.ExecutionType;
28
30
import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;
29
31
import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
30
32
import org.eclipse.linuxtools.tmf.core.signal.TmfSignalThrottler;
38
40
import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
39
41
import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
40
42
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 
43
import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
41
44
import org.eclipse.linuxtools.tmf.ui.views.TmfView;
42
45
import org.eclipse.swt.SWT;
 
46
import org.eclipse.swt.custom.CLabel;
43
47
import org.eclipse.swt.events.MouseAdapter;
44
48
import org.eclipse.swt.events.MouseEvent;
45
49
import org.eclipse.swt.events.MouseWheelListener;
46
50
import org.eclipse.swt.events.PaintEvent;
47
51
import org.eclipse.swt.events.PaintListener;
 
52
import org.eclipse.swt.graphics.GC;
48
53
import org.eclipse.swt.graphics.Image;
49
54
import org.eclipse.swt.graphics.Rectangle;
50
55
import org.eclipse.swt.layout.GridData;
51
56
import org.eclipse.swt.layout.GridLayout;
 
57
import org.eclipse.swt.layout.RowLayout;
52
58
import org.eclipse.swt.widgets.Composite;
 
59
import org.eclipse.swt.widgets.Control;
53
60
import org.eclipse.swt.widgets.Display;
54
61
import org.eclipse.swt.widgets.Label;
55
62
import org.eclipse.ui.IActionBars;
78
85
    /**
79
86
     *  The view ID as defined in plugin.xml
80
87
     */
81
 
    public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.histogram"; //$NON-NLS-1$
 
88
    public static final @NonNull String ID = "org.eclipse.linuxtools.tmf.ui.views.histogram"; //$NON-NLS-1$
82
89
 
83
90
    private static final Image LINK_IMG = Activator.getDefault().getImageFromPath("/icons/etool16/link.gif"); //$NON-NLS-1$
84
91
 
118
125
    private static TimeRangeHistogram fTimeRangeHistogram;
119
126
    private HistogramRequest fTimeRangeRequest;
120
127
 
 
128
    // Legend area
 
129
    private Composite fLegendArea;
 
130
    private Image[] fLegendImages;
 
131
 
121
132
    // Throttlers for the time sync and time-range sync signals
122
133
    private final TmfSignalThrottler fTimeSyncThrottle;
123
134
    private final TmfSignalThrottler fTimeRangeSyncThrottle;
124
135
 
125
136
    // Action for toggle showing the lost events
126
137
    private Action hideLostEventsAction;
 
138
    // Action for toggle showing the traces
 
139
    private Action showTraceAction;
127
140
 
128
141
    // ------------------------------------------------------------------------
129
142
    // Constructor
291
304
        // Histogram
292
305
        fFullTraceHistogram = new FullTraceHistogram(this, fullRangeComposite);
293
306
 
 
307
        fLegendArea = new Composite(viewComposite, SWT.FILL);
 
308
        fLegendArea.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false, 2, 1));
 
309
        fLegendArea.setLayout(new RowLayout());
 
310
 
294
311
        // Add mouse wheel listener to time span control
295
312
        MouseWheelListener listener = fFullTraceHistogram.getZoom();
296
313
        fTimeSpanControl.addMouseWheelListener(listener);
354
371
                public void run() {
355
372
                    HistogramScaledData.hideLostEvents = hideLostEventsAction.isChecked();
356
373
                    long maxNbEvents = HistogramScaledData.hideLostEvents ? fFullTraceHistogram.fScaledData.fMaxValue : fFullTraceHistogram.fScaledData.fMaxCombinedValue;
357
 
                    fFullTraceHistogram.getMaxNbEventsText().setText(Long.toString(maxNbEvents));
358
 
                    fFullTraceHistogram.getMaxNbEventsText().getParent().layout();
359
 
                    fFullTraceHistogram.fCanvas.redraw();
 
374
                    fFullTraceHistogram.setMaxNbEvents(maxNbEvents);
360
375
                    maxNbEvents = HistogramScaledData.hideLostEvents ? fTimeRangeHistogram.fScaledData.fMaxValue : fTimeRangeHistogram.fScaledData.fMaxCombinedValue;
361
 
                    fTimeRangeHistogram.getMaxNbEventsText().setText(Long.toString(maxNbEvents));
362
 
                    fTimeRangeHistogram.getMaxNbEventsText().getParent().layout();
363
 
                    fTimeRangeHistogram.fCanvas.redraw();
 
376
                    fTimeRangeHistogram.setMaxNbEvents(maxNbEvents);
364
377
                }
365
378
            };
366
379
            hideLostEventsAction.setText(Messages.HistogramView_hideLostEvents);
370
383
        return hideLostEventsAction;
371
384
    }
372
385
 
 
386
    /**
 
387
     * get the show trace action
 
388
     *
 
389
     * @return The action object
 
390
     * @since 3.0
 
391
     */
 
392
    public Action getShowTraceAction() {
 
393
        if (showTraceAction == null) {
 
394
            /* show lost events */
 
395
            showTraceAction = new Action(Messages.HistogramView_showTraces, IAction.AS_CHECK_BOX) {
 
396
                @Override
 
397
                public void run() {
 
398
                    Histogram.showTraces = showTraceAction.isChecked();
 
399
                    fFullTraceHistogram.fCanvas.redraw();
 
400
                    fTimeRangeHistogram.fCanvas.redraw();
 
401
                    updateLegendArea();
 
402
                }
 
403
            };
 
404
            showTraceAction.setChecked(true);
 
405
            showTraceAction.setText(Messages.HistogramView_showTraces);
 
406
            showTraceAction.setToolTipText(Messages.HistogramView_showTraces);
 
407
            showTraceAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SHOW_HIST_TRACES));
 
408
        }
 
409
        return showTraceAction;
 
410
    }
 
411
 
373
412
    // ------------------------------------------------------------------------
374
413
    // Operations
375
414
    // ------------------------------------------------------------------------
537
576
        fSelectionEndControl.setValue(Long.MIN_VALUE);
538
577
 
539
578
        fTimeSpanControl.setValue(Long.MIN_VALUE);
 
579
 
 
580
        for (Control c: fLegendArea.getChildren()) {
 
581
            c.dispose();
 
582
        }
 
583
        if (fLegendImages != null) {
 
584
            for (Image i: fLegendImages) {
 
585
                i.dispose();
 
586
            }
 
587
        }
 
588
        fLegendImages = null;
 
589
        fLegendArea.layout();
 
590
        fLegendArea.getParent().layout();
540
591
    }
541
592
 
542
593
    /**
671
722
        fTimeRangeHistogram.setFullRange(fTraceStartTime, fTraceEndTime);
672
723
        fTimeRangeHistogram.setTimeRange(startTime, duration);
673
724
        fTimeRangeHistogram.setSelection(selectionBeginTime, selectionEndTime);
 
725
        fTimeRangeHistogram.fDataModel.setTrace(fTrace);
674
726
 
675
727
        if ((fFullTraceRequest != null) && !fFullTraceRequest.isCompleted()) {
676
728
            fFullTraceRequest.cancel();
679
731
        fFullTraceHistogram.setFullRange(fTraceStartTime, fTraceEndTime);
680
732
        fFullTraceHistogram.setTimeRange(startTime, duration);
681
733
        fFullTraceHistogram.setSelection(selectionBeginTime, selectionEndTime);
 
734
        fFullTraceHistogram.fDataModel.setTrace(fTrace);
682
735
 
683
736
        fWindowStartTime = startTime;
684
737
        fWindowSpan = duration;
691
744
 
692
745
        fTimeSpanControl.setValue(duration);
693
746
 
 
747
        ITmfTrace[] traces = TmfTraceManager.getTraceSet(fTrace);
 
748
        if (traces != null) {
 
749
            this.showTraceAction.setEnabled(traces.length < fFullTraceHistogram.getMaxNbTraces());
 
750
        }
 
751
        updateLegendArea();
 
752
 
694
753
        if (!fullRange.equals(TmfTimeRange.NULL_RANGE)) {
695
754
            sendTimeRangeRequest(startTime, startTime + duration);
696
755
            sendFullRangeRequest(fullRange);
697
756
        }
698
757
    }
699
758
 
 
759
    private void updateLegendArea() {
 
760
        for (Control c: fLegendArea.getChildren()) {
 
761
            c.dispose();
 
762
        }
 
763
        if (fLegendImages != null) {
 
764
            for (Image i: fLegendImages) {
 
765
                i.dispose();
 
766
            }
 
767
        }
 
768
        fLegendImages = null;
 
769
        if (fFullTraceHistogram.showTraces()) {
 
770
            ITmfTrace[] traces = TmfTraceManager.getTraceSet(fTrace);
 
771
            fLegendImages = new Image[traces.length];
 
772
            int traceIndex = 0;
 
773
            for (ITmfTrace trace : traces) {
 
774
                fLegendImages[traceIndex] = new Image(fLegendArea.getDisplay(), 16, 16);
 
775
                GC gc = new GC(fLegendImages[traceIndex]);
 
776
                gc.setBackground(fFullTraceHistogram.getTraceColor(traceIndex));
 
777
                gc.fillRectangle(0, 0, 15, 15);
 
778
                gc.setForeground(fLegendArea.getDisplay().getSystemColor(SWT.COLOR_BLACK));
 
779
                gc.drawRectangle(0, 0, 15, 15);
 
780
                gc.dispose();
 
781
 
 
782
                CLabel label = new CLabel(fLegendArea, SWT.NONE);
 
783
                label.setText(trace.getName());
 
784
                label.setImage(fLegendImages[traceIndex]);
 
785
                traceIndex++;
 
786
            }
 
787
        }
 
788
        fLegendArea.layout();
 
789
        fLegendArea.getParent().layout();
 
790
    }
 
791
 
700
792
    private void updateDisplayedSelectionTime(long beginTime, long endTime) {
701
793
        fSelectionBeginTime = beginTime;
702
794
        fSelectionEndTime = endTime;
739
831
        fTimeRangeHistogram.setTimeRange(startTime, endTime - startTime);
740
832
 
741
833
        int cacheSize = fTrace.getCacheSize();
742
 
        fTimeRangeRequest = new HistogramRequest(fTimeRangeHistogram.getDataModel(), timeRange, 0, TmfDataRequest.ALL_DATA, cacheSize, ExecutionType.FOREGROUND, false);
 
834
        fTimeRangeRequest = new HistogramRequest(fTimeRangeHistogram.getDataModel(),
 
835
                timeRange, 0, ITmfEventRequest.ALL_DATA, cacheSize, ExecutionType.FOREGROUND, false);
743
836
        fTrace.sendRequest(fTimeRangeRequest);
744
837
    }
745
838
 
748
841
            fFullTraceRequest.cancel();
749
842
        }
750
843
        int cacheSize = fTrace.getCacheSize();
751
 
        fFullTraceRequest = new HistogramRequest(fFullTraceHistogram.getDataModel(), fullRange, (int) fFullTraceHistogram.fDataModel.getNbEvents(),
752
 
                TmfDataRequest.ALL_DATA, cacheSize, ExecutionType.BACKGROUND, true);
 
844
        fFullTraceRequest = new HistogramRequest(fFullTraceHistogram.getDataModel(),
 
845
                fullRange,
 
846
                (int) fFullTraceHistogram.fDataModel.getNbEvents(),
 
847
                ITmfEventRequest.ALL_DATA,
 
848
                cacheSize,
 
849
                ExecutionType.BACKGROUND, true);
753
850
        fTrace.sendRequest(fFullTraceRequest);
754
851
    }
755
852
 
756
853
    private void contributeToActionBars() {
757
854
        IActionBars bars = getViewSite().getActionBars();
758
855
        bars.getToolBarManager().add(getShowLostEventsAction());
 
856
        bars.getToolBarManager().add(getShowTraceAction());
759
857
        bars.getToolBarManager().add(new Separator());
760
858
    }
761
859