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