source: trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt/GenerateSequencesDialog.java @ 927

Last change on this file since 927 was 927, checked in by sherbold, 12 years ago
  • added copyright under the Apache License, Version 2.0
  • Property svn:mime-type set to text/plain
File size: 9.5 KB
Line 
1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.autoquest.ui.swt;
16
17import org.eclipse.swt.widgets.Dialog;
18import org.eclipse.swt.widgets.Display;
19import org.eclipse.swt.widgets.MessageBox;
20import org.eclipse.swt.widgets.Shell;
21import org.eclipse.swt.widgets.Group;
22import org.eclipse.swt.SWT;
23import org.eclipse.swt.widgets.Text;
24import org.eclipse.swt.widgets.Button;
25import org.eclipse.swt.widgets.Spinner;
26import org.eclipse.swt.widgets.Label;
27import org.eclipse.ui.forms.widgets.FormToolkit;
28import org.eclipse.swt.layout.GridLayout;
29import org.eclipse.swt.layout.GridData;
30
31import de.ugoe.cs.util.console.CommandExecuter;
32
33import org.eclipse.swt.events.SelectionAdapter;
34import org.eclipse.swt.events.SelectionEvent;
35
36public class GenerateSequencesDialog extends Dialog {
37
38    private String processName;
39
40    protected Button btnNumberAll;
41    protected Button btnLengthAll;
42    protected Spinner numberSpinner;
43    protected Spinner iterationsSpinner;
44    protected Spinner minLengthSpinner;
45    protected Spinner maxLengthSpinner;
46
47    protected Shell shlGenerateSequences;
48    private Text sequencesNameText;
49    private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
50
51    /**
52     * Create the dialog.
53     *
54     * @param parent
55     * @param style
56     */
57    public GenerateSequencesDialog(Shell parent, int style) {
58        super(parent, style);
59        setText("SWT Dialog");
60    }
61
62    /**
63     * Open the dialog.
64     */
65    public void open() {
66        createContents();
67        shlGenerateSequences.open();
68        shlGenerateSequences.layout();
69        Display display = getParent().getDisplay();
70        while (!shlGenerateSequences.isDisposed()) {
71            if (!display.readAndDispatch()) {
72                display.sleep();
73            }
74        }
75    }
76
77    /**
78     * Create contents of the dialog.
79     */
80    private void createContents() {
81        shlGenerateSequences = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
82        shlGenerateSequences.setSize(201, 303);
83        shlGenerateSequences.setText("Generate Sequences");
84        shlGenerateSequences.setLayout(new GridLayout(2, false));
85
86        Group group = new Group(shlGenerateSequences, SWT.NONE);
87        group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
88        group.setText("Name");
89        group.setLayout(new GridLayout(1, false));
90
91        sequencesNameText = new Text(group, SWT.BORDER);
92        sequencesNameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
93
94        Group grpNumber = new Group(shlGenerateSequences, SWT.NONE);
95        grpNumber.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
96        grpNumber.setText("Number");
97        grpNumber.setLayout(new GridLayout(2, false));
98
99        numberSpinner = new Spinner(grpNumber, SWT.BORDER);
100        numberSpinner.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
101        numberSpinner.setMinimum(1);
102        numberSpinner.setMaximum(Integer.MAX_VALUE);
103
104        btnNumberAll = new Button(grpNumber, SWT.CHECK);
105        btnNumberAll.addSelectionListener(new SelectionAdapter() {
106            @Override
107            public void widgetSelected(SelectionEvent e) {
108                numberSpinner.setEnabled(!btnNumberAll.getSelection());
109                btnLengthAll.setEnabled(!btnNumberAll.getSelection());
110                iterationsSpinner.setEnabled(!btnNumberAll.getSelection());
111            }
112        });
113        btnNumberAll.setText("All");
114
115        Group grpIterations = new Group(shlGenerateSequences, SWT.NONE);
116        grpIterations.setLayout(new GridLayout(1, false));
117        grpIterations.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
118        grpIterations.setText("Iterations");
119
120        iterationsSpinner = new Spinner(grpIterations, SWT.BORDER);
121        iterationsSpinner.setMinimum(1);
122        iterationsSpinner.setMaximum(Integer.MAX_VALUE);
123        iterationsSpinner.setSelection(100000);
124        iterationsSpinner.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
125
126        Group grpLength = new Group(shlGenerateSequences, SWT.NONE);
127        grpLength.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
128        grpLength.setText("Length");
129        grpLength.setLayout(new GridLayout(4, false));
130
131        btnLengthAll = new Button(grpLength, SWT.CHECK);
132        btnLengthAll.addSelectionListener(new SelectionAdapter() {
133            @Override
134            public void widgetSelected(SelectionEvent e) {
135                minLengthSpinner.setEnabled(!btnLengthAll.getSelection());
136                maxLengthSpinner.setEnabled(!btnLengthAll.getSelection());
137            }
138        });
139        btnLengthAll.setText("All");
140        new Label(grpLength, SWT.NONE);
141        new Label(grpLength, SWT.NONE);
142        new Label(grpLength, SWT.NONE);
143
144        Label label = new Label(grpLength, SWT.NONE);
145        label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
146        label.setText("Min.");
147
148        minLengthSpinner = new Spinner(grpLength, SWT.BORDER);
149        minLengthSpinner.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
150        minLengthSpinner.setMinimum(1);
151
152        Label label_1 = new Label(grpLength, SWT.NONE);
153        label_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1));
154        label_1.setText("Max.");
155
156        maxLengthSpinner = new Spinner(grpLength, SWT.BORDER);
157        maxLengthSpinner.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
158        maxLengthSpinner.setToolTipText("0 means no limitations");
159        maxLengthSpinner.setMinimum(1);
160
161        Button btnGenerate = formToolkit.createButton(shlGenerateSequences, "Generate!", SWT.NONE);
162        btnGenerate.addSelectionListener(new SelectionAdapter() {
163            @Override
164            public void widgetSelected(SelectionEvent e) {
165                if ("".equals(sequencesNameText.getText())) {
166                    MessageBox messageBox = new MessageBox(shlGenerateSequences, SWT.ERROR);
167                    messageBox.setText("Error");
168                    messageBox.setMessage("Sequences name not defined!");
169                    messageBox.open();
170                    return;
171                }
172                String sequencesName = sequencesNameText.getText();
173                int number = numberSpinner.getSelection();
174                int minLength = minLengthSpinner.getSelection();
175                int maxLength = maxLengthSpinner.getSelection();
176                int maxIter = iterationsSpinner.getSelection();
177                if (maxIter <= number) {
178                    maxIter = number;
179                }
180                String command = "";
181                if (btnNumberAll.getSelection()) {
182                    if (minLength > maxLength) {
183                        MessageBox messageBox = new MessageBox(shlGenerateSequences, SWT.ERROR);
184                        messageBox.setText("Error");
185                        messageBox
186                            .setMessage("Min. length must be smaller than or equal to max. length!");
187                        messageBox.open();
188                        return;
189                    }
190                    command =
191                        "generateFixedLengthSequences " + processName + " " + sequencesName + " " +
192                            minLength + " " + maxLength + " true";
193                }
194                else {
195                    command =
196                        "generateRandomSequences " + processName + " " + sequencesName + " " +
197                            number + " " + maxIter;
198                    if (!btnLengthAll.getSelection()) {
199                        if (minLength > maxLength) {
200                            MessageBox messageBox = new MessageBox(shlGenerateSequences, SWT.ERROR);
201                            messageBox.setText("Error");
202                            messageBox
203                                .setMessage("Min. length must be smaller than or equal to max. length!");
204                            messageBox.open();
205                            return;
206                        }
207                        command += " " + minLength + " " + maxLength;
208                    }
209                }
210                CommandExecuter.getInstance().exec(command);
211                shlGenerateSequences.dispose();
212            }
213        });
214
215        Button btnAbort = formToolkit.createButton(shlGenerateSequences, "Abort", SWT.NONE);
216        btnAbort.addSelectionListener(new SelectionAdapter() {
217            @Override
218            public void widgetSelected(SelectionEvent e) {
219                shlGenerateSequences.dispose();
220            }
221        });
222
223    }
224
225    public void setProcessName(String name) {
226        this.processName = name;
227    }
228}
Note: See TracBrowser for help on using the repository browser.