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 |
|
---|
15 | package de.ugoe.cs.autoquest.ui.swt;
|
---|
16 |
|
---|
17 | import java.util.List;
|
---|
18 | import java.util.logging.Level;
|
---|
19 |
|
---|
20 | import org.eclipse.swt.widgets.Display;
|
---|
21 | import org.eclipse.swt.widgets.Shell;
|
---|
22 | import org.eclipse.swt.widgets.Menu;
|
---|
23 | import org.eclipse.swt.SWT;
|
---|
24 | import org.eclipse.swt.widgets.FileDialog;
|
---|
25 | import org.eclipse.swt.widgets.MenuItem;
|
---|
26 | import org.eclipse.swt.widgets.TabFolder;
|
---|
27 | import org.eclipse.swt.widgets.TabItem;
|
---|
28 | import org.eclipse.swt.layout.GridLayout;
|
---|
29 | import org.eclipse.swt.layout.GridData;
|
---|
30 | import org.eclipse.swt.events.SelectionAdapter;
|
---|
31 | import org.eclipse.swt.events.SelectionEvent;
|
---|
32 |
|
---|
33 | import de.ugoe.cs.util.console.CommandExecuter;
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * <p>
|
---|
37 | * Main window of the SWT GUI.
|
---|
38 | * </p>
|
---|
39 | *
|
---|
40 | * @author Steffen Herbold
|
---|
41 | * @version 1.0
|
---|
42 | */
|
---|
43 | public class MainWindow {
|
---|
44 |
|
---|
45 | private List<String> startupCommands;
|
---|
46 |
|
---|
47 | private final Level traceLevel;
|
---|
48 |
|
---|
49 | protected Shell shlEventbenchConsole;
|
---|
50 |
|
---|
51 | protected TabItem consoleTab;
|
---|
52 | protected TabItem sequencesTab;
|
---|
53 | protected TabItem modelsTab;
|
---|
54 | protected TabItem guiModelsTab;
|
---|
55 | protected TabItem usabilityTab;
|
---|
56 | protected TabItem dataTab;
|
---|
57 | protected ConsoleTabComposite consoleTabComposite;
|
---|
58 | protected SequencesTabComposite sequencesTabComposite;
|
---|
59 | protected ModelsTabComposite modelsTabComposite;
|
---|
60 | protected GuiModelTabComposite guiModelTabComposite;
|
---|
61 | protected UsabilityTabComposite usabilityTabComposite;
|
---|
62 | protected DataTabComposite dataTabComposite;
|
---|
63 |
|
---|
64 | protected CommandHistoryDialog historyDialog;
|
---|
65 |
|
---|
66 | public MainWindow(List<String> startupCommands, Level traceLevel) {
|
---|
67 | this.startupCommands = startupCommands;
|
---|
68 | this.traceLevel = traceLevel;
|
---|
69 | }
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * <p>
|
---|
73 | * Open the window.
|
---|
74 | * </p>
|
---|
75 | *
|
---|
76 | * @wbp.parser.entryPoint
|
---|
77 | */
|
---|
78 | public void open() {
|
---|
79 | Display display = Display.getDefault();
|
---|
80 | createContents();
|
---|
81 | new SWTConsole(consoleTabComposite.textConsoleOutput, traceLevel);
|
---|
82 | historyDialog = new CommandHistoryDialog(shlEventbenchConsole, SWT.NONE);
|
---|
83 | shlEventbenchConsole.open();
|
---|
84 | shlEventbenchConsole.layout();
|
---|
85 | for (String command : startupCommands) {
|
---|
86 | CommandExecuter.getInstance().exec(command);
|
---|
87 | }
|
---|
88 | while (!shlEventbenchConsole.isDisposed()) {
|
---|
89 | if (!display.readAndDispatch()) {
|
---|
90 | display.sleep();
|
---|
91 | }
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * <p>
|
---|
97 | * Create contents of the window.
|
---|
98 | * </p>
|
---|
99 | */
|
---|
100 | protected void createContents() {
|
---|
101 | shlEventbenchConsole = new Shell();
|
---|
102 | shlEventbenchConsole.setSize(800, 600);
|
---|
103 | shlEventbenchConsole.setText("AutoQUEST Console");
|
---|
104 | shlEventbenchConsole.setLayout(new GridLayout(1, false));
|
---|
105 |
|
---|
106 | createMenu();
|
---|
107 | createTabs();
|
---|
108 | }
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * </p> Creates the menu of the window. </p>
|
---|
112 | */
|
---|
113 | private void createMenu() {
|
---|
114 | Menu menu = new Menu(shlEventbenchConsole, SWT.BAR);
|
---|
115 | shlEventbenchConsole.setMenuBar(menu);
|
---|
116 |
|
---|
117 | MenuItem mntmFile = new MenuItem(menu, SWT.CASCADE);
|
---|
118 | mntmFile.setText("File");
|
---|
119 |
|
---|
120 | Menu menu_1 = new Menu(mntmFile);
|
---|
121 | mntmFile.setMenu(menu_1);
|
---|
122 |
|
---|
123 | MenuItem mntmShowHistory = new MenuItem(menu_1, SWT.NONE);
|
---|
124 | mntmShowHistory.addSelectionListener(new SelectionAdapter() {
|
---|
125 | @Override
|
---|
126 | public void widgetSelected(SelectionEvent e) {
|
---|
127 | if (!historyDialog.isOpen()) {
|
---|
128 | historyDialog.open();
|
---|
129 | }
|
---|
130 | }
|
---|
131 | });
|
---|
132 | mntmShowHistory.setText("Show History");
|
---|
133 |
|
---|
134 | MenuItem mntmExecBatchFile = new MenuItem(menu_1, SWT.NONE);
|
---|
135 | mntmExecBatchFile.addSelectionListener(new SelectionAdapter() {
|
---|
136 | @Override
|
---|
137 | public void widgetSelected(SelectionEvent e) {
|
---|
138 | FileDialog fileDialog = new FileDialog(shlEventbenchConsole, SWT.OPEN);
|
---|
139 | String filename = fileDialog.open();
|
---|
140 | if (filename != null) {
|
---|
141 | String command = "exec '" + filename + "'";
|
---|
142 | CommandExecuter.getInstance().exec(command);
|
---|
143 | }
|
---|
144 | }
|
---|
145 | });
|
---|
146 | mntmExecBatchFile.setText("Exec. Batch File");
|
---|
147 |
|
---|
148 | new MenuItem(menu_1, SWT.SEPARATOR);
|
---|
149 |
|
---|
150 | MenuItem mntmLoad = new MenuItem(menu_1, SWT.NONE);
|
---|
151 | mntmLoad.addSelectionListener(new SelectionAdapter() {
|
---|
152 | @Override
|
---|
153 | public void widgetSelected(SelectionEvent e) {
|
---|
154 | FileDialog fileDialog = new FileDialog(shlEventbenchConsole, SWT.OPEN);
|
---|
155 | String filename = fileDialog.open();
|
---|
156 | if (filename != null) {
|
---|
157 | String command = "load '" + filename + "'";
|
---|
158 | CommandExecuter.getInstance().exec(command);
|
---|
159 | }
|
---|
160 | }
|
---|
161 | });
|
---|
162 | mntmLoad.setText("Load...");
|
---|
163 |
|
---|
164 | MenuItem mntmSave = new MenuItem(menu_1, SWT.NONE);
|
---|
165 | mntmSave.addSelectionListener(new SelectionAdapter() {
|
---|
166 | @Override
|
---|
167 | public void widgetSelected(SelectionEvent e) {
|
---|
168 | FileDialog fileDialog = new FileDialog(shlEventbenchConsole, SWT.SAVE);
|
---|
169 | String filename = fileDialog.open();
|
---|
170 | if (filename != null) {
|
---|
171 | String command = "save '" + filename + "'";
|
---|
172 | CommandExecuter.getInstance().exec(command);
|
---|
173 | }
|
---|
174 | }
|
---|
175 | });
|
---|
176 | mntmSave.setText("Save...");
|
---|
177 |
|
---|
178 | new MenuItem(menu_1, SWT.SEPARATOR);
|
---|
179 |
|
---|
180 | MenuItem mntmExit = new MenuItem(menu_1, SWT.NONE);
|
---|
181 | mntmExit.addSelectionListener(new SelectionAdapter() {
|
---|
182 | @Override
|
---|
183 | public void widgetSelected(SelectionEvent e) {
|
---|
184 | shlEventbenchConsole.dispose();
|
---|
185 | }
|
---|
186 | });
|
---|
187 | mntmExit.setText("Exit");
|
---|
188 |
|
---|
189 | MenuItem mntmHelp = new MenuItem(menu, SWT.CASCADE);
|
---|
190 | mntmHelp.setText("Help");
|
---|
191 |
|
---|
192 | Menu menu_2 = new Menu(mntmHelp);
|
---|
193 | mntmHelp.setMenu(menu_2);
|
---|
194 |
|
---|
195 | MenuItem mntmAbout = new MenuItem(menu_2, SWT.NONE);
|
---|
196 | mntmAbout.addSelectionListener(new SelectionAdapter() {
|
---|
197 | @Override
|
---|
198 | public void widgetSelected(SelectionEvent e) {
|
---|
199 | AboutDialog aboutDialog = new AboutDialog(shlEventbenchConsole, SWT.NONE);
|
---|
200 | aboutDialog.open();
|
---|
201 | }
|
---|
202 | });
|
---|
203 | mntmAbout.setText("About");
|
---|
204 | }
|
---|
205 |
|
---|
206 | /**
|
---|
207 | * <p>
|
---|
208 | * Creates the central TabFolder of the window.
|
---|
209 | * </p>
|
---|
210 | */
|
---|
211 | private void createTabs() {
|
---|
212 | TabFolder tabFolder = new TabFolder(shlEventbenchConsole, SWT.NONE);
|
---|
213 | tabFolder.addSelectionListener(new SelectionAdapter() {
|
---|
214 | @Override
|
---|
215 | public void widgetSelected(SelectionEvent e) {
|
---|
216 | if (e.item == sequencesTab) {
|
---|
217 | sequencesTabComposite.updateSequenceList();
|
---|
218 | }
|
---|
219 | else if (e.item == modelsTab) {
|
---|
220 | modelsTabComposite.updateModelList();
|
---|
221 | }
|
---|
222 | else if (e.item == guiModelsTab) {
|
---|
223 | guiModelTabComposite.updateModelList();
|
---|
224 | }
|
---|
225 | else if (e.item == usabilityTab) {
|
---|
226 | usabilityTabComposite.updateResultList();
|
---|
227 | }
|
---|
228 | else if (e.item == dataTab) {
|
---|
229 | dataTabComposite.updateDataList();
|
---|
230 | }
|
---|
231 | }
|
---|
232 | });
|
---|
233 | tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
|
---|
234 |
|
---|
235 | consoleTab = new TabItem(tabFolder, SWT.NONE);
|
---|
236 | consoleTab.setText("Console");
|
---|
237 |
|
---|
238 | consoleTabComposite = new ConsoleTabComposite(tabFolder, SWT.NO_BACKGROUND);
|
---|
239 | consoleTab.setControl(consoleTabComposite);
|
---|
240 |
|
---|
241 | sequencesTab = new TabItem(tabFolder, SWT.NONE);
|
---|
242 | sequencesTab.setText("Sequences");
|
---|
243 |
|
---|
244 | sequencesTabComposite = new SequencesTabComposite(tabFolder, SWT.NO_BACKGROUND);
|
---|
245 | sequencesTab.setControl(sequencesTabComposite);
|
---|
246 |
|
---|
247 | modelsTab = new TabItem(tabFolder, SWT.NONE);
|
---|
248 | modelsTab.setText("Models");
|
---|
249 |
|
---|
250 | modelsTabComposite = new ModelsTabComposite(tabFolder, SWT.NO_BACKGROUND);
|
---|
251 | modelsTab.setControl(modelsTabComposite);
|
---|
252 |
|
---|
253 | guiModelsTab = new TabItem(tabFolder, SWT.NONE);
|
---|
254 | guiModelsTab.setText("GUI Models");
|
---|
255 |
|
---|
256 | guiModelTabComposite = new GuiModelTabComposite(tabFolder, SWT.NO_BACKGROUND);
|
---|
257 | guiModelsTab.setControl(guiModelTabComposite);
|
---|
258 |
|
---|
259 | usabilityTab = new TabItem(tabFolder, SWT.NONE);
|
---|
260 | usabilityTab.setText("Usability Evaluation Results");
|
---|
261 |
|
---|
262 | usabilityTabComposite = new UsabilityTabComposite(tabFolder, SWT.NO_BACKGROUND);
|
---|
263 | usabilityTab.setControl(usabilityTabComposite);
|
---|
264 |
|
---|
265 | dataTab = new TabItem(tabFolder, SWT.NONE);
|
---|
266 | dataTab.setText("Data");
|
---|
267 |
|
---|
268 | dataTabComposite = new DataTabComposite(tabFolder, SWT.NO_BACKGROUND);
|
---|
269 | dataTab.setControl(dataTabComposite);
|
---|
270 | }
|
---|
271 | }
|
---|