~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to systemtap/org.eclipse.linuxtools.systemtap.ui.dashboardextension/src/org/eclipse/linuxtools/internal/systemtap/ui/dashboardextension/dialogs/ExportScriptDialog.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

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, Anithra P J
 
10
 *******************************************************************************/
 
11
 
 
12
package org.eclipse.linuxtools.internal.systemtap.ui.dashboardextension.dialogs;
 
13
 
 
14
import java.text.MessageFormat;
 
15
 
 
16
import org.eclipse.jface.dialogs.Dialog;
 
17
import org.eclipse.jface.dialogs.MessageDialog;
 
18
import org.eclipse.jface.wizard.WizardDialog;
 
19
import org.eclipse.swt.SWT;
 
20
import org.eclipse.swt.events.SelectionEvent;
 
21
import org.eclipse.swt.events.SelectionListener;
 
22
import org.eclipse.swt.widgets.Button;
 
23
import org.eclipse.swt.widgets.Composite;
 
24
import org.eclipse.swt.widgets.Control;
 
25
import org.eclipse.swt.widgets.Label;
 
26
import org.eclipse.swt.widgets.Shell;
 
27
import org.eclipse.swt.widgets.Text;
 
28
import org.eclipse.swt.widgets.Tree;
 
29
import org.eclipse.swt.widgets.TreeItem;
 
30
import org.eclipse.ui.IWorkbench;
 
31
import org.eclipse.ui.PlatformUI;
 
32
 
 
33
import org.eclipse.linuxtools.internal.systemtap.ui.dashboardextension.Localization;
 
34
import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.IDataSet;
 
35
import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.filters.IDataSetFilter;
 
36
import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.structures.GraphData;
 
37
import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.wizards.filter.AvailableFilterTypes;
 
38
import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.wizards.filter.SelectFilterWizard;
 
39
import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.wizards.graph.GraphFactory;
 
40
import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.wizards.graph.SelectGraphWizard;
 
41
import org.eclipse.linuxtools.systemtap.ui.structures.TreeNode;
 
42
 
 
43
/**
 
44
 * This class handles creating a dialog that the user is able to select
 
45
 * features that they want to be part of their new dashboard module.
 
46
 * Once the user is done configuring the module, it will create the new 
 
47
 * module for the dashboard from the active script in the editor.
 
48
 * @author Ryan Morse
 
49
 */
 
50
public class ExportScriptDialog extends Dialog {
 
51
        public ExportScriptDialog(Shell parentShell, IDataSet data) {
 
52
                super(parentShell);
 
53
                this.data = data;
 
54
                canceled = false;
 
55
        }
 
56
 
 
57
        /**
 
58
         * This method will setup the size of the dialog window and set its title.
 
59
         * @param shell The shell that will contain this dialog box
 
60
         */
 
61
        protected void configureShell(Shell shell) {
 
62
                super.configureShell(shell);
 
63
                shell.setText(Localization.getString("ExportScriptDialog.ExportScript"));
 
64
                shell.setSize(330, 375);
 
65
        }
 
66
 
 
67
        /**
 
68
         * This method adds all of the components to the dialog and positions them.
 
69
         * Actions are added to all of the buttons to deal with user interaction.
 
70
         * @param parent The Composite that will contain all components created in this method
 
71
         * @return The main Control created by this method.
 
72
         */
 
73
        protected Control createDialogArea(Composite parent) {
 
74
                Composite comp = new Composite(parent, SWT.NONE);
 
75
 
 
76
                //Dialog reference labels
 
77
                Label lblDisplay = new Label(comp, SWT.NONE);
 
78
                lblDisplay.setText(Localization.getString("ExportScriptDialog.Display"));
 
79
                lblDisplay.setBounds(10, 12, 100, 25);
 
80
                Label lblCategory = new Label(comp, SWT.NONE);
 
81
                lblCategory.setText(Localization.getString("ExportScriptDialog.Category"));
 
82
                lblCategory.setBounds(10, 42, 100, 25);
 
83
                Label lblDescription = new Label(comp, SWT.NONE);
 
84
                lblDescription.setText(Localization.getString("ExportScriptDialog.Description"));
 
85
                lblDescription.setBounds(10, 72, 100, 25);
 
86
                Label lblGraphs = new Label(comp, SWT.NONE);
 
87
                lblGraphs.setText(Localization.getString("ExportScriptDialog.Graphs"));
 
88
                lblGraphs.setBounds(10, 150, 100, 25);
 
89
 
 
90
                //Text boxes for how to display the new module in the dashboard
 
91
                txtDisplay = new Text(comp, SWT.BORDER);
 
92
                txtDisplay.setBounds(120, 10, 200, 25);
 
93
                txtCategory = new Text(comp, SWT.BORDER);
 
94
                txtCategory.setBounds(120, 40, 200, 25);
 
95
                txtDescription = new Text(comp, SWT.MULTI | SWT.WRAP | SWT.BORDER);
 
96
                txtDescription.setBounds(120, 70, 200, 75);
 
97
                
 
98
                treeGraphs = new Tree(comp, SWT.SINGLE | SWT.BORDER);
 
99
                treeGraphs.setBounds(10, 175, 200, 125);
 
100
 
 
101
                //Button to add another graph
 
102
                btnAdd = new Button(comp, SWT.PUSH);
 
103
                btnAdd.setText(Localization.getString("ExportScriptDialog.Add"));
 
104
                btnAdd.setBounds(220, 175, 100, 26);
 
105
 
 
106
                //Button to filter the script output data
 
107
                btnAddFilter = new Button(comp, SWT.PUSH);
 
108
                btnAddFilter.setText(Localization.getString("ExportScriptDialog.AddFilter"));
 
109
                btnAddFilter.setBounds(220, 205, 100, 26);
 
110
                btnAddFilter.setEnabled(false);
 
111
                
 
112
                //Button to remove the selected graph/filter
 
113
                btnRemove = new Button(comp, SWT.PUSH);
 
114
                btnRemove.setText(Localization.getString("ExportScriptDialog.Remove"));
 
115
                btnRemove.setBounds(220, 265, 100, 26);
 
116
                btnRemove.setEnabled(false);
 
117
 
 
118
                //Action to notify the buttons when to enable/disable themselves based on list selection
 
119
                treeGraphs.addSelectionListener(new SelectionListener() {
 
120
                        public void widgetSelected(SelectionEvent e) {
 
121
                                selectedTreeItem = (TreeItem)e.item;
 
122
                                if(null == selectedTreeItem.getParentItem())
 
123
                                        btnAddFilter.setEnabled(true);
 
124
                                else
 
125
                                        btnAddFilter.setEnabled(false);
 
126
                                btnRemove.setEnabled(true);
 
127
                        }
 
128
                        
 
129
                        public void widgetDefaultSelected(SelectionEvent e) {}
 
130
                });
 
131
                
 
132
                //Brings up a new dialog box when user clicks the add button.  Allows selecting a new graph to display.
 
133
                btnAdd.addSelectionListener(new SelectionListener() {
 
134
                        public void widgetSelected(SelectionEvent e) {
 
135
                                SelectGraphWizard wizard = new SelectGraphWizard(data);
 
136
                                IWorkbench workbench = PlatformUI.getWorkbench();
 
137
                                wizard.init(workbench, null);
 
138
                                WizardDialog dialog = new WizardDialog(workbench.getActiveWorkbenchWindow().getShell(), wizard);
 
139
                                dialog.create();
 
140
                                dialog.open();
 
141
 
 
142
                                GraphData gd = wizard.getGraphData();
 
143
                                if(null != gd) {
 
144
                                        TreeItem item = new TreeItem(treeGraphs, SWT.NONE);
 
145
                                        item.setText(GraphFactory.getGraphName(gd.graphID) + ":" + gd.title);
 
146
                                        item.setData(gd);
 
147
                                }
 
148
                        }
 
149
                        
 
150
                        public void widgetDefaultSelected(SelectionEvent e) {}
 
151
                });
 
152
 
 
153
                //Brings up a new dialog for selecting filter options when the user clicks the filter button.
 
154
                btnAddFilter.addSelectionListener(new SelectionListener() {
 
155
                        public void widgetSelected(SelectionEvent e) {
 
156
                                SelectFilterWizard wizard = new SelectFilterWizard(data.getTitles());
 
157
                                IWorkbench workbench = PlatformUI.getWorkbench();
 
158
                                wizard.init(workbench, null);
 
159
                                WizardDialog dialog = new WizardDialog(workbench.getActiveWorkbenchWindow().getShell(), wizard);
 
160
                                dialog.create();
 
161
                                dialog.open();
 
162
 
 
163
                                IDataSetFilter f = wizard.getFilter();
 
164
                                if(null != f) {
 
165
                                        TreeItem item = new TreeItem(treeGraphs.getSelection()[0], SWT.NONE);
 
166
                                        item.setText(AvailableFilterTypes.getFilterName(f.getID()));
 
167
                                        item.setData(f);
 
168
                                }
 
169
                        }
 
170
                        
 
171
                        public void widgetDefaultSelected(SelectionEvent e) {}
 
172
                });
 
173
                
 
174
                //Removes the selected graph/filter from the tree
 
175
                btnRemove.addSelectionListener(new SelectionListener() {
 
176
                        public void widgetSelected(SelectionEvent e) {
 
177
                                selectedTreeItem.dispose();
 
178
                                btnRemove.setEnabled(false);
 
179
                        }
 
180
                        
 
181
                        public void widgetDefaultSelected(SelectionEvent e) {}
 
182
                });
 
183
                
 
184
                return comp;
 
185
        }
 
186
 
 
187
        /**
 
188
         * This method haddles what to do when the user clicks the ok or cancel button.
 
189
         * If canceled it will just close without doing anything.  If the user clicked ok
 
190
         * and the data entered is valid it will set up variables that can be accessed
 
191
         * later to build the actual module.  This method should not be called explicitly.
 
192
         * @param buttonID A reference to the button that was pressed. 0 - ID, 1- for others
 
193
         */
 
194
        protected void buttonPressed(int buttonID) {
 
195
                if(0 == buttonID) {     //OK
 
196
                        if(txtDisplay.getText().length() <= 0 || 
 
197
                           txtCategory.getText().length() <= 0 ||
 
198
                           txtDescription.getText().length() <= 0 ||
 
199
                           treeGraphs.getItemCount() <= 0) {
 
200
                                String msg = MessageFormat.format(Localization.getString("ExportScriptDialog.FillFields"), (Object[])null);
 
201
                                MessageDialog.openWarning(this.getShell(), Localization.getString("ExportScriptDialog.Error"), msg);
 
202
                                return;
 
203
                        }
 
204
 
 
205
                        display = txtDisplay.getText();
 
206
                        category = txtCategory.getText();
 
207
                        description = txtDescription.getText();
 
208
                        buildGraphData();
 
209
                        buildFilterData();
 
210
                } else {
 
211
                        canceled = true;
 
212
                }
 
213
                
 
214
                super.buttonPressed(buttonID);
 
215
        }
 
216
 
 
217
        /**
 
218
         * This allows outside classes to determine if the user clicked ok or cancel.
 
219
         * @return boolean representing whether the cancel button was pressed or not
 
220
         */
 
221
        public boolean isCanceled() {
 
222
                return canceled;
 
223
        }
 
224
        
 
225
        /**
 
226
         * This allows an outside class to determin what was chosen to be the Category.
 
227
         * @return String representing the selected Category name.
 
228
         */
 
229
        public String getCategory() {
 
230
                return category;
 
231
        }
 
232
        
 
233
        /**
 
234
         * This allows an outside class to determin what was chosen to be the Description.
 
235
         * @return String representing the selected Description.
 
236
         */
 
237
        public String getDescription() {
 
238
                return description;
 
239
        }
 
240
        
 
241
        /**
 
242
         * This allows an outside class to determin what was chosen to be the Display name.
 
243
         * @return String representing the selected Display name.
 
244
         */
 
245
        public String getDisplay() {
 
246
                return display;
 
247
        }
 
248
        
 
249
        /**
 
250
         * This allows an outside class to determin what graph types were selected.
 
251
         * @return GraphData[] for each selected graph.
 
252
         */
 
253
        public GraphData[] getGraphs() {
 
254
                return graphData;
 
255
        }
 
256
        
 
257
        /**
 
258
         * This allows an outside class to determin what filter types were chosen.
 
259
         * @return TreeNode organized as follows: Root->Graphs->Filters.
 
260
         */
 
261
        public TreeNode getGraphFilters() {
 
262
                return filters;
 
263
        }
 
264
        
 
265
        /**
 
266
         * This cleans up all internal references to objects.  No other method should
 
267
         * be called after the dispose method.
 
268
         */
 
269
        public void dispose() {
 
270
                if(null != txtDisplay)
 
271
                        txtDisplay.dispose();
 
272
                if(null != txtCategory)
 
273
                        txtCategory.dispose();
 
274
                if(null != txtDescription)
 
275
                        txtDescription.dispose();
 
276
                if(null != treeGraphs)
 
277
                        treeGraphs.dispose();
 
278
                if(null != btnAdd)
 
279
                        btnAdd.dispose();
 
280
                if(null != btnRemove)
 
281
                        btnRemove.dispose();
 
282
                if(null != btnAddFilter)
 
283
                        btnAddFilter.dispose();
 
284
                if(null != selectedTreeItem)
 
285
                        selectedTreeItem.dispose();
 
286
                txtDisplay = null;
 
287
                txtCategory = null;
 
288
                txtDescription = null;
 
289
                treeGraphs = null;
 
290
                btnAdd = null;
 
291
                btnRemove = null;
 
292
                btnAddFilter = null;
 
293
                selectedTreeItem = null;
 
294
                data = null;
 
295
        }
 
296
        
 
297
        /**
 
298
         * This method converts what was selected in the tree into a simple array
 
299
         * of all of the selected graphs and their data.
 
300
         */
 
301
        private void buildGraphData() {
 
302
                TreeItem[] children = treeGraphs.getItems();
 
303
                graphData = new GraphData[children.length];
 
304
                for(int i=0; i<graphData.length; i++)
 
305
                        graphData[i] = (GraphData)children[i].getData();
 
306
        }
 
307
        
 
308
        /**
 
309
         * This mothod takes the data from the tree and builds another tree that
 
310
         * has all the information about the graph and Filters in an easily
 
311
         * accessable structure.
 
312
         */
 
313
        private void buildFilterData() {
 
314
                TreeItem[] items = treeGraphs.getItems();
 
315
                TreeItem[] filterItems;
 
316
 
 
317
                filters = new TreeNode("", false); //$NON-NLS-1$
 
318
                TreeNode graphLevel;
 
319
                for(int i=0; i<items.length; i++) {
 
320
                        filterItems = items[i].getItems();
 
321
        
 
322
                        graphLevel = new TreeNode("graph", false); //$NON-NLS-1$
 
323
                        filters.add(graphLevel);
 
324
                        
 
325
                        for(int j=0; j<filterItems.length; j++)
 
326
                                graphLevel.add(new TreeNode(filterItems[j].getData(), false));
 
327
                }
 
328
        }
 
329
        
 
330
        private IDataSet data;
 
331
        private Tree treeGraphs;
 
332
        private Text txtDisplay, txtCategory, txtDescription;
 
333
        private Button btnAdd, btnRemove, btnAddFilter;
 
334
        private String display, category, description;
 
335
        private GraphData[] graphData;
 
336
        private TreeNode filters;
 
337
        private boolean canceled;
 
338
        private TreeItem selectedTreeItem;
 
339
}