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