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
10
*******************************************************************************/
12
package org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.wizards.graph;
14
import org.eclipse.jface.wizard.WizardPage;
15
import org.eclipse.linuxtools.internal.systemtap.ui.graphingapi.ui.Localization;
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.events.ModifyEvent;
18
import org.eclipse.swt.events.ModifyListener;
19
import org.eclipse.swt.events.SelectionEvent;
20
import org.eclipse.swt.events.SelectionListener;
21
import org.eclipse.swt.layout.FormAttachment;
22
import org.eclipse.swt.layout.FormData;
23
import org.eclipse.swt.layout.FormLayout;
24
import org.eclipse.swt.widgets.Button;
25
import org.eclipse.swt.widgets.Combo;
26
import org.eclipse.swt.widgets.Composite;
27
import org.eclipse.swt.widgets.Label;
28
import org.eclipse.swt.widgets.Text;
29
import org.eclipse.ui.forms.widgets.ColumnLayout;
34
public class SelectSeriesWizardPage extends WizardPage {
35
public SelectSeriesWizardPage() {
36
super("selectSeries");
37
setTitle(Localization.getString("SelectSeriesWizardPage.SelectSeries"));
40
public void createControl(Composite parent) {
41
model = ((SelectGraphWizard)super.getWizard()).model;
44
Composite comp = new Composite(parent, SWT.NULL);
45
comp.setLayout(new FormLayout());
46
FormData data1 = new FormData();
47
data1.left = new FormAttachment(0, 0);
48
data1.top = new FormAttachment(0, 0);
49
data1.right = new FormAttachment(40, 0);
50
data1.bottom = new FormAttachment(100, 0);
52
//Add the title wigets
53
Label lblTitle = new Label(comp, SWT.NONE);
54
lblTitle.setText(Localization.getString("SelectSeriesWizardPage.Title"));
55
txtTitle = new Text(comp, SWT.BORDER);
56
txtTitle.addModifyListener(new ModifyListener() {
57
public void modifyText(ModifyEvent e) {
58
getWizard().getContainer().updateButtons();
59
if(txtTitle.getText().length() == 0) {
60
setErrorMessage(Localization.getString("SelectSeriesWizardPage.TitleNotSet"));
63
setErrorMessage(null);
68
data1 = new FormData();
69
data1.left = new FormAttachment(0,0);
70
data1.top = new FormAttachment(0,0);
72
lblTitle.setLayoutData(data1);
74
data1 = new FormData();
75
data1.left = new FormAttachment(0,0);
76
data1.top = new FormAttachment(lblTitle,0);
78
txtTitle.setLayoutData(data1);
81
//Add the data series widgets
82
data1 = new FormData();
83
data1.left = new FormAttachment(0, 0);
84
data1.top = new FormAttachment(txtTitle, 20);
85
data1.right = new FormAttachment(40, 0);
86
data1.bottom = new FormAttachment(100, 0);
88
Composite cmpGraphOpts = new Composite(comp, SWT.NONE);
89
cmpGraphOpts.setLayoutData(data1);
90
ColumnLayout colLayout = new ColumnLayout();
91
colLayout.maxNumColumns = 1;
92
cmpGraphOpts.setLayout(colLayout);
94
String[] labels = model.getSeries();
96
cboYItems = new Combo[labels.length];
97
lblYItems = new Label[cboYItems.length];
99
Label lblXItem = new Label(cmpGraphOpts, SWT.NONE);
100
lblXItem.setText(Localization.getString("SelectSeriesWizardPage.XSeries"));
101
cboXItem = new Combo(cmpGraphOpts, SWT.DROP_DOWN);
102
cboXItem.addSelectionListener(new ComboSelectionListener());
103
cboXItem.add(Localization.getString("SelectSeriesWizardPage.RowID"));
106
new Label(cmpGraphOpts, SWT.NONE); //Spacer
108
for(int i=0; i<cboYItems.length; i++) {
109
lblYItems[i] = new Label(cmpGraphOpts, SWT.NONE);
110
lblYItems[i].setText(Localization.getString("SelectSeriesWizardPage.YSeries") + i + ":");
111
cboYItems[i] = new Combo(cmpGraphOpts, SWT.DROP_DOWN);
112
cboYItems[i].addSelectionListener(new ComboSelectionListener());
115
cboYItems[i].add(Localization.getString("SelectSeriesWizardPage.NA"));
116
cboYItems[i].select(0);
117
cboYItems[i].setVisible(false);
118
lblYItems[i].setVisible(false);
122
for(int j,i=0; i<labels.length; i++) {
123
cboXItem.add(labels[i]);
124
for(j=0; j<lblYItems.length; j++)
125
cboYItems[j].add(labels[i]);
129
//Add the key filter wigets
130
btnKey = new Button(comp, SWT.CHECK);
131
btnKey.setText(Localization.getString("SelectSeriesWizardPage.UseHistoricalData"));
132
btnKey.addSelectionListener(new SelectionListener() {
133
public void widgetDefaultSelected(SelectionEvent e) {}
134
public void widgetSelected(SelectionEvent e) {
135
txtKey.setEnabled(btnKey.getSelection());
139
data1 = new FormData();
140
data1.left = new FormAttachment(cmpGraphOpts, 20);
141
data1.top = new FormAttachment(txtTitle, 0);
142
data1.right = new FormAttachment(100, 0);
143
btnKey.setLayoutData(data1);
145
lblKey = new Label(comp, SWT.NONE);
146
lblKey.setText(Localization.getString("SelectSeriesWizardPage.KeyFilter"));
147
txtKey = new Text(comp, SWT.BORDER);
150
txtKey.addModifyListener(new ModifyListener() {
151
public void modifyText(ModifyEvent e) {
152
getWizard().getContainer().updateButtons();
153
if(txtTitle.getText().length() == 0) {
154
setErrorMessage(Localization.getString("SelectSeriesWizardPage.KeyNotSet"));
157
setErrorMessage(null);
158
setMessage(""); //$NON-NLS-1$
164
data1 = new FormData();
165
data1.left = new FormAttachment(cmpGraphOpts, 20);
166
data1.top = new FormAttachment(btnKey, 0);
167
data1.right = new FormAttachment(80, 0);
168
lblKey.setLayoutData(data1);
170
data1 = new FormData();
171
data1.left = new FormAttachment(cmpGraphOpts, 20);
172
data1.top = new FormAttachment(lblKey, 2);
173
data1.right = new FormAttachment(80, 0);
174
txtKey.setLayoutData(data1);
180
public void setKeyEnablement(boolean required, boolean optional) {
181
btnKey.setVisible(optional);
182
txtKey.setVisible(required || optional);
183
lblKey.setVisible(required || optional);
184
txtKey.setEnabled(required);
187
public boolean canFlipToNextPage() {
191
public boolean isPageComplete() {
192
return saveDataToModel();
195
private boolean saveDataToModel() {
196
if(isSeriesUnique()) {
197
model.setTitle(txtTitle.getText());
199
if(null != txtKey && txtKey.isEnabled())
200
model.setKey(txtKey.getText());
204
model.setXSeries(cboXItem.getSelectionIndex()-1);
207
for(i=1, count=1; i<cboYItems.length; i++)
208
if(cboYItems[i].isVisible() && 0 != cboYItems[i].getSelectionIndex())
211
int[] ySeries = new int[count];
212
ySeries[0] = cboYItems[0].getSelectionIndex();
213
for(i=1; i<count; i++)
214
ySeries[i] = cboYItems[i].getSelectionIndex()-1;
215
model.setYSeries(ySeries);
221
private boolean isSeriesUnique() {
222
if("".equals(txtTitle.getText().trim()))
224
if(null != txtKey && txtKey.isEnabled() && txtKey.getText().length() <= 0)
227
for(int j,i=0; i<cboYItems.length; i++) {
228
if(cboYItems[i].isVisible()) {
229
for(j=i+1; j<cboYItems.length; j++) {
230
if(cboYItems[j].isVisible()) {
231
if(0 > cboYItems[i].getSelectionIndex())
233
else if(0 > cboYItems[j].getSelectionIndex())
235
else if(cboYItems[i].getItem(cboYItems[i].getSelectionIndex()).equals(cboYItems[j].getItem(cboYItems[j].getSelectionIndex()))) {
240
if(0 > cboYItems[i].getSelectionIndex())
242
else if(0 > cboXItem.getSelectionIndex())
244
else if(cboYItems[i].getItem(cboYItems[i].getSelectionIndex()).equals(cboXItem.getItem(cboXItem.getSelectionIndex()))) {
252
public void dispose() {
271
if(null != cboYItems) {
272
for(int i=0; i<cboYItems.length; i++) {
273
if(null != cboYItems[i])
274
cboYItems[i].dispose();
276
if(null != lblYItems[i])
277
lblYItems[i].dispose();
286
private class ComboSelectionListener implements SelectionListener {
287
public void widgetDefaultSelected(SelectionEvent e) {}
289
public void widgetSelected(SelectionEvent e) {
290
if(!cboXItem.equals(e.getSource())) {
291
boolean setVisible = true;
292
if(GraphFactory.isMultiGraph(model.getGraphID())) {
293
for(int i=1; i<cboYItems.length; i++) {
294
cboYItems[i].setVisible(setVisible);
295
lblYItems[i].setVisible(setVisible);
296
if(cboYItems[i].getSelectionIndex() > 0 && cboYItems[i].isVisible())
304
if(!isSeriesUnique()) {
305
setErrorMessage(Localization.getString("SelectSeriesWizardPage.SeriesNotSelected"));
308
setErrorMessage(null);
311
if(txtTitle.getText().length() == 0) {
312
setErrorMessage(Localization.getString("SelectSeriesWizardPage.TitleNotSet"));
316
getWizard().getContainer().updateButtons();
320
private Text txtTitle; //TODO: Move this to another page once graphs get more detail
322
private Button btnKey;
323
private Label lblKey;
324
private Combo cboXItem;
325
private Combo[] cboYItems;
326
private Label[] lblYItems;
327
private GraphModel model;
b'\\ No newline at end of file'