Coverage Report - org.seasar.uruma.rcp.UrumaApplication
 
Classes in this File Line Coverage Branch Coverage Complexity
UrumaApplication
0%
0/32
0%
0/12
4.667
UrumaApplication$1
0%
0/4
0%
0/2
4.667
 
 1  
 /*
 2  
  * Copyright 2004-2008 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 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  
  * RCP 環境での Uruma ブートストラップクラスです。<br />
 36  
  * 
 37  
  * @author y-komori
 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  
      * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
 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  
      * @see org.eclipse.equinox.app.IApplication#stop()
 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  
 }