Coverage Report - org.seasar.uruma.rcp.ui.UrumaWorkbenchAdvisor
 
Classes in this File Line Coverage Branch Coverage Complexity
UrumaWorkbenchAdvisor
0%
0/39
0%
0/12
0
 
 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.ui;
 17  
 
 18  
 import java.util.ResourceBundle;
 19  
 
 20  
 import org.eclipse.swt.widgets.Display;
 21  
 import org.eclipse.swt.widgets.Shell;
 22  
 import org.eclipse.ui.application.IWorkbenchConfigurer;
 23  
 import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
 24  
 import org.eclipse.ui.application.WorkbenchAdvisor;
 25  
 import org.eclipse.ui.application.WorkbenchWindowAdvisor;
 26  
 import org.seasar.eclipse.common.util.ImageManager;
 27  
 import org.seasar.framework.util.StringUtil;
 28  
 import org.seasar.uruma.component.rcp.WorkbenchComponent;
 29  
 import org.seasar.uruma.core.UrumaConstants;
 30  
 import org.seasar.uruma.core.UrumaMessageCodes;
 31  
 import org.seasar.uruma.exception.NotFoundException;
 32  
 import org.seasar.uruma.log.UrumaLogger;
 33  
 import org.seasar.uruma.rcp.UrumaService;
 34  
 import org.seasar.uruma.rcp.util.UrumaServiceUtil;
 35  
 import org.seasar.uruma.ui.dialogs.UrumaErrorDialog;
 36  
 import org.seasar.uruma.util.MessageUtil;
 37  
 
 38  
 /**
 39  
  * Uruma における {@link WorkbenchAdvisor} です。<br />
 40  
  * 
 41  
  * @author y-komori
 42  
  */
 43  0
 public class UrumaWorkbenchAdvisor extends WorkbenchAdvisor implements
 44  
         UrumaMessageCodes, UrumaConstants {
 45  0
     private static final UrumaLogger logger = UrumaLogger
 46  
             .getLogger(UrumaWorkbenchAdvisor.class);
 47  
 
 48  
     /*
 49  
      * @see org.eclipse.ui.application.WorkbenchAdvisor#initialize(org.eclipse.ui.application.IWorkbenchConfigurer)
 50  
      */
 51  
     @Override
 52  
     public void initialize(final IWorkbenchConfigurer configurer) {
 53  0
         UrumaService service = UrumaServiceUtil.getService();
 54  
 
 55  0
         service.getContainer().register(configurer);
 56  
 
 57  
         // ウィンドウの位置・サイズの保存可否を指定します。
 58  0
         WorkbenchComponent workbench = service.getWorkbenchComponent();
 59  0
         boolean flg = Boolean.parseBoolean(workbench.saveAndRestore);
 60  0
         configurer.setSaveAndRestore(flg);
 61  
 
 62  0
         ResourceBundle imageBundle = service.getImageBundle();
 63  0
         if (imageBundle != null) {
 64  0
             logger.log(UrumaMessageCodes.LOADING_IMAGE_BUNDLE, imageBundle);
 65  0
             ImageManager.loadImages(imageBundle);
 66  
         }
 67  0
     }
 68  
 
 69  
     /*
 70  
      * @see org.eclipse.ui.application.WorkbenchAdvisor#preShutdown()
 71  
      */
 72  
     @Override
 73  
     public boolean preShutdown() {
 74  0
         ImageManager.dispose();
 75  0
         return true;
 76  
     }
 77  
 
 78  
     /*
 79  
      * @see org.eclipse.ui.application.WorkbenchAdvisor#getInitialWindowPerspectiveId()
 80  
      */
 81  
     @Override
 82  
     public String getInitialWindowPerspectiveId() {
 83  0
         UrumaService service = UrumaServiceUtil.getService();
 84  
 
 85  0
         String perspectiveId = service.getWorkbenchComponent().initialPerspectiveId;
 86  
 
 87  0
         if (StringUtil.isNotBlank(perspectiveId)) {
 88  0
             WorkbenchComponent workbench = UrumaServiceUtil.getService()
 89  
                     .getWorkbenchComponent();
 90  0
             if (workbench.findPerspective(perspectiveId) != null) {
 91  0
                 return service.createRcpId(perspectiveId);
 92  
             } else {
 93  0
                 throw new NotFoundException(
 94  
                         UrumaMessageCodes.PERSPECTIVE_NOT_FOUND, perspectiveId);
 95  
             }
 96  
         } else {
 97  0
             return service.createRcpId(UrumaConstants.DEFAULT_PERSPECTIVE_ID);
 98  
         }
 99  
     }
 100  
 
 101  
     /*
 102  
      * @see org.eclipse.ui.application.WorkbenchAdvisor#createWorkbenchWindowAdvisor(org.eclipse.ui.application.IWorkbenchWindowConfigurer)
 103  
      */
 104  
     @Override
 105  
     public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(
 106  
             final IWorkbenchWindowConfigurer configurer) {
 107  0
         return new UrumaWorkbenchWindowAdvisor(configurer);
 108  
     }
 109  
 
 110  
     /*
 111  
      * @see org.eclipse.ui.application.WorkbenchAdvisor#eventLoopException(java.lang.Throwable)
 112  
      */
 113  
     @Override
 114  
     public void eventLoopException(final Throwable throwable) {
 115  0
         logger.log(EXCEPTION_OCCURED_WITH_REASON, throwable, throwable
 116  
                 .getMessage());
 117  
 
 118  0
         Display display = getWorkbenchConfigurer().getWorkbench().getDisplay();
 119  0
         boolean displayCreated = false;
 120  0
         if (display == null) {
 121  0
             display = Display.getCurrent();
 122  
 
 123  0
             if (display == null) {
 124  0
                 display = new Display();
 125  0
                 displayCreated = true;
 126  
             }
 127  
         }
 128  0
         Shell shell = new Shell(display);
 129  0
         String msg = MessageUtil.getMessageWithBundleName(URUMA_MESSAGE_BASE,
 130  
                 "RCP_EXCEPTION_OCCURED");
 131  0
         UrumaErrorDialog dialog = new UrumaErrorDialog(shell, "Uruma", msg,
 132  
                 throwable);
 133  0
         dialog.open();
 134  0
         shell.dispose();
 135  
 
 136  0
         if (displayCreated) {
 137  0
             display.dispose();
 138  
         }
 139  0
     }
 140  
 }