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