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