01: /*******************************************************************************
02: * Copyright (c) 2003, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.examples.rcp.browser;
11:
12: import org.eclipse.equinox.app.IApplication;
13: import org.eclipse.equinox.app.IApplicationContext;
14: import org.eclipse.swt.widgets.Display;
15: import org.eclipse.ui.IWorkbench;
16: import org.eclipse.ui.PlatformUI;
17:
18: /**
19: * The application class for the RCP Browser Example.
20: * Creates and runs the Workbench, passing a <code>BrowserAdvisor</code>
21: * as the workbench advisor.
22: *
23: * @issue Couldn't run without initial perspective -- it failed with NPE
24: * on WorkbenchWindow.openPage (called from Workbench.openFirstTimeWindow). Advisor is currently required to override
25: * getInitialWindowPerspectiveId.
26: *
27: * @issue If shortcut bar is hidden, and last view in perspective is closed, there's no way to get it open again.
28: *
29: * @since 3.0
30: */
31: public class BrowserApp implements IApplication {
32:
33: /**
34: * Constructs a new <code>BrowserApp</code>.
35: */
36: public BrowserApp() {
37: // do nothing
38: }
39:
40: /* (non-Javadoc)
41: * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
42: */
43: public Object start(IApplicationContext context) throws Exception {
44: Display display = PlatformUI.createDisplay();
45: try {
46: int code = PlatformUI.createAndRunWorkbench(display,
47: new BrowserAdvisor());
48: // exit the application with an appropriate return code
49: return code == PlatformUI.RETURN_RESTART ? EXIT_RESTART
50: : EXIT_OK;
51: } finally {
52: if (display != null)
53: display.dispose();
54: }
55: }
56:
57: /* (non-Javadoc)
58: * @see org.eclipse.equinox.app.IApplication#stop()
59: */
60: public void stop() {
61: final IWorkbench workbench = PlatformUI.getWorkbench();
62: if (workbench == null)
63: return;
64: final Display display = workbench.getDisplay();
65: display.syncExec(new Runnable() {
66: public void run() {
67: if (!display.isDisposed())
68: workbench.close();
69: }
70: });
71: }
72: }
|