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.graphingapi.ui.wizards.graph;
14
import org.eclipse.jface.wizard.WizardPage;
15
import org.eclipse.linuxtools.internal.systemtap.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
* @deprecated See {@link SelectGraphAndSeriesWizardPage}
37
public class SelectSeriesWizardPage extends WizardPage {
38
public SelectSeriesWizardPage() {
39
super("selectSeries"); //$NON-NLS-1$
40
setTitle(Localization.getString("SelectSeriesWizardPage.SelectSeries")); //$NON-NLS-1$
44
public void createControl(Composite parent) {
45
edit = ((SelectGraphWizard)super.getWizard()).isEditing();
46
model = ((SelectGraphWizard)super.getWizard()).model;
49
Composite comp = new Composite(parent, SWT.NULL);
50
comp.setLayout(new FormLayout());
51
FormData data1 = new FormData();
52
data1.left = new FormAttachment(0, 0);
53
data1.top = new FormAttachment(0, 0);
54
data1.right = new FormAttachment(40, 0);
55
data1.bottom = new FormAttachment(100, 0);
57
//Add the title wigets
58
Label lblTitle = new Label(comp, SWT.NONE);
59
lblTitle.setText(Localization.getString("SelectSeriesWizardPage.Title")); //$NON-NLS-1$
60
txtTitle = new Text(comp, SWT.BORDER);
62
txtTitle.setText(model.getGraphData().title);
64
txtTitle.addModifyListener(new ModifyListener() {
66
public void modifyText(ModifyEvent e) {
67
getWizard().getContainer().updateButtons();
68
if(txtTitle.getText().length() == 0) {
69
setErrorMessage(Localization.getString("SelectSeriesWizardPage.TitleNotSet")); //$NON-NLS-1$
72
setErrorMessage(null);
73
setMessage(""); //$NON-NLS-1$
77
data1 = new FormData();
78
data1.left = new FormAttachment(0,0);
79
data1.top = new FormAttachment(0,0);
81
lblTitle.setLayoutData(data1);
83
data1 = new FormData();
84
data1.left = new FormAttachment(0,0);
85
data1.top = new FormAttachment(lblTitle,0);
87
txtTitle.setLayoutData(data1);
90
//Add the data series widgets
91
data1 = new FormData();
92
data1.left = new FormAttachment(0, 0);
93
data1.top = new FormAttachment(txtTitle, 20);
94
data1.right = new FormAttachment(40, 0);
95
data1.bottom = new FormAttachment(100, 0);
97
Composite cmpGraphOpts = new Composite(comp, SWT.NONE);
98
cmpGraphOpts.setLayoutData(data1);
99
ColumnLayout colLayout = new ColumnLayout();
100
colLayout.maxNumColumns = 1;
101
cmpGraphOpts.setLayout(colLayout);
103
String[] labels = model.getSeries();
105
cboYItems = new Combo[labels.length];
106
lblYItems = new Label[cboYItems.length];
108
Label lblXItem = new Label(cmpGraphOpts, SWT.NONE);
109
lblXItem.setText(Localization.getString("SelectSeriesWizardPage.XSeries")); //$NON-NLS-1$
110
cboXItem = new Combo(cmpGraphOpts, SWT.DROP_DOWN);
111
cboXItem.addSelectionListener(new ComboSelectionListener());
112
cboXItem.add(Localization.getString("SelectSeriesWizardPage.RowID")); //$NON-NLS-1$
114
new Label(cmpGraphOpts, SWT.NONE); //Spacer
116
for(int i=0; i<cboYItems.length; i++) {
117
lblYItems[i] = new Label(cmpGraphOpts, SWT.NONE);
118
lblYItems[i].setText(Localization.getString("SelectSeriesWizardPage.YSeries") + i + ":"); //$NON-NLS-1$ //$NON-NLS-2$
119
cboYItems[i] = new Combo(cmpGraphOpts, SWT.DROP_DOWN);
120
cboYItems[i].addSelectionListener(new ComboSelectionListener());
123
cboYItems[i].add(Localization.getString("SelectSeriesWizardPage.NA")); //$NON-NLS-1$
124
cboYItems[i].setVisible(false);
125
lblYItems[i].setVisible(false);
129
for(int j,i=0; i<labels.length; i++) {
130
cboXItem.add(labels[i]);
131
for(j=0; j<lblYItems.length; j++)
132
cboYItems[j].add(labels[i]);
135
cboXItem.select(edit ? model.getXSeries() + 1 : 0);
136
boolean cvisible = edit;
138
cboYItems[0].select(model.getYSeries()[0]);
140
for(int i=1; i<cboYItems.length; i++) {
141
int index = edit && model.getYSeries().length > i ? model.getYSeries()[i] + 1 : 0;
142
cboYItems[i].select(index);
143
cboYItems[i].setVisible(cvisible);
144
lblYItems[i].setVisible(cvisible);
145
cvisible = (index > 0);
148
//Add the key filter wigets
149
btnKey = new Button(comp, SWT.CHECK);
150
btnKey.setText(Localization.getString("SelectSeriesWizardPage.UseHistoricalData")); //$NON-NLS-1$
151
btnKey.addSelectionListener(new SelectionListener() {
153
public void widgetDefaultSelected(SelectionEvent e) {}
155
public void widgetSelected(SelectionEvent e) {
156
txtKey.setEnabled(btnKey.getSelection());
160
data1 = new FormData();
161
data1.left = new FormAttachment(cmpGraphOpts, 20);
162
data1.top = new FormAttachment(txtTitle, 0);
163
data1.right = new FormAttachment(100, 0);
164
btnKey.setLayoutData(data1);
166
lblKey = new Label(comp, SWT.NONE);
167
lblKey.setText(Localization.getString("SelectSeriesWizardPage.KeyFilter")); //$NON-NLS-1$
168
txtKey = new Text(comp, SWT.BORDER);
169
if (edit && model.getGraphData().key != null) {
170
txtKey.setText(model.getGraphData().key);
174
txtKey.addModifyListener(new ModifyListener() {
176
public void modifyText(ModifyEvent e) {
177
getWizard().getContainer().updateButtons();
178
if(txtTitle.getText().length() == 0) {
179
setErrorMessage(Localization.getString("SelectSeriesWizardPage.KeyNotSet")); //$NON-NLS-1$
182
setErrorMessage(null);
183
setMessage(""); //$NON-NLS-1$
189
data1 = new FormData();
190
data1.left = new FormAttachment(cmpGraphOpts, 20);
191
data1.top = new FormAttachment(btnKey, 0);
192
data1.right = new FormAttachment(80, 0);
193
lblKey.setLayoutData(data1);
195
data1 = new FormData();
196
data1.left = new FormAttachment(cmpGraphOpts, 20);
197
data1.top = new FormAttachment(lblKey, 2);
198
data1.right = new FormAttachment(80, 0);
199
txtKey.setLayoutData(data1);
202
setKeyEnablement(GraphFactory.isKeyRequired(model.getGraphID(), model.getDataSet()),
203
GraphFactory.isKeyOptional(model.getGraphID(), model.getDataSet()));
210
public void setKeyEnablement(boolean required, boolean optional) {
211
btnKey.setVisible(optional);
212
txtKey.setVisible(required || optional);
213
lblKey.setVisible(required || optional);
214
txtKey.setEnabled(required);
218
public boolean canFlipToNextPage() {
223
public boolean isPageComplete() {
224
return saveDataToModel();
227
private boolean saveDataToModel() {
228
if(isSeriesUnique()) {
229
model.setTitle(txtTitle.getText());
231
if(null != txtKey && txtKey.isEnabled())
232
model.setKey(txtKey.getText());
236
model.setXSeries(cboXItem.getSelectionIndex()-1);
239
for(i=1, count=1; i<cboYItems.length; i++)
240
if(cboYItems[i].isVisible() && 0 != cboYItems[i].getSelectionIndex())
243
int[] ySeries = new int[count];
244
ySeries[0] = cboYItems[0].getSelectionIndex();
245
for(i=1; i<count; i++)
246
ySeries[i] = cboYItems[i].getSelectionIndex()-1;
247
model.setYSeries(ySeries);
253
private boolean isSeriesUnique() {
254
if("".equals(txtTitle.getText().trim())) //$NON-NLS-1$
256
if(null != txtKey && txtKey.isEnabled() && txtKey.getText().length() <= 0)
259
for(int j,i=0; i<cboYItems.length; i++) {
260
if(cboYItems[i].isVisible()) {
261
for(j=i+1; j<cboYItems.length; j++) {
262
if(cboYItems[j].isVisible()) {
263
if(0 > cboYItems[i].getSelectionIndex())
265
else if(0 > cboYItems[j].getSelectionIndex())
267
else if(cboYItems[i].getItem(cboYItems[i].getSelectionIndex()).equals(cboYItems[j].getItem(cboYItems[j].getSelectionIndex()))) {
272
if(0 > cboYItems[i].getSelectionIndex())
274
else if(0 > cboXItem.getSelectionIndex())
276
else if(cboYItems[i].getItem(cboYItems[i].getSelectionIndex()).equals(cboXItem.getItem(cboXItem.getSelectionIndex()))) {
285
public void dispose() {
304
if(null != cboYItems) {
305
for(int i=0; i<cboYItems.length; i++) {
306
if(null != cboYItems[i])
307
cboYItems[i].dispose();
309
if(null != lblYItems[i])
310
lblYItems[i].dispose();
319
private class ComboSelectionListener implements SelectionListener {
321
public void widgetDefaultSelected(SelectionEvent e) {}
324
public void widgetSelected(SelectionEvent e) {
325
if(!cboXItem.equals(e.getSource())) {
326
boolean setVisible = true;
327
if(GraphFactory.isMultiGraph(model.getGraphID())) {
328
for(int i=1; i<cboYItems.length; i++) {
329
cboYItems[i].setVisible(setVisible);
330
lblYItems[i].setVisible(setVisible);
331
if(cboYItems[i].getSelectionIndex() > 0 && cboYItems[i].isVisible())
339
if(!isSeriesUnique()) {
340
setErrorMessage(Localization.getString("SelectSeriesWizardPage.SeriesNotSelected")); //$NON-NLS-1$
343
setErrorMessage(null);
344
setMessage(""); //$NON-NLS-1$
346
if(txtTitle.getText().length() == 0) {
347
setErrorMessage(Localization.getString("SelectSeriesWizardPage.TitleNotSet")); //$NON-NLS-1$
351
getWizard().getContainer().updateButtons();
355
private Text txtTitle; //TODO: Move this to another page once graphs get more detail
357
private Button btnKey;
358
private Label lblKey;
359
private Combo cboXItem;
360
private Combo[] cboYItems;
361
private Label[] lblYItems;
362
private GraphModel model;
363
private boolean edit;
b'\\ No newline at end of file'