1 | package de.ugoe.cs.eventbench.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 |
|
---|
30 | private List<String> startupCommands;
|
---|
31 |
|
---|
32 | protected Shell shlEventbenchConsole;
|
---|
33 |
|
---|
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;
|
---|
42 |
|
---|
43 | protected CommandHistoryDialog historyDialog;
|
---|
44 |
|
---|
45 | public MainWindow(List<String> startupCommands) {
|
---|
46 | this.startupCommands = startupCommands;
|
---|
47 | }
|
---|
48 |
|
---|
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 | }
|
---|
72 |
|
---|
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));
|
---|
83 |
|
---|
84 | createMenu();
|
---|
85 | createTabs();
|
---|
86 | }
|
---|
87 |
|
---|
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);
|
---|
94 |
|
---|
95 | MenuItem mntmFile = new MenuItem(menu, SWT.CASCADE);
|
---|
96 | mntmFile.setText("File");
|
---|
97 |
|
---|
98 | Menu menu_1 = new Menu(mntmFile);
|
---|
99 | mntmFile.setMenu(menu_1);
|
---|
100 |
|
---|
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");
|
---|
111 |
|
---|
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,
|
---|
117 | 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");
|
---|
126 |
|
---|
127 | new MenuItem(menu_1, SWT.SEPARATOR);
|
---|
128 |
|
---|
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,
|
---|
134 | 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...");
|
---|
143 |
|
---|
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,
|
---|
149 | SWT.SAVE);
|
---|
150 | String filename = fileDialog.open();
|
---|
151 | if (filename != null) {
|
---|
152 | String command = "save '" + filename + "'";
|
---|
153 | CommandExecuter.getInstance().exec(command);
|
---|
154 | }
|
---|
155 | }
|
---|
156 | });
|
---|
157 | mntmSave.setText("Save...");
|
---|
158 |
|
---|
159 | new MenuItem(menu_1, SWT.SEPARATOR);
|
---|
160 |
|
---|
161 | MenuItem mntmExit = new MenuItem(menu_1, SWT.NONE);
|
---|
162 | mntmExit.addSelectionListener(new SelectionAdapter() {
|
---|
163 | @Override
|
---|
164 | public void widgetSelected(SelectionEvent e) {
|
---|
165 | shlEventbenchConsole.dispose();
|
---|
166 | }
|
---|
167 | });
|
---|
168 | mntmExit.setText("Exit");
|
---|
169 |
|
---|
170 | MenuItem mntmHelp = new MenuItem(menu, SWT.CASCADE);
|
---|
171 | mntmHelp.setText("Help");
|
---|
172 |
|
---|
173 | Menu menu_2 = new Menu(mntmHelp);
|
---|
174 | mntmHelp.setMenu(menu_2);
|
---|
175 |
|
---|
176 | MenuItem mntmAbout = new MenuItem(menu_2, SWT.NONE);
|
---|
177 | mntmAbout.addSelectionListener(new SelectionAdapter() {
|
---|
178 | @Override
|
---|
179 | public void widgetSelected(SelectionEvent e) {
|
---|
180 | AboutDialog aboutDialog = new AboutDialog(shlEventbenchConsole,
|
---|
181 | SWT.NONE);
|
---|
182 | aboutDialog.open();
|
---|
183 | }
|
---|
184 | });
|
---|
185 | mntmAbout.setText("About");
|
---|
186 | }
|
---|
187 |
|
---|
188 | /**
|
---|
189 | * <p>
|
---|
190 | * Creates the central TabFolder of the window.
|
---|
191 | * </p>
|
---|
192 | */
|
---|
193 | private void createTabs() {
|
---|
194 | TabFolder tabFolder = new TabFolder(shlEventbenchConsole, SWT.NONE);
|
---|
195 | tabFolder.addSelectionListener(new SelectionAdapter() {
|
---|
196 | @Override
|
---|
197 | public void widgetSelected(SelectionEvent e) {
|
---|
198 | if (e.item == sequencesTab) {
|
---|
199 | sequencesTabComposite.updateSequenceList();
|
---|
200 | } else if (e.item == modelsTab) {
|
---|
201 | modelsTabComposite.updateModelList();
|
---|
202 | } else if (e.item == dataTab) {
|
---|
203 | dataTabComposite.updateDataList();
|
---|
204 | }
|
---|
205 | }
|
---|
206 | });
|
---|
207 | tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1,
|
---|
208 | 1));
|
---|
209 |
|
---|
210 | consoleTab = new TabItem(tabFolder, SWT.NONE);
|
---|
211 | consoleTab.setText("Console");
|
---|
212 |
|
---|
213 | consoleTabComposite = new ConsoleTabComposite(tabFolder,
|
---|
214 | SWT.NO_BACKGROUND);
|
---|
215 | consoleTab.setControl(consoleTabComposite);
|
---|
216 |
|
---|
217 | sequencesTab = new TabItem(tabFolder, SWT.NONE);
|
---|
218 | sequencesTab.setText("Sequences");
|
---|
219 |
|
---|
220 | sequencesTabComposite = new SequencesTabComposite(tabFolder,
|
---|
221 | SWT.NO_BACKGROUND);
|
---|
222 | sequencesTab.setControl(sequencesTabComposite);
|
---|
223 |
|
---|
224 | modelsTab = new TabItem(tabFolder, SWT.NONE);
|
---|
225 | modelsTab.setText("Models");
|
---|
226 |
|
---|
227 | modelsTabComposite = new ModelsTabComposite(tabFolder,
|
---|
228 | SWT.NO_BACKGROUND);
|
---|
229 | modelsTab.setControl(modelsTabComposite);
|
---|
230 |
|
---|
231 | dataTab = new TabItem(tabFolder, SWT.NONE);
|
---|
232 | dataTab.setText("Data");
|
---|
233 |
|
---|
234 | dataTabComposite = new DataTabComposite(tabFolder, SWT.NO_BACKGROUND);
|
---|
235 | dataTab.setControl(dataTabComposite);
|
---|
236 | }
|
---|
237 | }
|
---|