Commit | Line | Data |
---|---|---|
00511ef2 FC |
1 | /******************************************************************************* |
2 | * Copyright (c) 2012 Ericsson | |
013a5f1c | 3 | * |
00511ef2 FC |
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 | |
013a5f1c | 8 | * |
00511ef2 FC |
9 | * Contributors: |
10 | * Matthew Khouzam - Initial API and implementation | |
be13f349 | 11 | * Bernd Hufmann - Updated to use Tree with columns to be able to group traces |
00511ef2 | 12 | *******************************************************************************/ |
ce2388e0 FC |
13 | package org.eclipse.linuxtools.tmf.ui.views.environment; |
14 | ||
ce2388e0 | 15 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; |
ce2388e0 | 16 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; |
faa38350 PT |
17 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal; |
18 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal; | |
ce2388e0 FC |
19 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
20 | import org.eclipse.linuxtools.tmf.ui.views.TmfView; | |
21 | import org.eclipse.swt.SWT; | |
22 | import org.eclipse.swt.widgets.Composite; | |
be13f349 BH |
23 | import org.eclipse.swt.widgets.Tree; |
24 | import org.eclipse.swt.widgets.TreeColumn; | |
25 | import org.eclipse.swt.widgets.TreeItem; | |
ce2388e0 | 26 | |
00511ef2 FC |
27 | /** |
28 | * Displays the CTF trace properties. | |
013a5f1c | 29 | * |
be13f349 | 30 | * @version 1.1 |
00511ef2 FC |
31 | * @author Matthew Khouzam |
32 | */ | |
ce2388e0 FC |
33 | public class TmfEnvironmentView extends TmfView { |
34 | ||
013a5f1c | 35 | /** The Environment View's ID */ |
ce2388e0 | 36 | public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.environment"; //$NON-NLS-1$ |
013a5f1c | 37 | |
faa38350 | 38 | private ITmfTrace fTrace; |
be13f349 | 39 | private Tree fTree; |
ce2388e0 | 40 | |
013a5f1c AM |
41 | /** |
42 | * Default constructor | |
43 | */ | |
ce2388e0 FC |
44 | public TmfEnvironmentView() { |
45 | super("EnvironmentVariables"); //$NON-NLS-1$ | |
8fd82db5 | 46 | // fTitlePrefix = getTitle(); |
ce2388e0 FC |
47 | } |
48 | ||
49 | // ------------------------------------------------------------------------ | |
50 | // ViewPart | |
51 | // ------------------------------------------------------------------------ | |
ce2388e0 FC |
52 | |
53 | @Override | |
ce2388e0 | 54 | public void createPartControl(Composite parent) { |
be13f349 BH |
55 | fTree = new Tree(parent, SWT.NONE); |
56 | TreeColumn nameCol = new TreeColumn(fTree, SWT.NONE, 0); | |
57 | TreeColumn valueCol = new TreeColumn(fTree, SWT.NONE, 1); | |
ce2388e0 FC |
58 | nameCol.setText("Environment Variable"); //$NON-NLS-1$ |
59 | valueCol.setText("Value"); //$NON-NLS-1$ | |
60 | ||
be13f349 | 61 | fTree.setItemCount(0); |
ce2388e0 | 62 | |
be13f349 | 63 | fTree.setHeaderVisible(true); |
ce2388e0 FC |
64 | nameCol.pack(); |
65 | valueCol.pack(); | |
ce2388e0 | 66 | |
3ac5721a AM |
67 | ITmfTrace trace = getActiveTrace(); |
68 | if (trace != null) { | |
69 | traceSelected(new TmfTraceSelectedSignal(this, trace)); | |
faa38350 PT |
70 | } |
71 | } | |
72 | ||
73 | private void updateTable() { | |
be13f349 | 74 | fTree.setItemCount(0); |
faa38350 PT |
75 | if (fTrace == null) { |
76 | return; | |
77 | } | |
be13f349 | 78 | |
fe0c44c4 | 79 | ITmfTrace[] traces = fTrace.getTraces(); |
be13f349 | 80 | |
faa38350 | 81 | for (ITmfTrace trace : traces) { |
faa38350 | 82 | if (trace instanceof CtfTmfTrace) { |
be13f349 BH |
83 | TreeItem item = new TreeItem(fTree, SWT.NONE); |
84 | item.setText(0, trace.getName()); | |
faa38350 PT |
85 | CtfTmfTrace ctfTrace = (CtfTmfTrace) trace; |
86 | for (String varName : ctfTrace.getEnvNames()) { | |
be13f349 BH |
87 | TreeItem subItem = new TreeItem(item, SWT.NONE); |
88 | subItem.setText(0, varName); | |
89 | subItem.setText(1, ctfTrace.getEnvValue(varName)); | |
faa38350 PT |
90 | } |
91 | } | |
92 | } | |
93 | ||
be13f349 BH |
94 | // Expand the tree items |
95 | for (int i = 0; i < fTree.getItemCount(); i++) { | |
96 | fTree.getItem(i).setExpanded(true); | |
faa38350 PT |
97 | } |
98 | ||
be13f349 | 99 | for (TreeColumn column : fTree.getColumns()) { |
faa38350 PT |
100 | column.pack(); |
101 | } | |
ce2388e0 FC |
102 | } |
103 | ||
104 | /* (non-Javadoc) | |
105 | * @see org.eclipse.ui.part.WorkbenchPart#setFocus() | |
106 | */ | |
107 | @Override | |
108 | public void setFocus() { | |
be13f349 | 109 | fTree.setFocus(); |
ce2388e0 FC |
110 | } |
111 | ||
013a5f1c | 112 | /** |
faa38350 | 113 | * Handler for the trace selected signal. |
013a5f1c AM |
114 | * |
115 | * @param signal | |
116 | * The incoming signal | |
faa38350 | 117 | * @since 2.0 |
013a5f1c | 118 | */ |
ce2388e0 | 119 | @TmfSignalHandler |
faa38350 | 120 | public void traceSelected(TmfTraceSelectedSignal signal) { |
ce2388e0 | 121 | // Update the trace reference |
faa38350 PT |
122 | ITmfTrace trace = signal.getTrace(); |
123 | if (!trace.equals(fTrace)) { | |
124 | fTrace = trace; | |
125 | updateTable(); | |
ce2388e0 FC |
126 | } |
127 | } | |
128 | ||
ea279a69 | 129 | /** |
faa38350 PT |
130 | * Handler for the trace closed signal. |
131 | * | |
ea279a69 FC |
132 | * @param signal the incoming signal |
133 | * @since 2.0 | |
134 | */ | |
135 | @TmfSignalHandler | |
faa38350 PT |
136 | public void traceClosed(TmfTraceClosedSignal signal) { |
137 | if (signal.getTrace() == fTrace) { | |
138 | fTrace = null; | |
be13f349 | 139 | fTree.setItemCount(0); |
faa38350 | 140 | } |
ea279a69 | 141 | } |
ce2388e0 FC |
142 | |
143 | } | |
be13f349 | 144 |