d2d8a1ed2320134f315da27b6e415b9f2d3f8cd1
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.ui / src / org / eclipse / linuxtools / internal / lttng2 / kernel / ui / views / cpuusage / CpuUsageView.java
1 /*******************************************************************************
2 * Copyright (c) 2014 École Polytechnique de Montréal
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 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.cpuusage;
14
15 import org.eclipse.jface.viewers.ISelection;
16 import org.eclipse.jface.viewers.ISelectionChangedListener;
17 import org.eclipse.jface.viewers.IStructuredSelection;
18 import org.eclipse.jface.viewers.SelectionChangedEvent;
19 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal;
20 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
21 import org.eclipse.linuxtools.tmf.ui.views.TmfView;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.custom.SashForm;
24 import org.eclipse.swt.layout.FillLayout;
25 import org.eclipse.swt.widgets.Composite;
26
27 /**
28 * CPU usage view. It contains 2 viewers: one tree viewer showing all the
29 * threads who were on the CPU in the time range, and one XY chart viewer
30 * plotting the total time spent on CPU and the time of the threads selected in
31 * the tree viewer.
32 *
33 * @author Geneviève Bastien
34 */
35 public class CpuUsageView extends TmfView {
36
37 /** ID string */
38 public static final String ID = "org.eclipse.linuxtools.lttng2.kernel.ui.views.cpuusage"; //$NON-NLS-1$
39
40 private CpuUsageComposite fTreeViewer = null;
41 private CpuUsageXYViewer fXYViewer = null;
42
43 /**
44 * Constructor
45 */
46 public CpuUsageView() {
47 super(Messages.CpuUsageView_Title);
48 }
49
50 @Override
51 public void createPartControl(Composite parent) {
52
53 final SashForm sash = new SashForm(parent, SWT.NONE);
54
55 fTreeViewer = new CpuUsageComposite(sash);
56
57 /* Build the XY chart part of the view */
58 fXYViewer = new CpuUsageXYViewer(sash);
59
60 /* Add selection listener to tree viewer */
61 fTreeViewer.addSelectionChangeListener(new ISelectionChangedListener() {
62 @Override
63 public void selectionChanged(SelectionChangedEvent event) {
64 ISelection selection = event.getSelection();
65 if (selection instanceof IStructuredSelection) {
66 Object structSelection = ((IStructuredSelection) selection).getFirstElement();
67 if (structSelection instanceof CpuUsageEntry) {
68 CpuUsageEntry entry = (CpuUsageEntry) structSelection;
69 fTreeViewer.setSelectedThread(entry.getTid());
70 fXYViewer.setSelectedThread(Long.valueOf(entry.getTid()));
71 }
72 }
73 }
74 });
75
76 sash.setLayout(new FillLayout());
77
78 /* Initialize the viewers with the currently selected trace */
79 ITmfTrace trace = getActiveTrace();
80 if (trace != null) {
81 TmfTraceSelectedSignal signal = new TmfTraceSelectedSignal(this, trace);
82 fTreeViewer.traceSelected(signal);
83 fXYViewer.traceSelected(signal);
84 }
85
86 }
87
88 @Override
89 public void setFocus() {
90 }
91
92 @Override
93 public void dispose() {
94 super.dispose();
95 if (fTreeViewer != null) {
96 fTreeViewer.dispose();
97 }
98 if (fXYViewer != null) {
99 fXYViewer.dispose();
100 }
101 }
102
103 }
This page took 0.032862 seconds and 4 git commands to generate.