[927] | 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 |
|
---|
[922] | 15 | package de.ugoe.cs.autoquest.ui.swt;
|
---|
[526] | 16 |
|
---|
| 17 | import org.eclipse.swt.widgets.Dialog;
|
---|
| 18 | import org.eclipse.swt.widgets.Display;
|
---|
| 19 | import org.eclipse.swt.widgets.MessageBox;
|
---|
| 20 | import org.eclipse.swt.widgets.Shell;
|
---|
| 21 | import org.eclipse.swt.widgets.Group;
|
---|
| 22 | import org.eclipse.swt.SWT;
|
---|
| 23 | import org.eclipse.swt.widgets.Text;
|
---|
| 24 | import org.eclipse.swt.widgets.Button;
|
---|
| 25 | import org.eclipse.swt.widgets.Spinner;
|
---|
| 26 | import org.eclipse.swt.widgets.Label;
|
---|
| 27 | import org.eclipse.swt.layout.GridLayout;
|
---|
| 28 | import org.eclipse.swt.layout.GridData;
|
---|
| 29 |
|
---|
| 30 | import de.ugoe.cs.util.console.CommandExecuter;
|
---|
| 31 |
|
---|
| 32 | import org.eclipse.swt.events.SelectionAdapter;
|
---|
| 33 | import org.eclipse.swt.events.SelectionEvent;
|
---|
| 34 |
|
---|
| 35 | public class GenerateSequencesDialog extends Dialog {
|
---|
| 36 |
|
---|
[570] | 37 | private String processName;
|
---|
[526] | 38 |
|
---|
[570] | 39 | protected Button btnNumberAll;
|
---|
| 40 | protected Button btnLengthAll;
|
---|
| 41 | protected Spinner numberSpinner;
|
---|
| 42 | protected Spinner iterationsSpinner;
|
---|
| 43 | protected Spinner minLengthSpinner;
|
---|
| 44 | protected Spinner maxLengthSpinner;
|
---|
[526] | 45 |
|
---|
[570] | 46 | protected Shell shlGenerateSequences;
|
---|
| 47 | private Text sequencesNameText;
|
---|
[526] | 48 |
|
---|
[570] | 49 | /**
|
---|
| 50 | * Create the dialog.
|
---|
| 51 | *
|
---|
| 52 | * @param parent
|
---|
| 53 | * @param style
|
---|
| 54 | */
|
---|
| 55 | public GenerateSequencesDialog(Shell parent, int style) {
|
---|
| 56 | super(parent, style);
|
---|
| 57 | setText("SWT Dialog");
|
---|
| 58 | }
|
---|
[526] | 59 |
|
---|
[570] | 60 | /**
|
---|
| 61 | * Open the dialog.
|
---|
| 62 | */
|
---|
| 63 | public void open() {
|
---|
| 64 | createContents();
|
---|
| 65 | shlGenerateSequences.open();
|
---|
| 66 | shlGenerateSequences.layout();
|
---|
| 67 | Display display = getParent().getDisplay();
|
---|
| 68 | while (!shlGenerateSequences.isDisposed()) {
|
---|
| 69 | if (!display.readAndDispatch()) {
|
---|
| 70 | display.sleep();
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | /**
|
---|
| 76 | * Create contents of the dialog.
|
---|
| 77 | */
|
---|
| 78 | private void createContents() {
|
---|
| 79 | shlGenerateSequences = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
|
---|
| 80 | shlGenerateSequences.setSize(201, 303);
|
---|
| 81 | shlGenerateSequences.setText("Generate Sequences");
|
---|
| 82 | shlGenerateSequences.setLayout(new GridLayout(2, false));
|
---|
| 83 |
|
---|
| 84 | Group group = new Group(shlGenerateSequences, SWT.NONE);
|
---|
| 85 | group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
|
---|
| 86 | group.setText("Name");
|
---|
| 87 | group.setLayout(new GridLayout(1, false));
|
---|
| 88 |
|
---|
| 89 | sequencesNameText = new Text(group, SWT.BORDER);
|
---|
| 90 | sequencesNameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
|
---|
| 91 |
|
---|
| 92 | Group grpNumber = new Group(shlGenerateSequences, SWT.NONE);
|
---|
| 93 | grpNumber.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
|
---|
| 94 | grpNumber.setText("Number");
|
---|
| 95 | grpNumber.setLayout(new GridLayout(2, false));
|
---|
| 96 |
|
---|
| 97 | numberSpinner = new Spinner(grpNumber, SWT.BORDER);
|
---|
| 98 | numberSpinner.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
|
---|
| 99 | numberSpinner.setMinimum(1);
|
---|
| 100 | numberSpinner.setMaximum(Integer.MAX_VALUE);
|
---|
| 101 |
|
---|
| 102 | btnNumberAll = new Button(grpNumber, SWT.CHECK);
|
---|
| 103 | btnNumberAll.addSelectionListener(new SelectionAdapter() {
|
---|
| 104 | @Override
|
---|
| 105 | public void widgetSelected(SelectionEvent e) {
|
---|
| 106 | numberSpinner.setEnabled(!btnNumberAll.getSelection());
|
---|
| 107 | btnLengthAll.setEnabled(!btnNumberAll.getSelection());
|
---|
| 108 | iterationsSpinner.setEnabled(!btnNumberAll.getSelection());
|
---|
| 109 | }
|
---|
| 110 | });
|
---|
| 111 | btnNumberAll.setText("All");
|
---|
| 112 |
|
---|
| 113 | Group grpIterations = new Group(shlGenerateSequences, SWT.NONE);
|
---|
| 114 | grpIterations.setLayout(new GridLayout(1, false));
|
---|
| 115 | grpIterations.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
|
---|
| 116 | grpIterations.setText("Iterations");
|
---|
| 117 |
|
---|
| 118 | iterationsSpinner = new Spinner(grpIterations, SWT.BORDER);
|
---|
| 119 | iterationsSpinner.setMinimum(1);
|
---|
| 120 | iterationsSpinner.setMaximum(Integer.MAX_VALUE);
|
---|
| 121 | iterationsSpinner.setSelection(100000);
|
---|
| 122 | iterationsSpinner.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
|
---|
| 123 |
|
---|
| 124 | Group grpLength = new Group(shlGenerateSequences, SWT.NONE);
|
---|
| 125 | grpLength.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
|
---|
| 126 | grpLength.setText("Length");
|
---|
| 127 | grpLength.setLayout(new GridLayout(4, false));
|
---|
| 128 |
|
---|
| 129 | btnLengthAll = new Button(grpLength, SWT.CHECK);
|
---|
| 130 | btnLengthAll.addSelectionListener(new SelectionAdapter() {
|
---|
| 131 | @Override
|
---|
| 132 | public void widgetSelected(SelectionEvent e) {
|
---|
| 133 | minLengthSpinner.setEnabled(!btnLengthAll.getSelection());
|
---|
| 134 | maxLengthSpinner.setEnabled(!btnLengthAll.getSelection());
|
---|
| 135 | }
|
---|
| 136 | });
|
---|
| 137 | btnLengthAll.setText("All");
|
---|
| 138 | new Label(grpLength, SWT.NONE);
|
---|
| 139 | new Label(grpLength, SWT.NONE);
|
---|
| 140 | new Label(grpLength, SWT.NONE);
|
---|
| 141 |
|
---|
| 142 | Label label = new Label(grpLength, SWT.NONE);
|
---|
| 143 | label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
|
---|
| 144 | label.setText("Min.");
|
---|
| 145 |
|
---|
| 146 | minLengthSpinner = new Spinner(grpLength, SWT.BORDER);
|
---|
| 147 | minLengthSpinner.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
---|
| 148 | minLengthSpinner.setMinimum(1);
|
---|
| 149 |
|
---|
| 150 | Label label_1 = new Label(grpLength, SWT.NONE);
|
---|
| 151 | label_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1));
|
---|
| 152 | label_1.setText("Max.");
|
---|
| 153 |
|
---|
| 154 | maxLengthSpinner = new Spinner(grpLength, SWT.BORDER);
|
---|
| 155 | maxLengthSpinner.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
---|
| 156 | maxLengthSpinner.setToolTipText("0 means no limitations");
|
---|
| 157 | maxLengthSpinner.setMinimum(1);
|
---|
[1101] | 158 |
|
---|
| 159 | Button btnGenerate = new Button(shlGenerateSequences, SWT.NONE);
|
---|
| 160 | btnGenerate.setText("Generate!");
|
---|
[570] | 161 | btnGenerate.addSelectionListener(new SelectionAdapter() {
|
---|
| 162 | @Override
|
---|
| 163 | public void widgetSelected(SelectionEvent e) {
|
---|
| 164 | if ("".equals(sequencesNameText.getText())) {
|
---|
| 165 | MessageBox messageBox = new MessageBox(shlGenerateSequences, SWT.ERROR);
|
---|
| 166 | messageBox.setText("Error");
|
---|
| 167 | messageBox.setMessage("Sequences name not defined!");
|
---|
| 168 | messageBox.open();
|
---|
| 169 | return;
|
---|
| 170 | }
|
---|
| 171 | String sequencesName = sequencesNameText.getText();
|
---|
| 172 | int number = numberSpinner.getSelection();
|
---|
| 173 | int minLength = minLengthSpinner.getSelection();
|
---|
| 174 | int maxLength = maxLengthSpinner.getSelection();
|
---|
| 175 | int maxIter = iterationsSpinner.getSelection();
|
---|
| 176 | if (maxIter <= number) {
|
---|
| 177 | maxIter = number;
|
---|
| 178 | }
|
---|
| 179 | String command = "";
|
---|
| 180 | if (btnNumberAll.getSelection()) {
|
---|
| 181 | if (minLength > maxLength) {
|
---|
| 182 | MessageBox messageBox = new MessageBox(shlGenerateSequences, SWT.ERROR);
|
---|
| 183 | messageBox.setText("Error");
|
---|
| 184 | messageBox
|
---|
| 185 | .setMessage("Min. length must be smaller than or equal to max. length!");
|
---|
| 186 | messageBox.open();
|
---|
| 187 | return;
|
---|
| 188 | }
|
---|
| 189 | command =
|
---|
| 190 | "generateFixedLengthSequences " + processName + " " + sequencesName + " " +
|
---|
| 191 | minLength + " " + maxLength + " true";
|
---|
| 192 | }
|
---|
| 193 | else {
|
---|
| 194 | command =
|
---|
| 195 | "generateRandomSequences " + processName + " " + sequencesName + " " +
|
---|
| 196 | number + " " + maxIter;
|
---|
| 197 | if (!btnLengthAll.getSelection()) {
|
---|
| 198 | if (minLength > maxLength) {
|
---|
| 199 | MessageBox messageBox = new MessageBox(shlGenerateSequences, SWT.ERROR);
|
---|
| 200 | messageBox.setText("Error");
|
---|
| 201 | messageBox
|
---|
| 202 | .setMessage("Min. length must be smaller than or equal to max. length!");
|
---|
| 203 | messageBox.open();
|
---|
| 204 | return;
|
---|
| 205 | }
|
---|
| 206 | command += " " + minLength + " " + maxLength;
|
---|
| 207 | }
|
---|
| 208 | }
|
---|
| 209 | CommandExecuter.getInstance().exec(command);
|
---|
| 210 | shlGenerateSequences.dispose();
|
---|
| 211 | }
|
---|
| 212 | });
|
---|
| 213 |
|
---|
[1101] | 214 | Button btnAbort = new Button(shlGenerateSequences, SWT.NONE);
|
---|
| 215 | btnAbort.setText("Abort");
|
---|
[570] | 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 | }
|
---|
[526] | 228 | }
|
---|