source: trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/swt/GenerateSequencesDialog.java @ 194

Last change on this file since 194 was 194, checked in by sherbold, 13 years ago

Work on the SWT GUI prototype. The prototype is still incomplete and should not be used.

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