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
9
* IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse, Anithra P J
10
*******************************************************************************/
12
package org.eclipse.linuxtools.internal.systemtap.ui.dashboardextension.dialogs;
14
import java.text.MessageFormat;
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;
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;
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.
50
public class ExportScriptDialog extends Dialog {
51
public ExportScriptDialog(Shell parentShell, IDataSet data) {
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
61
protected void configureShell(Shell shell) {
62
super.configureShell(shell);
63
shell.setText(Localization.getString("ExportScriptDialog.ExportScript"));
64
shell.setSize(330, 375);
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.
73
protected Control createDialogArea(Composite parent) {
74
Composite comp = new Composite(parent, SWT.NONE);
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);
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);
98
treeGraphs = new Tree(comp, SWT.SINGLE | SWT.BORDER);
99
treeGraphs.setBounds(10, 175, 200, 125);
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);
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);
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);
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);
125
btnAddFilter.setEnabled(false);
126
btnRemove.setEnabled(true);
129
public void widgetDefaultSelected(SelectionEvent e) {}
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);
142
GraphData gd = wizard.getGraphData();
144
TreeItem item = new TreeItem(treeGraphs, SWT.NONE);
145
item.setText(GraphFactory.getGraphName(gd.graphID) + ":" + gd.title);
150
public void widgetDefaultSelected(SelectionEvent e) {}
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);
163
IDataSetFilter f = wizard.getFilter();
165
TreeItem item = new TreeItem(treeGraphs.getSelection()[0], SWT.NONE);
166
item.setText(AvailableFilterTypes.getFilterName(f.getID()));
171
public void widgetDefaultSelected(SelectionEvent e) {}
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);
181
public void widgetDefaultSelected(SelectionEvent e) {}
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
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);
205
display = txtDisplay.getText();
206
category = txtCategory.getText();
207
description = txtDescription.getText();
214
super.buttonPressed(buttonID);
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
221
public boolean isCanceled() {
226
* This allows an outside class to determin what was chosen to be the Category.
227
* @return String representing the selected Category name.
229
public String getCategory() {
234
* This allows an outside class to determin what was chosen to be the Description.
235
* @return String representing the selected Description.
237
public String getDescription() {
242
* This allows an outside class to determin what was chosen to be the Display name.
243
* @return String representing the selected Display name.
245
public String getDisplay() {
250
* This allows an outside class to determin what graph types were selected.
251
* @return GraphData[] for each selected graph.
253
public GraphData[] getGraphs() {
258
* This allows an outside class to determin what filter types were chosen.
259
* @return TreeNode organized as follows: Root->Graphs->Filters.
261
public TreeNode getGraphFilters() {
266
* This cleans up all internal references to objects. No other method should
267
* be called after the dispose method.
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();
280
if(null != btnRemove)
282
if(null != btnAddFilter)
283
btnAddFilter.dispose();
284
if(null != selectedTreeItem)
285
selectedTreeItem.dispose();
288
txtDescription = null;
293
selectedTreeItem = null;
298
* This method converts what was selected in the tree into a simple array
299
* of all of the selected graphs and their data.
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();
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.
313
private void buildFilterData() {
314
TreeItem[] items = treeGraphs.getItems();
315
TreeItem[] filterItems;
317
filters = new TreeNode("", false); //$NON-NLS-1$
319
for(int i=0; i<items.length; i++) {
320
filterItems = items[i].getItems();
322
graphLevel = new TreeNode("graph", false); //$NON-NLS-1$
323
filters.add(graphLevel);
325
for(int j=0; j<filterItems.length; j++)
326
graphLevel.add(new TreeNode(filterItems[j].getData(), false));
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;