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