1 | package de.ugoe.cs.eventbench.swt;
|
---|
2 |
|
---|
3 | import java.util.Collection;
|
---|
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.MenuItem;
|
---|
10 | import org.eclipse.swt.widgets.Text;
|
---|
11 | import org.eclipse.swt.widgets.Label;
|
---|
12 | import org.eclipse.swt.widgets.TabFolder;
|
---|
13 | import org.eclipse.swt.widgets.TabItem;
|
---|
14 | import org.eclipse.swt.widgets.Composite;
|
---|
15 | import org.eclipse.swt.widgets.Button;
|
---|
16 | import org.eclipse.swt.widgets.List;
|
---|
17 | import org.eclipse.swt.layout.GridLayout;
|
---|
18 | import org.eclipse.swt.layout.GridData;
|
---|
19 | import org.eclipse.swt.events.SelectionAdapter;
|
---|
20 | import org.eclipse.swt.events.SelectionEvent;
|
---|
21 |
|
---|
22 | import de.ugoe.cs.eventbench.data.Event;
|
---|
23 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
24 | import de.ugoe.cs.util.console.CommandExecuter;
|
---|
25 | import de.ugoe.cs.util.console.TextConsole;
|
---|
26 | import org.eclipse.swt.events.KeyAdapter;
|
---|
27 | import org.eclipse.swt.events.KeyEvent;
|
---|
28 |
|
---|
29 | public class MainWindow {
|
---|
30 |
|
---|
31 | protected Shell shell;
|
---|
32 | private Text textCommand;
|
---|
33 | private Text textConsoleOutput;
|
---|
34 | private List list;
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Launch the application.
|
---|
38 | * @param args
|
---|
39 | */
|
---|
40 | public static void main(String[] args) {
|
---|
41 | // TODO this main method needs to be removed/remodeled when merging with other project
|
---|
42 | try {
|
---|
43 | CommandExecuter.getInstance().addCommandPackage(
|
---|
44 | "de.ugoe.cs.eventbench.commands");
|
---|
45 | CommandExecuter.getInstance().addCommandPackage(
|
---|
46 | "de.ugoe.cs.eventbench.windows.commands");
|
---|
47 | CommandExecuter.getInstance().addCommandPackage(
|
---|
48 | "de.ugoe.cs.eventbench.web.commands");
|
---|
49 | new TextConsole();
|
---|
50 |
|
---|
51 | MainWindow window = new MainWindow();
|
---|
52 | window.open();
|
---|
53 | } catch (Exception e) {
|
---|
54 | e.printStackTrace();
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * Open the window.
|
---|
60 | */
|
---|
61 | public void open() {
|
---|
62 | Display display = Display.getDefault();
|
---|
63 | createContents();
|
---|
64 | new SWTConsole(textConsoleOutput);
|
---|
65 | shell.open();
|
---|
66 | shell.layout();
|
---|
67 | while (!shell.isDisposed()) {
|
---|
68 | if (!display.readAndDispatch()) {
|
---|
69 | display.sleep();
|
---|
70 | }
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * Create contents of the window.
|
---|
76 | */
|
---|
77 | protected void createContents() {
|
---|
78 | shell = new Shell();
|
---|
79 | shell.setSize(500, 300);
|
---|
80 | shell.setText("SWT Application");
|
---|
81 | shell.setLayout(new GridLayout(1, false));
|
---|
82 |
|
---|
83 | Menu menu = new Menu(shell, SWT.BAR);
|
---|
84 | shell.setMenuBar(menu);
|
---|
85 |
|
---|
86 | MenuItem mntmFile = new MenuItem(menu, SWT.CASCADE);
|
---|
87 | mntmFile.setText("File");
|
---|
88 |
|
---|
89 | Menu menu_1 = new Menu(mntmFile);
|
---|
90 | mntmFile.setMenu(menu_1);
|
---|
91 |
|
---|
92 | MenuItem mntmShowHistory = new MenuItem(menu_1, SWT.NONE);
|
---|
93 | mntmShowHistory.setText("Show History");
|
---|
94 |
|
---|
95 | MenuItem mntmExecBatchFile = new MenuItem(menu_1, SWT.NONE);
|
---|
96 | mntmExecBatchFile.setText("Exec. Batch File");
|
---|
97 |
|
---|
98 | new MenuItem(menu_1, SWT.SEPARATOR);
|
---|
99 |
|
---|
100 | MenuItem mntmLoad = new MenuItem(menu_1, SWT.NONE);
|
---|
101 | mntmLoad.setText("Load...");
|
---|
102 |
|
---|
103 | MenuItem mntmSave = new MenuItem(menu_1, SWT.NONE);
|
---|
104 | mntmSave.setText("Save...");
|
---|
105 |
|
---|
106 | new MenuItem(menu_1, SWT.SEPARATOR);
|
---|
107 |
|
---|
108 | MenuItem mntmExit = new MenuItem(menu_1, SWT.NONE);
|
---|
109 | mntmExit.setText("Exit");
|
---|
110 |
|
---|
111 | MenuItem mntmHelp = new MenuItem(menu, SWT.CASCADE);
|
---|
112 | mntmHelp.setText("Help");
|
---|
113 |
|
---|
114 | Menu menu_2 = new Menu(mntmHelp);
|
---|
115 | mntmHelp.setMenu(menu_2);
|
---|
116 |
|
---|
117 | MenuItem mntmAbout = new MenuItem(menu_2, SWT.NONE);
|
---|
118 | mntmAbout.setText("About");
|
---|
119 |
|
---|
120 | TabFolder tabFolder = new TabFolder(shell, SWT.NONE);
|
---|
121 | tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
|
---|
122 |
|
---|
123 | TabItem tbtmConsoleMode = new TabItem(tabFolder, SWT.NONE);
|
---|
124 | tbtmConsoleMode.setText("Console");
|
---|
125 |
|
---|
126 | Composite composite = new Composite(tabFolder, SWT.NO_BACKGROUND);
|
---|
127 | tbtmConsoleMode.setControl(composite);
|
---|
128 | composite.setLayout(new GridLayout(3, false));
|
---|
129 |
|
---|
130 | Label lblCommand = new Label(composite, SWT.NONE);
|
---|
131 | lblCommand.setText("Command:");
|
---|
132 |
|
---|
133 | textCommand = new Text(composite, SWT.BORDER);
|
---|
134 | textCommand.addKeyListener(new KeyAdapter() {
|
---|
135 | @Override
|
---|
136 | public void keyReleased(KeyEvent e) {
|
---|
137 | if( e.keyCode==SWT.CR ) {
|
---|
138 | String command = textCommand.getText().trim();
|
---|
139 | CommandExecuter.getInstance().exec(command);
|
---|
140 | }
|
---|
141 | }
|
---|
142 | });
|
---|
143 | GridData gd_textCommand = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
|
---|
144 | gd_textCommand.widthHint = 304;
|
---|
145 | textCommand.setLayoutData(gd_textCommand);
|
---|
146 |
|
---|
147 | Button btnEnter = new Button(composite, SWT.NONE);
|
---|
148 | btnEnter.addSelectionListener(new SelectionAdapter() {
|
---|
149 | @Override
|
---|
150 | public void widgetSelected(SelectionEvent e) {
|
---|
151 | // Event handler for executing commands
|
---|
152 | String command = textCommand.getText().trim();
|
---|
153 | CommandExecuter.getInstance().exec(command);
|
---|
154 | }
|
---|
155 | });
|
---|
156 | btnEnter.setText("Enter");
|
---|
157 |
|
---|
158 | textConsoleOutput = new Text(composite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL);
|
---|
159 | GridData gd_textConsoleOutput = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
|
---|
160 | gd_textConsoleOutput.heightHint = 102;
|
---|
161 | gd_textConsoleOutput.widthHint = 456;
|
---|
162 | textConsoleOutput.setLayoutData(gd_textConsoleOutput);
|
---|
163 |
|
---|
164 | TabItem tbtmSequences = new TabItem(tabFolder, SWT.NONE);
|
---|
165 | tbtmSequences.setText("Sequences");
|
---|
166 |
|
---|
167 | Composite composite_2 = new Composite(tabFolder, SWT.NO_BACKGROUND);
|
---|
168 | tbtmSequences.setControl(composite_2);
|
---|
169 | composite_2.setLayout(new GridLayout(5, false));
|
---|
170 |
|
---|
171 | list = new List(composite_2, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
|
---|
172 | list.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1));
|
---|
173 | list.setItems(new String[] {});
|
---|
174 | for( String sequencesName : GlobalDataContainer.getInstance().getAllSequencesNames() ) {
|
---|
175 | list.add(sequencesName);
|
---|
176 | }
|
---|
177 |
|
---|
178 | Button btnEdit = new Button(composite_2, SWT.NONE);
|
---|
179 | btnEdit.addSelectionListener(new SelectionAdapter() {
|
---|
180 | @Override
|
---|
181 | public void widgetSelected(SelectionEvent e) {
|
---|
182 | // TODO edit sequences event handler
|
---|
183 | }
|
---|
184 | });
|
---|
185 | btnEdit.setText("Edit");
|
---|
186 |
|
---|
187 | Button btnDelete = new Button(composite_2, SWT.NONE);
|
---|
188 | btnDelete.addSelectionListener(new SelectionAdapter() {
|
---|
189 | @Override
|
---|
190 | public void widgetSelected(SelectionEvent e) {
|
---|
191 | String[] selectedSequences = list.getSelection();
|
---|
192 | for( String selected : selectedSequences) {
|
---|
193 | GlobalDataContainer.getInstance().removeData(selected);
|
---|
194 | }
|
---|
195 | }
|
---|
196 | });
|
---|
197 | btnDelete.setText("Delete");
|
---|
198 |
|
---|
199 | Button btnReplay = new Button(composite_2, SWT.NONE);
|
---|
200 | btnReplay.setText("Replay");
|
---|
201 |
|
---|
202 | Button btnTrainModel = new Button(composite_2, SWT.NONE);
|
---|
203 | btnTrainModel.setText("Train Model");
|
---|
204 |
|
---|
205 | Button btnParse = new Button(composite_2, SWT.NONE);
|
---|
206 | btnParse.setText("Parse");
|
---|
207 |
|
---|
208 | TabItem tbtmModels = new TabItem(tabFolder, SWT.NONE);
|
---|
209 | tbtmModels.setText("Models");
|
---|
210 |
|
---|
211 | Composite composite_1 = new Composite(tabFolder, SWT.NO_BACKGROUND);
|
---|
212 | tbtmModels.setControl(composite_1);
|
---|
213 | composite_1.setLayout(new GridLayout(5, false));
|
---|
214 |
|
---|
215 | List list_1 = new List(composite_1, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
|
---|
216 | list_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1));
|
---|
217 |
|
---|
218 | Button btnShow = new Button(composite_1, SWT.NONE);
|
---|
219 | btnShow.setText("Visualize");
|
---|
220 |
|
---|
221 | Button btnDelete_1 = new Button(composite_1, SWT.NONE);
|
---|
222 | btnDelete_1.setText("Delete");
|
---|
223 |
|
---|
224 | Button btnGenSequences = new Button(composite_1, SWT.NONE);
|
---|
225 | btnGenSequences.setText("Gen. Sequences");
|
---|
226 |
|
---|
227 | Button btnProperties = new Button(composite_1, SWT.NONE);
|
---|
228 | btnProperties.setText("Properties");
|
---|
229 |
|
---|
230 | Button btnCreateDot = new Button(composite_1, SWT.NONE);
|
---|
231 | btnCreateDot.setText("Create DOT");
|
---|
232 |
|
---|
233 | TabItem tbtmData = new TabItem(tabFolder, SWT.NONE);
|
---|
234 | tbtmData.setText("Data");
|
---|
235 |
|
---|
236 | Composite composite_3 = new Composite(tabFolder, SWT.NO_BACKGROUND);
|
---|
237 | tbtmData.setControl(composite_3);
|
---|
238 | composite_3.setLayout(new GridLayout(3, false));
|
---|
239 |
|
---|
240 | List list_2 = new List(composite_3, SWT.BORDER | SWT.V_SCROLL);
|
---|
241 | list_2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
|
---|
242 |
|
---|
243 | Button btnLoad = new Button(composite_3, SWT.NONE);
|
---|
244 | btnLoad.setText("Load");
|
---|
245 |
|
---|
246 | Button btnSave = new Button(composite_3, SWT.NONE);
|
---|
247 | btnSave.setText("Save");
|
---|
248 |
|
---|
249 | Button btnDelete_2 = new Button(composite_3, SWT.NONE);
|
---|
250 | btnDelete_2.setText("Delete");
|
---|
251 |
|
---|
252 | }
|
---|
253 | public Text getTextConsoleOutput() {
|
---|
254 | return textConsoleOutput;
|
---|
255 | }
|
---|
256 | }
|
---|