Internalize some classes and fix a pile of warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / environment / TmfEnvironmentView.java
CommitLineData
ce2388e0
FC
1package org.eclipse.linuxtools.tmf.ui.views.environment;
2
3import java.util.ArrayList;
4
5import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
6import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
7import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
ce2388e0
FC
8import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal;
9import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
10import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
9e0640dc 11import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
ce2388e0
FC
12import org.eclipse.linuxtools.tmf.ui.views.TmfView;
13import org.eclipse.swt.SWT;
14import org.eclipse.swt.widgets.Composite;
15import org.eclipse.swt.widgets.Table;
16import org.eclipse.swt.widgets.TableColumn;
17import org.eclipse.swt.widgets.TableItem;
18
19public class TmfEnvironmentView extends TmfView {
20
21 public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.environment"; //$NON-NLS-1$
22 private TmfExperiment<?> fExperiment;
23 private Table fTable;
8fd82db5 24// final private String fTitlePrefix;
ce2388e0
FC
25 private Composite fParent;
26
27 public TmfEnvironmentView() {
28 super("EnvironmentVariables"); //$NON-NLS-1$
8fd82db5 29// fTitlePrefix = getTitle();
ce2388e0
FC
30 }
31
32 // ------------------------------------------------------------------------
33 // ViewPart
34 // ------------------------------------------------------------------------
35 final private class Pair{
36 final private String key;
37 final private String value;
38 public Pair(String k) { key = k ; value = "";} //$NON-NLS-1$
39 public Pair(String k, String v){ key = k; value = v; }
40 public String getKey() { return key; }
41 public String getValue() { return value; }
42 }
43
44 @Override
8fd82db5 45 @SuppressWarnings({ "unchecked", "rawtypes" })
ce2388e0
FC
46 public void createPartControl(Composite parent) {
47 fParent = parent;
48 TableItem ti[];
49 // If an experiment is already selected, update the table
50 TmfExperiment<ITmfEvent> experiment = (TmfExperiment<ITmfEvent>) TmfExperiment
51 .getCurrentExperiment();
52 if (experiment == null) {
53 return;
54 }
55 fTable = new Table(parent, SWT.BORDER|SWT.FILL);
56
57
58 ArrayList<Pair> tableData = new ArrayList<Pair>();
59 for (ITmfTrace trace : experiment.getTraces()) {
60 Pair traceEntry = new Pair(trace.getName());
61 tableData.add(traceEntry);
62 if (trace instanceof CtfTmfTrace) {
63 CtfTmfTrace ctfTrace = (CtfTmfTrace) trace;
64 for (String varName : ctfTrace
65 .getEnvNames()) {
66 tableData.add(new Pair( varName, ctfTrace.getEnvValue(varName)));
67 }
68 }
69 }
70 TableColumn nameCol = new TableColumn(fTable, SWT.NONE, 0);
71 TableColumn valueCol = new TableColumn(fTable, SWT.NONE, 1);
72 nameCol.setText("Environment Variable"); //$NON-NLS-1$
73 valueCol.setText("Value"); //$NON-NLS-1$
74
75 final int tableSize = tableData.size();
76
77 fTable.setItemCount(tableSize);
78 ti = fTable.getItems();
79 for(int i = 0; i < tableSize; i++){
80 final Pair currentPair = tableData.get(i);
81 ti[i].setText(0, currentPair.getKey());
82 ti[i].setText(1, currentPair.getValue());
83 }
84
85 fTable.setHeaderVisible(true);
86 nameCol.pack();
87 valueCol.pack();
88 fTable.pack();
89
90 parent.layout();
91
92 }
93
94 /* (non-Javadoc)
95 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
96 */
97 @Override
98 public void setFocus() {
99 fTable.setFocus();
100 }
101
102 @Override
103 public void dispose() {
104 if (fTable != null) {
105 fTable.dispose();
106 }
107 super.dispose();
108 }
109
110 @SuppressWarnings("unchecked")
111 @TmfSignalHandler
112 public void experimentSelected(TmfExperimentSelectedSignal<TmfEvent> signal) {
113 // Update the trace reference
114 TmfExperiment<TmfEvent> exp = (TmfExperiment<TmfEvent>) signal.getExperiment();
115 if (!exp.equals(fExperiment)) {
116 fExperiment = exp;
117 if (fTable != null) {
118 fTable.dispose();
119 }
120 createPartControl( fParent );
121 fParent.layout();
122 }
123 }
124
125
126}
This page took 0.031041 seconds and 5 git commands to generate.