1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.uruma.rcp;
17
18 import org.eclipse.equinox.app.IApplication;
19 import org.eclipse.equinox.app.IApplicationContext;
20 import org.eclipse.swt.widgets.Display;
21 import org.eclipse.swt.widgets.Shell;
22 import org.eclipse.ui.IWorkbench;
23 import org.eclipse.ui.PlatformUI;
24 import org.seasar.uruma.core.UrumaConstants;
25 import org.seasar.uruma.core.UrumaMessageCodes;
26 import org.seasar.uruma.log.UrumaLogger;
27 import org.seasar.uruma.rcp.core.UrumaBundleState;
28 import org.seasar.uruma.rcp.core.UrumaBundleState.BundleState;
29 import org.seasar.uruma.rcp.ui.UrumaWorkbenchAdvisor;
30 import org.seasar.uruma.rcp.util.UrumaServiceUtil;
31 import org.seasar.uruma.ui.dialogs.UrumaErrorDialog;
32 import org.seasar.uruma.util.MessageUtil;
33
34
35
36
37
38
39 public class UrumaApplication implements IApplication, UrumaMessageCodes,
40 UrumaConstants {
41 private static final UrumaLogger logger = UrumaLogger
42 .getLogger(UrumaApplication.class);
43
44
45
46
47 public Object start(final IApplicationContext context) throws Exception {
48 if (UrumaBundleState.getInstance().getUrumaBundleState() == BundleState.NOT_AVAILABLE) {
49 return IApplication.EXIT_OK;
50 }
51
52 logger.log(URUMA_APPLICATION_STARTING);
53
54 Display display = null;
55 try {
56 UrumaServiceUtil.getService().switchToAppClassLoader();
57
58 display = PlatformUI.createDisplay();
59 int returnCode = PlatformUI.createAndRunWorkbench(display,
60 new UrumaWorkbenchAdvisor());
61 if (returnCode == PlatformUI.RETURN_RESTART) {
62 return IApplication.EXIT_RESTART;
63 } else {
64 return IApplication.EXIT_OK;
65 }
66 } catch (Throwable ex) {
67 if (display == null) {
68 display = new Display();
69 }
70 Shell shell = new Shell(display);
71 String msg = MessageUtil.getMessageWithBundleName(
72 URUMA_MESSAGE_BASE, "RCP_EXCEPTION_OCCURED");
73 UrumaErrorDialog dialog = new UrumaErrorDialog(shell, "Uruma", msg,
74 ex);
75 dialog.open();
76 shell.dispose();
77 } finally {
78 if ((display != null) && !display.isDisposed()) {
79 display.dispose();
80 }
81 }
82 return IApplication.EXIT_OK;
83 }
84
85
86
87
88 public void stop() {
89 logger.log(URUMA_APPLICATION_STOPPING);
90
91 final IWorkbench workbench = PlatformUI.getWorkbench();
92 if (workbench == null)
93 return;
94 final Display display = workbench.getDisplay();
95 display.syncExec(new Runnable() {
96 public void run() {
97 if (!display.isDisposed()) {
98 workbench.close();
99 }
100 }
101 });
102 }
103 }