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

Last change on this file since 287 was 287, checked in by sherbold, 12 years ago
  • fixed some code smells
  • 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 Shell shlGenerateSequences;
34        private Text sequencesNameText;
35        private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
36
37        /**
38         * Create the dialog.
39         * @param parent
40         * @param style
41         */
42        public GenerateSequencesDialog(Shell parent, int style) {
43                super(parent, style);
44                setText("SWT Dialog");
45        }
46
47        /**
48         * Open the dialog.
49         */
50        public void open() {
51                createContents();
52                shlGenerateSequences.open();
53                shlGenerateSequences.layout();
54                Display display = getParent().getDisplay();
55                while (!shlGenerateSequences.isDisposed()) {
56                        if (!display.readAndDispatch()) {
57                                display.sleep();
58                        }
59                }
60        }
61
62        /**
63         * Create contents of the dialog.
64         */
65        private void createContents() {
66                shlGenerateSequences = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
67                shlGenerateSequences.setSize(201, 303);
68                shlGenerateSequences.setText("Generate Sequences");
69                shlGenerateSequences.setLayout(new GridLayout(2, false));
70               
71                Group group = new Group(shlGenerateSequences, SWT.NONE);
72                group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
73                group.setText("Name");
74                group.setLayout(new GridLayout(1, false));
75               
76                sequencesNameText = new Text(group, SWT.BORDER);
77                sequencesNameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
78               
79                Group grpNumber = new Group(shlGenerateSequences, SWT.NONE);
80                grpNumber.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
81                grpNumber.setText("Number");
82                grpNumber.setLayout(new GridLayout(2, false));
83               
84                numberSpinner = new Spinner(grpNumber, SWT.BORDER);
85                numberSpinner.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
86                numberSpinner.setMinimum(1);
87                numberSpinner.setMaximum(Integer.MAX_VALUE);
88               
89                btnNumberAll = new Button(grpNumber, SWT.CHECK);
90                btnNumberAll.addSelectionListener(new SelectionAdapter() {
91                        @Override
92                        public void widgetSelected(SelectionEvent e) {
93                                numberSpinner.setEnabled(!btnNumberAll.getSelection());
94                                btnLengthAll.setEnabled(!btnNumberAll.getSelection());
95                                iterationsSpinner.setEnabled(!btnNumberAll.getSelection());
96                        }
97                });
98                btnNumberAll.setText("All");
99               
100                Group grpIterations = new Group(shlGenerateSequences, SWT.NONE);
101                grpIterations.setLayout(new GridLayout(1, false));
102                grpIterations.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
103                grpIterations.setText("Iterations");
104               
105                iterationsSpinner = new Spinner(grpIterations, SWT.BORDER);
106                iterationsSpinner.setMinimum(1);
107                iterationsSpinner.setMaximum(Integer.MAX_VALUE);
108                iterationsSpinner.setSelection(100000);
109                iterationsSpinner.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
110               
111                Group grpLength = new Group(shlGenerateSequences, SWT.NONE);
112                grpLength.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
113                grpLength.setText("Length");
114                grpLength.setLayout(new GridLayout(4, false));
115               
116                btnLengthAll = new Button(grpLength, SWT.CHECK);
117                btnLengthAll.addSelectionListener(new SelectionAdapter() {
118                        @Override
119                        public void widgetSelected(SelectionEvent e) {
120                                minLengthSpinner.setEnabled(!btnLengthAll.getSelection());
121                                maxLengthSpinner.setEnabled(!btnLengthAll.getSelection());
122                        }
123                });
124                btnLengthAll.setText("All");
125                new Label(grpLength, SWT.NONE);
126                new Label(grpLength, SWT.NONE);
127                new Label(grpLength, SWT.NONE);
128               
129                Label label = new Label(grpLength, SWT.NONE);
130                label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
131                label.setText("Min.");
132               
133                minLengthSpinner = new Spinner(grpLength, SWT.BORDER);
134                minLengthSpinner.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
135                minLengthSpinner.setMinimum(1);
136               
137                Label label_1 = new Label(grpLength, SWT.NONE);
138                label_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1));
139                label_1.setText("Max.");
140               
141                maxLengthSpinner = new Spinner(grpLength, SWT.BORDER);
142                maxLengthSpinner.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
143                maxLengthSpinner.setToolTipText("0 means no limitations");
144                maxLengthSpinner.setMinimum(1);
145               
146                Button btnGenerate = formToolkit.createButton(shlGenerateSequences, "Generate!", SWT.NONE);
147                btnGenerate.addSelectionListener(new SelectionAdapter() {
148                        @Override
149                        public void widgetSelected(SelectionEvent e) {
150                                if("".equals(sequencesNameText.getText())) {
151                                        MessageBox messageBox = new MessageBox(shlGenerateSequences, SWT.ERROR);
152                                        messageBox.setText("Error");
153                                        messageBox.setMessage("Sequences name not defined!");
154                                        messageBox.open();
155                                        return;
156                                }
157                                String sequencesName = sequencesNameText.getText();
158                                int number = numberSpinner.getSelection();
159                                int minLength = minLengthSpinner.getSelection();
160                                int maxLength = maxLengthSpinner.getSelection();
161                                int maxIter = iterationsSpinner.getSelection();
162                                if( maxIter<=number ) {
163                                        maxIter = number;
164                                }
165                                String command = "";
166                                if( btnNumberAll.getSelection() ) {
167                                        if( minLength>maxLength ) {
168                                                MessageBox messageBox = new MessageBox(shlGenerateSequences, SWT.ERROR);
169                                                messageBox.setText("Error");
170                                                messageBox.setMessage("Min. length must be smaller than or equal to max. length!");
171                                                messageBox.open();
172                                                return;
173                                        }
174                                        command = "generateFixedLengthSequences " + processName + " " + sequencesName + " " + minLength + " " + maxLength + " true";
175                                } else {
176                                        command = "generateRandomSequences " + processName + " " + sequencesName + " " + number + " " + maxIter;
177                                        if( !btnLengthAll.getSelection() ) {
178                                                if( minLength>maxLength ) {
179                                                        MessageBox messageBox = new MessageBox(shlGenerateSequences, SWT.ERROR);
180                                                        messageBox.setText("Error");
181                                                        messageBox.setMessage("Min. length must be smaller than or equal to max. length!");
182                                                        messageBox.open();
183                                                        return;
184                                                }
185                                                command += " " + minLength + " " + maxLength;
186                                        }
187                                }
188                                CommandExecuter.getInstance().exec(command);
189                                shlGenerateSequences.dispose();
190                        }
191                });
192               
193                Button btnAbort = formToolkit.createButton(shlGenerateSequences, "Abort", SWT.NONE);
194                btnAbort.addSelectionListener(new SelectionAdapter() {
195                        @Override
196                        public void widgetSelected(SelectionEvent e) {
197                                shlGenerateSequences.dispose();
198                        }
199                });
200
201        }
202       
203        public void setProcessName(String name) {
204                this.processName = name;
205        }
206}
Note: See TracBrowser for help on using the repository browser.