| 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 | 0 | public class UrumaApplication implements IApplication, UrumaMessageCodes, |
| 40 | |
UrumaConstants { |
| 41 | 0 | private static final UrumaLogger logger = UrumaLogger |
| 42 | |
.getLogger(UrumaApplication.class); |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
public Object start(final IApplicationContext context) throws Exception { |
| 48 | 0 | if (UrumaBundleState.getInstance().getUrumaBundleState() == BundleState.NOT_AVAILABLE) { |
| 49 | 0 | return IApplication.EXIT_OK; |
| 50 | |
} |
| 51 | |
|
| 52 | 0 | logger.log(URUMA_APPLICATION_STARTING); |
| 53 | |
|
| 54 | 0 | Display display = null; |
| 55 | |
try { |
| 56 | 0 | UrumaServiceUtil.getService().switchToAppClassLoader(); |
| 57 | |
|
| 58 | 0 | display = PlatformUI.createDisplay(); |
| 59 | 0 | int returnCode = PlatformUI.createAndRunWorkbench(display, |
| 60 | |
new UrumaWorkbenchAdvisor()); |
| 61 | 0 | if (returnCode == PlatformUI.RETURN_RESTART) { |
| 62 | 0 | return IApplication.EXIT_RESTART; |
| 63 | |
} else { |
| 64 | 0 | return IApplication.EXIT_OK; |
| 65 | |
} |
| 66 | 0 | } catch (Throwable ex) { |
| 67 | 0 | if (display == null) { |
| 68 | 0 | display = new Display(); |
| 69 | |
} |
| 70 | 0 | Shell shell = new Shell(display); |
| 71 | 0 | String msg = MessageUtil.getMessageWithBundleName( |
| 72 | |
URUMA_MESSAGE_BASE, "RCP_EXCEPTION_OCCURED"); |
| 73 | 0 | UrumaErrorDialog dialog = new UrumaErrorDialog(shell, "Uruma", msg, |
| 74 | |
ex); |
| 75 | 0 | dialog.open(); |
| 76 | 0 | shell.dispose(); |
| 77 | 0 | } finally { |
| 78 | 0 | if ((display != null) && !display.isDisposed()) { |
| 79 | 0 | display.dispose(); |
| 80 | |
} |
| 81 | 0 | } |
| 82 | 0 | return IApplication.EXIT_OK; |
| 83 | |
} |
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
public void stop() { |
| 89 | 0 | logger.log(URUMA_APPLICATION_STOPPING); |
| 90 | |
|
| 91 | 0 | final IWorkbench workbench = PlatformUI.getWorkbench(); |
| 92 | 0 | if (workbench == null) |
| 93 | 0 | return; |
| 94 | 0 | final Display display = workbench.getDisplay(); |
| 95 | 0 | display.syncExec(new Runnable() { |
| 96 | 0 | public void run() { |
| 97 | 0 | if (!display.isDisposed()) { |
| 98 | 0 | workbench.close(); |
| 99 | |
} |
| 100 | 0 | } |
| 101 | |
}); |
| 102 | 0 | } |
| 103 | |
} |