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

« back to all changes in this revision

Viewing changes to systemtap/org.eclipse.linuxtools.systemtap.graphing.ui/src/org/eclipse/linuxtools/systemtap/graphing/ui/GraphDisplaySet.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:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2006 IBM Corporation.
 
3
 * All rights reserved. This program and the accompanying materials
 
4
 * are made available under the terms of the Eclipse Public License v1.0
 
5
 * which accompanies this distribution, and is available at
 
6
 * http://www.eclipse.org/legal/epl-v10.html
 
7
 *
 
8
 * Contributors:
 
9
 *     IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse
 
10
 *******************************************************************************/
 
11
 
 
12
package org.eclipse.linuxtools.systemtap.graphing.ui;
 
13
 
 
14
import java.text.MessageFormat;
 
15
import java.util.ArrayList;
 
16
import java.util.List;
 
17
 
 
18
import org.eclipse.jface.preference.IPreferenceStore;
 
19
import org.eclipse.jface.util.IPropertyChangeListener;
 
20
import org.eclipse.jface.util.PropertyChangeEvent;
 
21
import org.eclipse.jface.wizard.WizardDialog;
 
22
import org.eclipse.linuxtools.internal.systemtap.graphing.ui.GraphingUIPlugin;
 
23
import org.eclipse.linuxtools.internal.systemtap.graphing.ui.Localization;
 
24
import org.eclipse.linuxtools.internal.systemtap.graphing.ui.preferences.GraphingPreferenceConstants;
 
25
import org.eclipse.linuxtools.systemtap.graphing.core.datasets.IDataSet;
 
26
import org.eclipse.linuxtools.systemtap.graphing.core.datasets.IFilteredDataSet;
 
27
import org.eclipse.linuxtools.systemtap.graphing.core.structures.GraphData;
 
28
import org.eclipse.linuxtools.systemtap.graphing.ui.charts.AbstractChartBuilder;
 
29
import org.eclipse.linuxtools.systemtap.graphing.ui.datadisplay.DataGrid;
 
30
import org.eclipse.linuxtools.systemtap.graphing.ui.widgets.GraphComposite;
 
31
import org.eclipse.linuxtools.systemtap.graphing.ui.widgets.Messages;
 
32
import org.eclipse.linuxtools.systemtap.graphing.ui.wizards.dataset.DataSetFactory;
 
33
import org.eclipse.linuxtools.systemtap.graphing.ui.wizards.graph.GraphFactory;
 
34
import org.eclipse.linuxtools.systemtap.graphing.ui.wizards.graph.SelectGraphAndSeriesWizard;
 
35
import org.eclipse.linuxtools.systemtap.structures.UpdateManager;
 
36
import org.eclipse.linuxtools.systemtap.structures.listeners.ITabListener;
 
37
import org.eclipse.swt.SWT;
 
38
import org.eclipse.swt.custom.CTabFolder;
 
39
import org.eclipse.swt.custom.CTabFolder2Adapter;
 
40
import org.eclipse.swt.custom.CTabFolderEvent;
 
41
import org.eclipse.swt.custom.CTabItem;
 
42
import org.eclipse.swt.events.SelectionAdapter;
 
43
import org.eclipse.swt.events.SelectionEvent;
 
44
import org.eclipse.swt.layout.FormAttachment;
 
45
import org.eclipse.swt.layout.FormData;
 
46
import org.eclipse.swt.layout.FormLayout;
 
47
import org.eclipse.swt.layout.GridData;
 
48
import org.eclipse.swt.layout.GridLayout;
 
49
import org.eclipse.swt.widgets.Button;
 
50
import org.eclipse.swt.widgets.Composite;
 
51
import org.eclipse.ui.IWorkbench;
 
52
import org.eclipse.ui.PlatformUI;
 
53
import org.eclipse.ui.plugin.AbstractUIPlugin;
 
54
 
 
55
 
 
56
 
 
57
/**
 
58
 * This class is used to contain all of the graphing components that can
 
59
 * be displayed as individual tabs in a single location.
 
60
 * @author Ryan Morse
 
61
 * @since 3.0 Migrated from .ui.graphing package.
 
62
 */
 
63
public class GraphDisplaySet {
 
64
 
 
65
    private IPropertyChangeListener propertyChangeListener;
 
66
    private IPreferenceStore p;
 
67
 
 
68
    /**
 
69
     * @since 3.0 set must be a IFilteredDataSet.
 
70
     */
 
71
    public GraphDisplaySet(Composite parent, IFilteredDataSet data) {
 
72
        p = GraphingUIPlugin.getDefault().getPreferenceStore();
 
73
        int delay = p.getInt(GraphingPreferenceConstants.P_GRAPH_UPDATE_DELAY);
 
74
 
 
75
        dataSet = data;
 
76
        updater = new UpdateManager(delay);
 
77
        createPartControl(parent);
 
78
 
 
79
        propertyChangeListener = new IPropertyChangeListener() {
 
80
            @Override
 
81
            public void propertyChange(PropertyChangeEvent event) {
 
82
                if (updater.isRunning() && event.getProperty().equals(GraphingPreferenceConstants.P_GRAPH_UPDATE_DELAY)) {
 
83
                    updater.restart((int) event.getNewValue());
 
84
                }
 
85
            }
 
86
        };
 
87
        p.addPropertyChangeListener(propertyChangeListener);
 
88
 
 
89
        builders = new ArrayList<>();
 
90
        tabListeners = new ArrayList<>();
 
91
    }
 
92
 
 
93
    /**
 
94
     * This method creates the framework for what will be displayed by this dialog box.
 
95
     * @param parent The composite that will contain all the elements from this dialog
 
96
     */
 
97
    private void createPartControl(Composite parent) {
 
98
        parent.setLayout(new FormLayout());
 
99
        FormData data1 = new FormData();
 
100
        Composite cmpCoolBar = new Composite(parent, SWT.NONE);
 
101
        data1.left = new FormAttachment(0, 0);
 
102
        data1.top = new FormAttachment(0, 0);
 
103
        data1.right = new FormAttachment(100, 0);
 
104
        data1.bottom = new FormAttachment(0, 10);
 
105
        cmpCoolBar.setLayoutData(data1);
 
106
 
 
107
        FormData data2 = new FormData();
 
108
        data2.left = new FormAttachment(0, 0);
 
109
        data2.top = new FormAttachment(cmpCoolBar);
 
110
        data2.right = new FormAttachment(100, 0);
 
111
        data2.bottom = new FormAttachment(100, 0);
 
112
        Composite cmpGraph = new Composite(parent, SWT.NONE);
 
113
        cmpGraph.setLayoutData(data2);
 
114
 
 
115
        //This is for the tab view
 
116
        cmpGraph.setLayout(new FormLayout());
 
117
 
 
118
        folder = new CTabFolder(cmpGraph, SWT.NONE);
 
119
        FormData data = new FormData();
 
120
        data.top = new FormAttachment(0, 0);
 
121
        data.left = new FormAttachment(0, 0);
 
122
        data.right = new FormAttachment(100, 0);
 
123
        data.bottom = new FormAttachment(100, 0);
 
124
        folder.setLayoutData(data);
 
125
 
 
126
        listener = new ButtonClickListener();
 
127
        folder.addSelectionListener(listener);
 
128
 
 
129
        folder.addCTabFolder2Listener(new CTabFolder2Adapter() {
 
130
            @Override
 
131
            public void close(CTabFolderEvent e) {
 
132
                int selected = folder.indexOf((CTabItem)e.item)-2;
 
133
                if(null != updater) {
 
134
                    updater.removeUpdateListener(builders.get(selected));
 
135
                }
 
136
                builders.remove(selected);
 
137
                fireTabCloseEvent();
 
138
            }
 
139
        });
 
140
 
 
141
        //This is a tab/button for opening new graphs
 
142
        CTabItem newGraph = new CTabItem(folder, SWT.NONE);
 
143
        newGraph.setImage(AbstractUIPlugin.imageDescriptorFromPlugin(GraphingUIPlugin.PLUGIN_ID, "icons/actions/new_wiz.gif").createImage()); //$NON-NLS-1$
 
144
        newGraph.setToolTipText(Localization.getString("GraphDisplaySet.CreateGraph")); //$NON-NLS-1$
 
145
 
 
146
        //Tab containing the data table
 
147
        CTabItem item = new CTabItem(folder, SWT.NONE);
 
148
        item.setText(Localization.getString("GraphDisplaySet.DataView")); //$NON-NLS-1$
 
149
        Composite c = new Composite(folder, SWT.NONE);
 
150
        GridLayout grid = new GridLayout();
 
151
        grid.marginHeight = 0;
 
152
        grid.marginWidth = 0;
 
153
        c.setLayout(grid);
 
154
 
 
155
        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
 
156
        DataGrid table = DataSetFactory.getDataGrid(c, dataSet);
 
157
        if(null != updater) {
 
158
            updater.addUpdateListener(table);
 
159
        }
 
160
        table.getControl().setLayoutData(gd);
 
161
        item.setControl(c);
 
162
        folder.setSelection(item);
 
163
        lastSelectedTab = 1;
 
164
    }
 
165
 
 
166
    public IDataSet getDataSet() {
 
167
        return dataSet;
 
168
    }
 
169
 
 
170
    /**
 
171
     * Finds the graph that is open in the current tab
 
172
     * @return The graph that is currently visible on the screen
 
173
     */
 
174
    public AbstractChartBuilder getActiveGraph() {
 
175
        if(0 == builders.size() || folder.getSelectionIndex() < 2) {
 
176
            return null;
 
177
        }
 
178
        return builders.get(folder.getSelectionIndex()-2);
 
179
    }
 
180
 
 
181
    /**
 
182
     * Removes all internal references in this class.  Nothing should make any references
 
183
     * to anything in this class after calling the dispose method.
 
184
     */
 
185
    public void dispose() {
 
186
        if(null != updater && updater.isRunning()) {
 
187
            updater.dispose();
 
188
        }
 
189
        updater = null;
 
190
 
 
191
        p.removePropertyChangeListener(propertyChangeListener);
 
192
        propertyChangeListener = null;
 
193
 
 
194
        dataSet = null;
 
195
        if(null != folder && !folder.isDisposed()) {
 
196
            folder.removeSelectionListener(listener);
 
197
            folder.dispose();
 
198
            folder = null;
 
199
        }
 
200
        listener = null;
 
201
 
 
202
        for (AbstractChartBuilder builder : builders) {
 
203
            builder.dispose();
 
204
        }
 
205
        builders.clear();
 
206
    }
 
207
 
 
208
    /**
 
209
     * This class handles switching between tabs and creating new graphs.
 
210
     * When the user selects the first tab a new dialog is displayed for
 
211
     * them to select what they want to display for the new graph.
 
212
     */
 
213
    private class ButtonClickListener extends SelectionAdapter {
 
214
        @Override
 
215
        public void widgetSelected(SelectionEvent event) {
 
216
            CTabFolder folder = (CTabFolder)event.getSource();
 
217
 
 
218
            if(folder.getSelectionIndex() == 0) {
 
219
                folder.setSelection(lastSelectedTab);
 
220
                SelectGraphAndSeriesWizard wizard = new SelectGraphAndSeriesWizard(dataSet, null);
 
221
                IWorkbench workbench = PlatformUI.getWorkbench();
 
222
                wizard.init(workbench, null);
 
223
                WizardDialog dialog = new WizardDialog(workbench.getActiveWorkbenchWindow().getShell(), wizard);
 
224
                dialog.create();
 
225
                dialog.open();
 
226
 
 
227
                GraphData gd = wizard.getGraphData();
 
228
 
 
229
                if(null != gd) {
 
230
                    addGraph(gd);
 
231
                }
 
232
                wizard.dispose();
 
233
                fireTabOpenEvent();
 
234
            }
 
235
            lastSelectedTab = folder.getSelectionIndex();
 
236
            fireTabChangedEvent();
 
237
        }
 
238
    }
 
239
 
 
240
    public void addTabListener(ITabListener listener) {
 
241
        tabListeners.add(listener);
 
242
    }
 
243
 
 
244
    private void fireTabCloseEvent() {
 
245
        for(int i=0; i<tabListeners.size(); i++) {
 
246
            (tabListeners.get(i)).tabClosed();
 
247
        }
 
248
    }
 
249
 
 
250
    private void fireTabOpenEvent() {
 
251
        for(int i=0; i<tabListeners.size(); i++) {
 
252
            (tabListeners.get(i)).tabOpened();
 
253
        }
 
254
    }
 
255
 
 
256
    private void fireTabChangedEvent() {
 
257
        for(int i=0; i<tabListeners.size(); i++) {
 
258
            (tabListeners.get(i)).tabChanged();
 
259
        }
 
260
    }
 
261
 
 
262
    public void addGraph(final GraphData gd) {
 
263
        CTabItem item = new CTabItem(folder, SWT.CLOSE);
 
264
        item.setText(MessageFormat.format(Localization.getString("GraphDisplaySet.GraphTabTitle"), //$NON-NLS-1$
 
265
                gd.title, GraphFactory.getGraphName(gd.graphID)));
 
266
        final GraphComposite gc = new GraphComposite(folder, SWT.FILL, gd, dataSet);
 
267
        gc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
 
268
        gc.addCheckOption(Messages.GraphCompositeTitle, new SelectionAdapter() {
 
269
            @Override
 
270
            public void widgetSelected(SelectionEvent e) {
 
271
                gc.setTitleVisible(((Button)e.getSource()).getSelection());
 
272
            }
 
273
        });
 
274
        gc.addCheckOption(Messages.GraphCompositeLegend, new SelectionAdapter() {
 
275
            @Override
 
276
            public void widgetSelected(SelectionEvent e) {
 
277
                gc.setLegendVisible(((Button)e.getSource()).getSelection());
 
278
            }
 
279
        });
 
280
        folder.setSelection(item);
 
281
 
 
282
        AbstractChartBuilder g = gc.getCanvas();
 
283
        item.setControl(gc);
 
284
 
 
285
        if(null != g) {
 
286
            if(null != updater) {
 
287
                updater.addUpdateListener(g);
 
288
            }
 
289
            builders.add(g);
 
290
        }
 
291
    }
 
292
 
 
293
    private int lastSelectedTab;
 
294
    private IFilteredDataSet dataSet;
 
295
    private CTabFolder folder;
 
296
    private ButtonClickListener listener;
 
297
    private UpdateManager updater;
 
298
    private List<ITabListener> tabListeners;
 
299
 
 
300
    private List<AbstractChartBuilder> builders;
 
301
}