source: trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt/MainWindow.java @ 927

Last change on this file since 927 was 927, checked in by sherbold, 12 years ago
  • added copyright under the Apache License, Version 2.0
  • Property svn:mime-type set to text/plain
File size: 9.0 KB
Line 
1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.autoquest.ui.swt;
16
17import java.util.List;
18import java.util.logging.Level;
19
20import org.eclipse.swt.widgets.Display;
21import org.eclipse.swt.widgets.Shell;
22import org.eclipse.swt.widgets.Menu;
23import org.eclipse.swt.SWT;
24import org.eclipse.swt.widgets.FileDialog;
25import org.eclipse.swt.widgets.MenuItem;
26import org.eclipse.swt.widgets.TabFolder;
27import org.eclipse.swt.widgets.TabItem;
28import org.eclipse.swt.layout.GridLayout;
29import org.eclipse.swt.layout.GridData;
30import org.eclipse.swt.events.SelectionAdapter;
31import org.eclipse.swt.events.SelectionEvent;
32
33import de.ugoe.cs.util.console.CommandExecuter;
34
35/**
36 * <p>
37 * Main window of the SWT GUI.
38 * </p>
39 *
40 * @author Steffen Herbold
41 * @version 1.0
42 */
43public class MainWindow {
44
45    private List<String> startupCommands;
46   
47    private final Level traceLevel;
48
49    protected Shell shlEventbenchConsole;
50
51    protected TabItem consoleTab;
52    protected TabItem sequencesTab;
53    protected TabItem modelsTab;
54    protected TabItem guiModelsTab;
55    protected TabItem dataTab;
56    protected ConsoleTabComposite consoleTabComposite;
57    protected SequencesTabComposite sequencesTabComposite;
58    protected ModelsTabComposite modelsTabComposite;
59    protected GuiModelTabComposite guiModelTabComposite;
60    protected DataTabComposite dataTabComposite;
61
62    protected CommandHistoryDialog historyDialog;
63
64    public MainWindow(List<String> startupCommands, Level traceLevel) {
65        this.startupCommands = startupCommands;
66        this.traceLevel = traceLevel;
67    }
68
69    /**
70     * <p>
71     * Open the window.
72     * </p>
73     *
74     * @wbp.parser.entryPoint
75     */
76    public void open() {
77        Display display = Display.getDefault();
78        createContents();
79        new SWTConsole(consoleTabComposite.textConsoleOutput, traceLevel);
80        historyDialog = new CommandHistoryDialog(shlEventbenchConsole, SWT.NONE);
81        shlEventbenchConsole.open();
82        shlEventbenchConsole.layout();
83        for (String command : startupCommands) {
84            CommandExecuter.getInstance().exec(command);
85        }
86        while (!shlEventbenchConsole.isDisposed()) {
87            if (!display.readAndDispatch()) {
88                display.sleep();
89            }
90        }
91    }
92
93    /**
94     * <p>
95     * Create contents of the window.
96     * </p>
97     */
98    protected void createContents() {
99        shlEventbenchConsole = new Shell();
100        shlEventbenchConsole.setSize(800, 600);
101        shlEventbenchConsole.setText("EventBench Console");
102        shlEventbenchConsole.setLayout(new GridLayout(1, false));
103
104        createMenu();
105        createTabs();
106    }
107
108    /**
109     * </p> Creates the menu of the window. </p>
110     */
111    private void createMenu() {
112        Menu menu = new Menu(shlEventbenchConsole, SWT.BAR);
113        shlEventbenchConsole.setMenuBar(menu);
114
115        MenuItem mntmFile = new MenuItem(menu, SWT.CASCADE);
116        mntmFile.setText("File");
117
118        Menu menu_1 = new Menu(mntmFile);
119        mntmFile.setMenu(menu_1);
120
121        MenuItem mntmShowHistory = new MenuItem(menu_1, SWT.NONE);
122        mntmShowHistory.addSelectionListener(new SelectionAdapter() {
123            @Override
124            public void widgetSelected(SelectionEvent e) {
125                if (!historyDialog.isOpen()) {
126                    historyDialog.open();
127                }
128            }
129        });
130        mntmShowHistory.setText("Show History");
131
132        MenuItem mntmExecBatchFile = new MenuItem(menu_1, SWT.NONE);
133        mntmExecBatchFile.addSelectionListener(new SelectionAdapter() {
134            @Override
135            public void widgetSelected(SelectionEvent e) {
136                FileDialog fileDialog = new FileDialog(shlEventbenchConsole, SWT.OPEN);
137                String filename = fileDialog.open();
138                if (filename != null) {
139                    String command = "exec '" + filename + "'";
140                    CommandExecuter.getInstance().exec(command);
141                }
142            }
143        });
144        mntmExecBatchFile.setText("Exec. Batch File");
145
146        new MenuItem(menu_1, SWT.SEPARATOR);
147
148        MenuItem mntmLoad = new MenuItem(menu_1, SWT.NONE);
149        mntmLoad.addSelectionListener(new SelectionAdapter() {
150            @Override
151            public void widgetSelected(SelectionEvent e) {
152                FileDialog fileDialog = new FileDialog(shlEventbenchConsole, SWT.OPEN);
153                String filename = fileDialog.open();
154                if (filename != null) {
155                    String command = "load '" + filename + "'";
156                    CommandExecuter.getInstance().exec(command);
157                }
158            }
159        });
160        mntmLoad.setText("Load...");
161
162        MenuItem mntmSave = new MenuItem(menu_1, SWT.NONE);
163        mntmSave.addSelectionListener(new SelectionAdapter() {
164            @Override
165            public void widgetSelected(SelectionEvent e) {
166                FileDialog fileDialog = new FileDialog(shlEventbenchConsole, SWT.SAVE);
167                String filename = fileDialog.open();
168                if (filename != null) {
169                    String command = "save '" + filename + "'";
170                    CommandExecuter.getInstance().exec(command);
171                }
172            }
173        });
174        mntmSave.setText("Save...");
175
176        new MenuItem(menu_1, SWT.SEPARATOR);
177
178        MenuItem mntmExit = new MenuItem(menu_1, SWT.NONE);
179        mntmExit.addSelectionListener(new SelectionAdapter() {
180            @Override
181            public void widgetSelected(SelectionEvent e) {
182                shlEventbenchConsole.dispose();
183            }
184        });
185        mntmExit.setText("Exit");
186
187        MenuItem mntmHelp = new MenuItem(menu, SWT.CASCADE);
188        mntmHelp.setText("Help");
189
190        Menu menu_2 = new Menu(mntmHelp);
191        mntmHelp.setMenu(menu_2);
192
193        MenuItem mntmAbout = new MenuItem(menu_2, SWT.NONE);
194        mntmAbout.addSelectionListener(new SelectionAdapter() {
195            @Override
196            public void widgetSelected(SelectionEvent e) {
197                AboutDialog aboutDialog = new AboutDialog(shlEventbenchConsole, SWT.NONE);
198                aboutDialog.open();
199            }
200        });
201        mntmAbout.setText("About");
202    }
203
204    /**
205     * <p>
206     * Creates the central TabFolder of the window.
207     * </p>
208     */
209    private void createTabs() {
210        TabFolder tabFolder = new TabFolder(shlEventbenchConsole, SWT.NONE);
211        tabFolder.addSelectionListener(new SelectionAdapter() {
212            @Override
213            public void widgetSelected(SelectionEvent e) {
214                if (e.item == sequencesTab) {
215                    sequencesTabComposite.updateSequenceList();
216                }
217                else if (e.item == modelsTab) {
218                    modelsTabComposite.updateModelList();
219                }
220                else if (e.item == guiModelsTab) {
221                    guiModelTabComposite.updateModelList();
222                }
223                else if (e.item == dataTab) {
224                    dataTabComposite.updateDataList();
225                }
226            }
227        });
228        tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
229
230        consoleTab = new TabItem(tabFolder, SWT.NONE);
231        consoleTab.setText("Console");
232
233        consoleTabComposite = new ConsoleTabComposite(tabFolder, SWT.NO_BACKGROUND);
234        consoleTab.setControl(consoleTabComposite);
235
236        sequencesTab = new TabItem(tabFolder, SWT.NONE);
237        sequencesTab.setText("Sequences");
238
239        sequencesTabComposite = new SequencesTabComposite(tabFolder, SWT.NO_BACKGROUND);
240        sequencesTab.setControl(sequencesTabComposite);
241
242        modelsTab = new TabItem(tabFolder, SWT.NONE);
243        modelsTab.setText("Models");
244
245        modelsTabComposite = new ModelsTabComposite(tabFolder, SWT.NO_BACKGROUND);
246        modelsTab.setControl(modelsTabComposite);
247       
248        guiModelsTab = new TabItem(tabFolder, SWT.NONE);
249        guiModelsTab.setText("GUI Models");
250
251        guiModelTabComposite = new GuiModelTabComposite(tabFolder, SWT.NO_BACKGROUND);
252        guiModelsTab.setControl(guiModelTabComposite);
253
254        dataTab = new TabItem(tabFolder, SWT.NONE);
255        dataTab.setText("Data");
256
257        dataTabComposite = new DataTabComposite(tabFolder, SWT.NO_BACKGROUND);
258        dataTab.setControl(dataTabComposite);
259    }
260}
Note: See TracBrowser for help on using the repository browser.