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 |
|
---|
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 guiModelsTab;
|
---|
38 | protected TabItem dataTab;
|
---|
39 | protected ConsoleTabComposite consoleTabComposite;
|
---|
40 | protected SequencesTabComposite sequencesTabComposite;
|
---|
41 | protected ModelsTabComposite modelsTabComposite;
|
---|
42 | protected GuiModelTabComposite guiModelTabComposite;
|
---|
43 | protected DataTabComposite dataTabComposite;
|
---|
44 |
|
---|
45 | protected CommandHistoryDialog historyDialog;
|
---|
46 |
|
---|
47 | public MainWindow(List<String> startupCommands) {
|
---|
48 | this.startupCommands = startupCommands;
|
---|
49 | }
|
---|
50 |
|
---|
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 | }
|
---|
74 |
|
---|
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));
|
---|
85 |
|
---|
86 | createMenu();
|
---|
87 | createTabs();
|
---|
88 | }
|
---|
89 |
|
---|
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);
|
---|
96 |
|
---|
97 | MenuItem mntmFile = new MenuItem(menu, SWT.CASCADE);
|
---|
98 | mntmFile.setText("File");
|
---|
99 |
|
---|
100 | Menu menu_1 = new Menu(mntmFile);
|
---|
101 | mntmFile.setMenu(menu_1);
|
---|
102 |
|
---|
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");
|
---|
113 |
|
---|
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");
|
---|
127 |
|
---|
128 | new MenuItem(menu_1, SWT.SEPARATOR);
|
---|
129 |
|
---|
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...");
|
---|
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, 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...");
|
---|
157 |
|
---|
158 | new MenuItem(menu_1, SWT.SEPARATOR);
|
---|
159 |
|
---|
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");
|
---|
168 |
|
---|
169 | MenuItem mntmHelp = new MenuItem(menu, SWT.CASCADE);
|
---|
170 | mntmHelp.setText("Help");
|
---|
171 |
|
---|
172 | Menu menu_2 = new Menu(mntmHelp);
|
---|
173 | mntmHelp.setMenu(menu_2);
|
---|
174 |
|
---|
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 | }
|
---|
185 |
|
---|
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 | }
|
---|
202 | else if (e.item == guiModelsTab) {
|
---|
203 | guiModelTabComposite.updateModelList();
|
---|
204 | }
|
---|
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));
|
---|
211 |
|
---|
212 | consoleTab = new TabItem(tabFolder, SWT.NONE);
|
---|
213 | consoleTab.setText("Console");
|
---|
214 |
|
---|
215 | consoleTabComposite = new ConsoleTabComposite(tabFolder, SWT.NO_BACKGROUND);
|
---|
216 | consoleTab.setControl(consoleTabComposite);
|
---|
217 |
|
---|
218 | sequencesTab = new TabItem(tabFolder, SWT.NONE);
|
---|
219 | sequencesTab.setText("Sequences");
|
---|
220 |
|
---|
221 | sequencesTabComposite = new SequencesTabComposite(tabFolder, 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, SWT.NO_BACKGROUND);
|
---|
228 | modelsTab.setControl(modelsTabComposite);
|
---|
229 |
|
---|
230 | guiModelsTab = new TabItem(tabFolder, SWT.NONE);
|
---|
231 | guiModelsTab.setText("GUI Models");
|
---|
232 |
|
---|
233 | guiModelTabComposite = new GuiModelTabComposite(tabFolder, SWT.NO_BACKGROUND);
|
---|
234 | guiModelsTab.setControl(guiModelTabComposite);
|
---|
235 |
|
---|
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 | }
|
---|
242 | }
|
---|