[927] | 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 |
|
---|
[922] | 15 | package de.ugoe.cs.autoquest.ui.swt;
|
---|
[526] | 16 |
|
---|
| 17 | import java.util.List;
|
---|
[674] | 18 | import java.util.logging.Level;
|
---|
[526] | 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 |
|
---|
[570] | 45 | private List<String> startupCommands;
|
---|
[674] | 46 |
|
---|
| 47 | private final Level traceLevel;
|
---|
[526] | 48 |
|
---|
[570] | 49 | protected Shell shlEventbenchConsole;
|
---|
[526] | 50 |
|
---|
[570] | 51 | protected TabItem consoleTab;
|
---|
| 52 | protected TabItem sequencesTab;
|
---|
| 53 | protected TabItem modelsTab;
|
---|
[658] | 54 | protected TabItem guiModelsTab;
|
---|
[1495] | 55 | protected TabItem usabilityTab;
|
---|
[570] | 56 | protected TabItem dataTab;
|
---|
| 57 | protected ConsoleTabComposite consoleTabComposite;
|
---|
| 58 | protected SequencesTabComposite sequencesTabComposite;
|
---|
| 59 | protected ModelsTabComposite modelsTabComposite;
|
---|
[658] | 60 | protected GuiModelTabComposite guiModelTabComposite;
|
---|
[1495] | 61 | protected UsabilityTabComposite usabilityTabComposite;
|
---|
[570] | 62 | protected DataTabComposite dataTabComposite;
|
---|
[526] | 63 |
|
---|
[570] | 64 | protected CommandHistoryDialog historyDialog;
|
---|
[526] | 65 |
|
---|
[674] | 66 | public MainWindow(List<String> startupCommands, Level traceLevel) {
|
---|
[570] | 67 | this.startupCommands = startupCommands;
|
---|
[674] | 68 | this.traceLevel = traceLevel;
|
---|
[570] | 69 | }
|
---|
[526] | 70 |
|
---|
[570] | 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();
|
---|
[674] | 81 | new SWTConsole(consoleTabComposite.textConsoleOutput, traceLevel);
|
---|
[570] | 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 | }
|
---|
[526] | 94 |
|
---|
[570] | 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);
|
---|
[1237] | 103 | shlEventbenchConsole.setText("AutoQUEST Console");
|
---|
[570] | 104 | shlEventbenchConsole.setLayout(new GridLayout(1, false));
|
---|
[526] | 105 |
|
---|
[570] | 106 | createMenu();
|
---|
| 107 | createTabs();
|
---|
| 108 | }
|
---|
[526] | 109 |
|
---|
[570] | 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);
|
---|
[526] | 116 |
|
---|
[570] | 117 | MenuItem mntmFile = new MenuItem(menu, SWT.CASCADE);
|
---|
| 118 | mntmFile.setText("File");
|
---|
[526] | 119 |
|
---|
[570] | 120 | Menu menu_1 = new Menu(mntmFile);
|
---|
| 121 | mntmFile.setMenu(menu_1);
|
---|
[526] | 122 |
|
---|
[570] | 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");
|
---|
[526] | 133 |
|
---|
[570] | 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");
|
---|
[526] | 147 |
|
---|
[570] | 148 | new MenuItem(menu_1, SWT.SEPARATOR);
|
---|
[526] | 149 |
|
---|
[570] | 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...");
|
---|
[526] | 163 |
|
---|
[570] | 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...");
|
---|
[526] | 177 |
|
---|
[570] | 178 | new MenuItem(menu_1, SWT.SEPARATOR);
|
---|
[526] | 179 |
|
---|
[570] | 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");
|
---|
[526] | 188 |
|
---|
[570] | 189 | MenuItem mntmHelp = new MenuItem(menu, SWT.CASCADE);
|
---|
| 190 | mntmHelp.setText("Help");
|
---|
[526] | 191 |
|
---|
[570] | 192 | Menu menu_2 = new Menu(mntmHelp);
|
---|
| 193 | mntmHelp.setMenu(menu_2);
|
---|
[526] | 194 |
|
---|
[570] | 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 | }
|
---|
[526] | 205 |
|
---|
[570] | 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 | }
|
---|
[658] | 222 | else if (e.item == guiModelsTab) {
|
---|
| 223 | guiModelTabComposite.updateModelList();
|
---|
| 224 | }
|
---|
[1495] | 225 | else if (e.item == usabilityTab) {
|
---|
| 226 | usabilityTabComposite.updateResultList();
|
---|
| 227 | }
|
---|
[570] | 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));
|
---|
[526] | 234 |
|
---|
[570] | 235 | consoleTab = new TabItem(tabFolder, SWT.NONE);
|
---|
| 236 | consoleTab.setText("Console");
|
---|
[526] | 237 |
|
---|
[570] | 238 | consoleTabComposite = new ConsoleTabComposite(tabFolder, SWT.NO_BACKGROUND);
|
---|
| 239 | consoleTab.setControl(consoleTabComposite);
|
---|
[526] | 240 |
|
---|
[570] | 241 | sequencesTab = new TabItem(tabFolder, SWT.NONE);
|
---|
| 242 | sequencesTab.setText("Sequences");
|
---|
[526] | 243 |
|
---|
[570] | 244 | sequencesTabComposite = new SequencesTabComposite(tabFolder, SWT.NO_BACKGROUND);
|
---|
| 245 | sequencesTab.setControl(sequencesTabComposite);
|
---|
[526] | 246 |
|
---|
[570] | 247 | modelsTab = new TabItem(tabFolder, SWT.NONE);
|
---|
| 248 | modelsTab.setText("Models");
|
---|
[526] | 249 |
|
---|
[570] | 250 | modelsTabComposite = new ModelsTabComposite(tabFolder, SWT.NO_BACKGROUND);
|
---|
| 251 | modelsTab.setControl(modelsTabComposite);
|
---|
[658] | 252 |
|
---|
| 253 | guiModelsTab = new TabItem(tabFolder, SWT.NONE);
|
---|
| 254 | guiModelsTab.setText("GUI Models");
|
---|
[570] | 255 |
|
---|
[658] | 256 | guiModelTabComposite = new GuiModelTabComposite(tabFolder, SWT.NO_BACKGROUND);
|
---|
| 257 | guiModelsTab.setControl(guiModelTabComposite);
|
---|
| 258 |
|
---|
[1495] | 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 |
|
---|
[570] | 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 | }
|
---|
[526] | 271 | }
|
---|