~ubuntu-branches/ubuntu/vivid/eclipse-linuxtools/vivid-proposed

« back to all changes in this revision

Viewing changes to systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/graph/SelectSeriesWizardPage.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam, Jakub Adam, tony mancill
  • Date: 2014-10-11 11:44:05 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20141011114405-yazjvxfzzhmi5sgj
Tags: 3.1.0-1
[ Jakub Adam ]
* New upstream release (Closes: #761524).
* Refreshed d/patches.
* Don't build removed feature org.eclipse.linuxtools.tools.launch
  - merged into org.eclipse.linuxtools.profiling.
* Use javac target 1.7.
* Build new feature org.eclipse.linuxtools.dataviewers.feature
  - required by Valgrind integration.
* Build-depend on eclipse-remote-services-api and eclipse-cdt-autotools.
* Bump Standards-Version to 3.9.6.
* Override incompatible-java-bytecode-format - linuxtools needs Java 7.
* Remove unused codeless-jar override.

[ tony mancill ]
* Tweak short package description to make lintian happy.

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.graphingapi.ui.wizards.graph;
13
 
 
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;
30
 
 
31
 
 
32
 
 
33
 
/**
34
 
 * @deprecated See {@link SelectGraphAndSeriesWizardPage}
35
 
 */
36
 
@Deprecated
37
 
public class SelectSeriesWizardPage extends WizardPage {
38
 
        public SelectSeriesWizardPage() {
39
 
                super("selectSeries"); //$NON-NLS-1$
40
 
                setTitle(Localization.getString("SelectSeriesWizardPage.SelectSeries")); //$NON-NLS-1$
41
 
        }
42
 
 
43
 
        @Override
44
 
        public void createControl(Composite parent) {
45
 
                edit = ((SelectGraphWizard)super.getWizard()).isEditing();
46
 
                model = ((SelectGraphWizard)super.getWizard()).model;
47
 
 
48
 
                //Set the layout data
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);
56
 
 
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);
61
 
                if (edit) {
62
 
                        txtTitle.setText(model.getGraphData().title);
63
 
                }
64
 
                txtTitle.addModifyListener(new ModifyListener() {
65
 
                        @Override
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$
70
 
                                        setMessage(null);
71
 
                                } else {
72
 
                                        setErrorMessage(null);
73
 
                                        setMessage(""); //$NON-NLS-1$
74
 
                                }
75
 
                        }
76
 
                });
77
 
                data1 = new FormData();
78
 
                data1.left = new FormAttachment(0,0);
79
 
                data1.top = new FormAttachment(0,0);
80
 
                data1.width = 200;
81
 
                lblTitle.setLayoutData(data1);
82
 
 
83
 
                data1 = new FormData();
84
 
                data1.left = new FormAttachment(0,0);
85
 
                data1.top = new FormAttachment(lblTitle,0);
86
 
                data1.width = 200;
87
 
                txtTitle.setLayoutData(data1);
88
 
 
89
 
 
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);
96
 
 
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);
102
 
 
103
 
                String[] labels = model.getSeries();
104
 
 
105
 
                cboYItems = new Combo[labels.length];
106
 
                lblYItems = new Label[cboYItems.length];
107
 
 
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$
113
 
 
114
 
                new Label(cmpGraphOpts, SWT.NONE);      //Spacer
115
 
 
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());
121
 
 
122
 
                        if(i>0) {
123
 
                                cboYItems[i].add(Localization.getString("SelectSeriesWizardPage.NA")); //$NON-NLS-1$
124
 
                                cboYItems[i].setVisible(false);
125
 
                                lblYItems[i].setVisible(false);
126
 
                        }
127
 
                }
128
 
 
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]);
133
 
                }
134
 
 
135
 
                cboXItem.select(edit ? model.getXSeries() + 1 : 0);
136
 
                boolean cvisible = edit;
137
 
                if (edit) {
138
 
                        cboYItems[0].select(model.getYSeries()[0]);
139
 
                }
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);
146
 
                }
147
 
 
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() {
152
 
                        @Override
153
 
                        public void widgetDefaultSelected(SelectionEvent e) {}
154
 
                        @Override
155
 
                        public void widgetSelected(SelectionEvent e) {
156
 
                                txtKey.setEnabled(btnKey.getSelection());
157
 
                        }
158
 
                });
159
 
 
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);
165
 
 
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);
171
 
                }
172
 
 
173
 
                if(null != txtKey) {
174
 
                        txtKey.addModifyListener(new ModifyListener() {
175
 
                                @Override
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$
180
 
                                                setMessage(null);
181
 
                                        } else {
182
 
                                                setErrorMessage(null);
183
 
                                                setMessage(""); //$NON-NLS-1$
184
 
                                        }
185
 
                                }
186
 
                        });
187
 
                }
188
 
 
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);
194
 
 
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);
200
 
 
201
 
                if (edit) {
202
 
                        setKeyEnablement(GraphFactory.isKeyRequired(model.getGraphID(), model.getDataSet()),
203
 
                                                         GraphFactory.isKeyOptional(model.getGraphID(), model.getDataSet()));
204
 
                }
205
 
 
206
 
                //Make comp visible
207
 
                setControl(comp);
208
 
        }
209
 
 
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);
215
 
        }
216
 
 
217
 
        @Override
218
 
        public boolean canFlipToNextPage() {
219
 
                return false;
220
 
        }
221
 
 
222
 
        @Override
223
 
        public boolean isPageComplete() {
224
 
                return saveDataToModel();
225
 
        }
226
 
 
227
 
        private boolean saveDataToModel() {
228
 
                if(isSeriesUnique()) {
229
 
                        model.setTitle(txtTitle.getText());
230
 
 
231
 
                        if(null != txtKey && txtKey.isEnabled())
232
 
                                model.setKey(txtKey.getText());
233
 
                        else
234
 
                                model.setKey(null);
235
 
 
236
 
                        model.setXSeries(cboXItem.getSelectionIndex()-1);
237
 
 
238
 
                        int i, count;
239
 
                        for(i=1, count=1; i<cboYItems.length; i++)
240
 
                                if(cboYItems[i].isVisible() && 0 != cboYItems[i].getSelectionIndex())
241
 
                                        count++;
242
 
 
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);
248
 
                        return true;
249
 
                }
250
 
                return false;
251
 
        }
252
 
 
253
 
        private boolean isSeriesUnique() {
254
 
                if("".equals(txtTitle.getText().trim())) //$NON-NLS-1$
255
 
                        return false;
256
 
                if(null != txtKey && txtKey.isEnabled() && txtKey.getText().length() <= 0)
257
 
                        return false;
258
 
 
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())
264
 
                                                        return false;
265
 
                                                else if(0 > cboYItems[j].getSelectionIndex())
266
 
                                                        return false;
267
 
                                                else if(cboYItems[i].getItem(cboYItems[i].getSelectionIndex()).equals(cboYItems[j].getItem(cboYItems[j].getSelectionIndex()))) {
268
 
                                                        return false;
269
 
                                                }
270
 
                                        }
271
 
                                }
272
 
                                if(0 > cboYItems[i].getSelectionIndex())
273
 
                                        return false;
274
 
                                else if(0 > cboXItem.getSelectionIndex())
275
 
                                        return false;
276
 
                                else if(cboYItems[i].getItem(cboYItems[i].getSelectionIndex()).equals(cboXItem.getItem(cboXItem.getSelectionIndex()))) {
277
 
                                        return false;
278
 
                                }
279
 
                        }
280
 
                }
281
 
                return true;
282
 
        }
283
 
 
284
 
        @Override
285
 
        public void dispose() {
286
 
                super.dispose();
287
 
                if(null != txtTitle)
288
 
                        txtTitle.dispose();
289
 
                txtTitle = null;
290
 
 
291
 
                if(null != txtKey)
292
 
                        txtKey.dispose();
293
 
                txtKey = null;
294
 
                if(null != btnKey)
295
 
                        btnKey.dispose();
296
 
                btnKey = null;
297
 
                if(null != lblKey)
298
 
                        lblKey.dispose();
299
 
                lblKey = null;
300
 
 
301
 
                if(null != cboXItem)
302
 
                        cboXItem.dispose();
303
 
                cboXItem = null;
304
 
                if(null != cboYItems) {
305
 
                        for(int i=0; i<cboYItems.length; i++) {
306
 
                                if(null != cboYItems[i])
307
 
                                        cboYItems[i].dispose();
308
 
                                cboYItems[i] = null;
309
 
                                if(null != lblYItems[i])
310
 
                                        lblYItems[i].dispose();
311
 
                                lblYItems[i] = null;
312
 
                        }
313
 
                }
314
 
                cboYItems = null;
315
 
                lblYItems = null;
316
 
                model = null;
317
 
        }
318
 
 
319
 
        private class ComboSelectionListener implements SelectionListener {
320
 
                @Override
321
 
                public void widgetDefaultSelected(SelectionEvent e) {}
322
 
 
323
 
                @Override
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())
332
 
                                                        setVisible = true;
333
 
                                                else
334
 
                                                        setVisible = false;
335
 
                                        }
336
 
                                }
337
 
                        }
338
 
 
339
 
                        if(!isSeriesUnique()) {
340
 
                                setErrorMessage(Localization.getString("SelectSeriesWizardPage.SeriesNotSelected")); //$NON-NLS-1$
341
 
                                setMessage(null);
342
 
                        } else {
343
 
                                setErrorMessage(null);
344
 
                                setMessage(""); //$NON-NLS-1$
345
 
                        }
346
 
                        if(txtTitle.getText().length() == 0) {
347
 
                                setErrorMessage(Localization.getString("SelectSeriesWizardPage.TitleNotSet")); //$NON-NLS-1$
348
 
                                setMessage(null);
349
 
                        }
350
 
 
351
 
                        getWizard().getContainer().updateButtons();
352
 
                }
353
 
        }
354
 
 
355
 
        private Text txtTitle;          //TODO: Move this to another page once graphs get more detail
356
 
        private Text txtKey;
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;
364
 
}
 
 
b'\\ No newline at end of file'