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

« back to all changes in this revision

Viewing changes to systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/graph/SelectSeriesWizardPage.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
 
10
 *******************************************************************************/
 
11
 
 
12
package org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.wizards.graph;
 
13
 
 
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;
 
30
 
 
31
 
 
32
 
 
33
 
 
34
public class SelectSeriesWizardPage extends WizardPage {
 
35
        public SelectSeriesWizardPage() {
 
36
                super("selectSeries");
 
37
                setTitle(Localization.getString("SelectSeriesWizardPage.SelectSeries"));
 
38
        }
 
39
        
 
40
        public void createControl(Composite parent) {
 
41
                model = ((SelectGraphWizard)super.getWizard()).model;
 
42
                
 
43
                //Set the layout data
 
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);
 
51
 
 
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"));
 
61
                                        setMessage(null);
 
62
                                } else {
 
63
                                        setErrorMessage(null);
 
64
                                        setMessage("");
 
65
                                }
 
66
                        }
 
67
                });
 
68
                data1 = new FormData();
 
69
                data1.left = new FormAttachment(0,0);
 
70
                data1.top = new FormAttachment(0,0);
 
71
                data1.width = 200;
 
72
                lblTitle.setLayoutData(data1);
 
73
 
 
74
                data1 = new FormData();
 
75
                data1.left = new FormAttachment(0,0);
 
76
                data1.top = new FormAttachment(lblTitle,0);
 
77
                data1.width = 200;
 
78
                txtTitle.setLayoutData(data1);
 
79
 
 
80
 
 
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);
 
87
                
 
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);
 
93
 
 
94
                String[] labels = model.getSeries();
 
95
 
 
96
                cboYItems = new Combo[labels.length];
 
97
                lblYItems = new Label[cboYItems.length];
 
98
 
 
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"));
 
104
                cboXItem.select(0);
 
105
 
 
106
                new Label(cmpGraphOpts, SWT.NONE);      //Spacer
 
107
                
 
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());
 
113
 
 
114
                        if(i>0) {
 
115
                                cboYItems[i].add(Localization.getString("SelectSeriesWizardPage.NA"));
 
116
                                cboYItems[i].select(0);
 
117
                                cboYItems[i].setVisible(false);
 
118
                                lblYItems[i].setVisible(false);
 
119
                        }
 
120
                }
 
121
 
 
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]);
 
126
                }
 
127
                
 
128
                
 
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());
 
136
                        }
 
137
                });
 
138
                
 
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);
 
144
                
 
145
                lblKey = new Label(comp, SWT.NONE);
 
146
                lblKey.setText(Localization.getString("SelectSeriesWizardPage.KeyFilter"));
 
147
                txtKey = new Text(comp, SWT.BORDER);
 
148
                
 
149
                if(null != txtKey) {
 
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"));
 
155
                                                setMessage(null);
 
156
                                        } else {
 
157
                                                setErrorMessage(null);
 
158
                                                setMessage(""); //$NON-NLS-1$
 
159
                                        }
 
160
                                }
 
161
                        });
 
162
                }
 
163
                
 
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);
 
169
                
 
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);
 
175
 
 
176
                //Make comp visible
 
177
                setControl(comp);
 
178
        }
 
179
        
 
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);
 
185
        }
 
186
        
 
187
        public boolean canFlipToNextPage() {
 
188
                return false;
 
189
        }
 
190
 
 
191
        public boolean isPageComplete() {
 
192
                return saveDataToModel();
 
193
        }
 
194
 
 
195
        private boolean saveDataToModel() {
 
196
                if(isSeriesUnique()) {
 
197
                        model.setTitle(txtTitle.getText());
 
198
                        
 
199
                        if(null != txtKey && txtKey.isEnabled())
 
200
                                model.setKey(txtKey.getText());
 
201
                        else
 
202
                                model.setKey(null);
 
203
                        
 
204
                        model.setXSeries(cboXItem.getSelectionIndex()-1);
 
205
                        
 
206
                        int i, count;
 
207
                        for(i=1, count=1; i<cboYItems.length; i++)
 
208
                                if(cboYItems[i].isVisible() && 0 != cboYItems[i].getSelectionIndex())
 
209
                                        count++;
 
210
 
 
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);
 
216
                        return true;
 
217
                }
 
218
                return false;
 
219
        }
 
220
 
 
221
        private boolean isSeriesUnique() {
 
222
                if("".equals(txtTitle.getText().trim()))
 
223
                        return false;
 
224
                if(null != txtKey && txtKey.isEnabled() && txtKey.getText().length() <= 0)
 
225
                        return false;
 
226
                
 
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())
 
232
                                                        return false;
 
233
                                                else if(0 > cboYItems[j].getSelectionIndex())
 
234
                                                        return false;
 
235
                                                else if(cboYItems[i].getItem(cboYItems[i].getSelectionIndex()).equals(cboYItems[j].getItem(cboYItems[j].getSelectionIndex()))) {
 
236
                                                        return false;
 
237
                                                }
 
238
                                        }
 
239
                                }
 
240
                                if(0 > cboYItems[i].getSelectionIndex())
 
241
                                        return false;
 
242
                                else if(0 > cboXItem.getSelectionIndex())
 
243
                                        return false;
 
244
                                else if(cboYItems[i].getItem(cboYItems[i].getSelectionIndex()).equals(cboXItem.getItem(cboXItem.getSelectionIndex()))) {
 
245
                                        return false;
 
246
                                }
 
247
                        }
 
248
                }
 
249
                return true;
 
250
        }
 
251
 
 
252
        public void dispose() {
 
253
                super.dispose();
 
254
                if(null != txtTitle)
 
255
                        txtTitle.dispose();
 
256
                txtTitle = null;
 
257
                
 
258
                if(null != txtKey)
 
259
                        txtKey.dispose();
 
260
                txtKey = null;
 
261
                if(null != btnKey)
 
262
                        btnKey.dispose();
 
263
                btnKey = null;
 
264
                if(null != lblKey)
 
265
                        lblKey.dispose();
 
266
                lblKey = null;
 
267
 
 
268
                if(null != cboXItem)
 
269
                        cboXItem.dispose();
 
270
                cboXItem = null;
 
271
                if(null != cboYItems) {
 
272
                        for(int i=0; i<cboYItems.length; i++) {
 
273
                                if(null != cboYItems[i])
 
274
                                        cboYItems[i].dispose();
 
275
                                cboYItems[i] = null;
 
276
                                if(null != lblYItems[i])
 
277
                                        lblYItems[i].dispose();
 
278
                                lblYItems[i] = null;
 
279
                        }
 
280
                }
 
281
                cboYItems = null;
 
282
                lblYItems = null;
 
283
                model = null;
 
284
        }
 
285
        
 
286
        private class ComboSelectionListener implements SelectionListener {
 
287
                public void widgetDefaultSelected(SelectionEvent e) {}
 
288
                
 
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())
 
297
                                                        setVisible = true;
 
298
                                                else
 
299
                                                        setVisible = false;
 
300
                                        }
 
301
                                }
 
302
                        }
 
303
 
 
304
                        if(!isSeriesUnique()) {
 
305
                                setErrorMessage(Localization.getString("SelectSeriesWizardPage.SeriesNotSelected"));
 
306
                                setMessage(null);
 
307
                        } else {
 
308
                                setErrorMessage(null);
 
309
                                setMessage("");
 
310
                        }
 
311
                        if(txtTitle.getText().length() == 0) {
 
312
                                setErrorMessage(Localization.getString("SelectSeriesWizardPage.TitleNotSet"));
 
313
                                setMessage(null);
 
314
                        }
 
315
 
 
316
                        getWizard().getContainer().updateButtons();
 
317
                }
 
318
        }
 
319
 
 
320
        private Text txtTitle;          //TODO: Move this to another page once graphs get more detail
 
321
        private Text txtKey;
 
322
        private Button btnKey;
 
323
        private Label lblKey;
 
324
        private Combo cboXItem;
 
325
        private Combo[] cboYItems;
 
326
        private Label[] lblYItems;
 
327
        private GraphModel model;
 
328
}
 
 
b'\\ No newline at end of file'