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