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