~ubuntu-branches/ubuntu/utopic/eclipse-linuxtools/utopic

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/environment/TmfEnvironmentView.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2014-05-12 18:11:40 UTC
  • mfrom: (3.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140512181140-w237r3vsah1tmybz
Tags: 2.2.1-1
* New upstream release.
* Refreshed d/patches.
* Removed eclipse-cdt-valgrind-remote package, all its functionality
  is now provided by eclipse-cdt-profiling-framework-remote.
* Added remove-license-feature.patch.
* Bump Standards-Version to 3.9.5.
* Enable eclipse-changelog package.
* Enable eclipse-rpm-editor package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*******************************************************************************
2
 
 * Copyright (c) 2012 Ericsson
 
2
 * Copyright (c) 2012, 2013 Ericsson
3
3
 *
4
4
 * All rights reserved. This program and the accompanying materials are
5
5
 * made available under the terms of the Eclipse Public License v1.0 which
8
8
 *
9
9
 * Contributors:
10
10
 *   Matthew Khouzam - Initial API and implementation
 
11
 *   Bernd Hufmann - Updated to use Tree with columns to be able to group traces
 
12
 *   Alexandre Montplaisir - Display info for any ITmfTraceProperties trace
11
13
 *******************************************************************************/
 
14
 
12
15
package org.eclipse.linuxtools.tmf.ui.views.environment;
13
16
 
14
 
import java.util.ArrayList;
 
17
import java.util.Map;
15
18
 
16
 
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
17
 
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
18
 
import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
19
 
import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal;
20
19
import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
 
20
import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal;
 
21
import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
 
22
import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal;
 
23
import org.eclipse.linuxtools.tmf.core.trace.ITmfTraceProperties;
21
24
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
22
 
import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
 
25
import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
23
26
import org.eclipse.linuxtools.tmf.ui.views.TmfView;
24
27
import org.eclipse.swt.SWT;
25
28
import org.eclipse.swt.widgets.Composite;
26
 
import org.eclipse.swt.widgets.Table;
27
 
import org.eclipse.swt.widgets.TableColumn;
28
 
import org.eclipse.swt.widgets.TableItem;
 
29
import org.eclipse.swt.widgets.Tree;
 
30
import org.eclipse.swt.widgets.TreeColumn;
 
31
import org.eclipse.swt.widgets.TreeItem;
29
32
 
30
33
/**
31
 
 * Displays the CTF trace properties.
 
34
 * Displays the trace's properties.
32
35
 *
33
 
 * @version 1.0
 
36
 * @version 1.1
34
37
 * @author Matthew Khouzam
35
38
 */
36
39
public class TmfEnvironmentView extends TmfView {
38
41
    /** The Environment View's ID */
39
42
    public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.environment"; //$NON-NLS-1$
40
43
 
41
 
    private TmfExperiment<?> fExperiment;
42
 
    private Table fTable;
43
 
//    final private String fTitlePrefix;
44
 
    private Composite fParent;
 
44
    private ITmfTrace fTrace;
 
45
    private Tree fTree;
45
46
 
46
47
    /**
47
48
     * Default constructor
54
55
    // ------------------------------------------------------------------------
55
56
    // ViewPart
56
57
    // ------------------------------------------------------------------------
57
 
    final private class Pair{
58
 
        final private String key;
59
 
        final private String value;
60
 
        public Pair(String k) { key = k ; value = "";} //$NON-NLS-1$
61
 
        public Pair(String k, String v){ key = k; value = v; }
62
 
        public String getKey() { return key; }
63
 
        public String getValue() { return value; }
64
 
    }
65
58
 
66
59
    @Override
67
 
    @SuppressWarnings({ "unchecked", "rawtypes" })
68
60
    public void createPartControl(Composite parent) {
69
 
        fParent = parent;
70
 
        TableItem ti[];
71
 
        // If an experiment is already selected, update the table
72
 
        TmfExperiment<ITmfEvent> experiment = (TmfExperiment<ITmfEvent>) TmfExperiment
73
 
                .getCurrentExperiment();
74
 
        if (experiment == null) {
75
 
            return;
76
 
        }
77
 
        fTable = new Table(parent, SWT.BORDER|SWT.FILL);
78
 
 
79
 
 
80
 
        ArrayList<Pair> tableData = new ArrayList<Pair>();
81
 
        for (ITmfTrace trace : experiment.getTraces()) {
82
 
            Pair traceEntry = new Pair(trace.getName());
83
 
            tableData.add(traceEntry);
84
 
            if (trace instanceof CtfTmfTrace) {
85
 
                CtfTmfTrace ctfTrace = (CtfTmfTrace) trace;
86
 
                for (String varName : ctfTrace
87
 
                        .getEnvNames()) {
88
 
                    tableData.add(new Pair( varName, ctfTrace.getEnvValue(varName)));
89
 
                }
90
 
            }
91
 
        }
92
 
        TableColumn nameCol = new TableColumn(fTable, SWT.NONE, 0);
93
 
        TableColumn valueCol = new TableColumn(fTable, SWT.NONE, 1);
 
61
        fTree = new Tree(parent, SWT.NONE);
 
62
        TreeColumn nameCol = new TreeColumn(fTree, SWT.NONE, 0);
 
63
        TreeColumn valueCol = new TreeColumn(fTree, SWT.NONE, 1);
94
64
        nameCol.setText("Environment Variable"); //$NON-NLS-1$
95
65
        valueCol.setText("Value"); //$NON-NLS-1$
96
66
 
97
 
        final int tableSize = tableData.size();
98
 
 
99
 
        fTable.setItemCount(tableSize);
100
 
        ti = fTable.getItems();
101
 
        for(int i = 0; i < tableSize; i++){
102
 
            final Pair currentPair = tableData.get(i);
103
 
            ti[i].setText(0, currentPair.getKey());
104
 
            ti[i].setText(1, currentPair.getValue());
105
 
        }
106
 
 
107
 
        fTable.setHeaderVisible(true);
 
67
        fTree.setItemCount(0);
 
68
 
 
69
        fTree.setHeaderVisible(true);
108
70
        nameCol.pack();
109
71
        valueCol.pack();
110
 
        fTable.pack();
111
 
 
112
 
        parent.layout();
113
 
 
114
 
    }
115
 
 
116
 
    /* (non-Javadoc)
117
 
     * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
118
 
     */
 
72
 
 
73
        ITmfTrace trace = getActiveTrace();
 
74
        if (trace != null) {
 
75
            traceSelected(new TmfTraceSelectedSignal(this, trace));
 
76
        }
 
77
    }
 
78
 
 
79
    private void updateTable() {
 
80
        fTree.setItemCount(0);
 
81
        if (fTrace == null) {
 
82
            return;
 
83
        }
 
84
 
 
85
        for (ITmfTrace trace : TmfTraceManager.getTraceSet(fTrace)) {
 
86
            if (trace instanceof ITmfTraceProperties) {
 
87
                TreeItem item = new TreeItem(fTree, SWT.NONE);
 
88
                item.setText(0, trace.getName());
 
89
 
 
90
                ITmfTraceProperties propTrace = (ITmfTraceProperties) trace;
 
91
                Map <String, String> properties = propTrace.getTraceProperties();
 
92
                for (Map.Entry<String, String> entry : properties.entrySet()) {
 
93
                    TreeItem subItem = new TreeItem(item, SWT.NONE);
 
94
                    subItem.setText(0, entry.getKey()); // Variable name
 
95
                    subItem.setText(1, entry.getValue()); // Variable value
 
96
                }
 
97
            }
 
98
        }
 
99
 
 
100
        // Expand the tree items
 
101
        for (int i = 0; i < fTree.getItemCount(); i++) {
 
102
            fTree.getItem(i).setExpanded(true);
 
103
        }
 
104
 
 
105
        for (TreeColumn column : fTree.getColumns()) {
 
106
            column.pack();
 
107
        }
 
108
    }
 
109
 
119
110
    @Override
120
111
    public void setFocus() {
121
 
        fTable.setFocus();
122
 
    }
123
 
 
124
 
    @Override
125
 
    public void dispose() {
126
 
        if (fTable != null) {
127
 
            fTable.dispose();
128
 
        }
129
 
        super.dispose();
130
 
    }
131
 
 
132
 
    /**
133
 
     * Handler for the experiment updated signal.
 
112
        fTree.setFocus();
 
113
    }
 
114
 
 
115
    /**
 
116
     * Handler for the trace opened signal.
 
117
     * @param signal
 
118
     *            The incoming signal
 
119
     * @since 2.0
 
120
     */
 
121
    @TmfSignalHandler
 
122
    public void traceOpened(TmfTraceOpenedSignal signal) {
 
123
        fTrace = signal.getTrace();
 
124
        updateTable();
 
125
    }
 
126
 
 
127
 
 
128
    /**
 
129
     * Handler for the trace selected signal.
134
130
     *
135
131
     * @param signal
136
132
     *            The incoming signal
 
133
     * @since 2.0
137
134
     */
138
 
    @SuppressWarnings("unchecked")
139
135
    @TmfSignalHandler
140
 
    public void experimentSelected(TmfExperimentSelectedSignal<TmfEvent> signal) {
 
136
    public void traceSelected(TmfTraceSelectedSignal signal) {
141
137
        // Update the trace reference
142
 
        TmfExperiment<TmfEvent> exp = (TmfExperiment<TmfEvent>) signal.getExperiment();
143
 
        if (!exp.equals(fExperiment)) {
144
 
            fExperiment = exp;
145
 
            if (fTable != null) {
146
 
                fTable.dispose();
147
 
            }
148
 
            createPartControl( fParent );
149
 
            fParent.layout();
 
138
        ITmfTrace trace = signal.getTrace();
 
139
        if (!trace.equals(fTrace)) {
 
140
            fTrace = trace;
 
141
            updateTable();
150
142
        }
151
143
    }
152
144
 
 
145
    /**
 
146
     * Handler for the trace closed signal.
 
147
     *
 
148
     * @param signal the incoming signal
 
149
     * @since 2.0
 
150
     */
 
151
    @TmfSignalHandler
 
152
    public void traceClosed(TmfTraceClosedSignal signal) {
 
153
        if (signal.getTrace() == fTrace) {
 
154
            fTrace = null;
 
155
            fTree.setItemCount(0);
 
156
        }
 
157
    }
153
158
 
154
159
}
 
160