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