Coverage Report - org.seasar.uruma.core.impl.UrumaWindowManagerImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
UrumaWindowManagerImpl
76%
39/51
31%
5/16
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.core.impl;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.HashMap;
 20  
 import java.util.List;
 21  
 import java.util.Map;
 22  
 
 23  
 import org.eclipse.jface.window.WindowManager;
 24  
 import org.eclipse.swt.widgets.Shell;
 25  
 import org.seasar.framework.container.annotation.tiger.Binding;
 26  
 import org.seasar.framework.container.annotation.tiger.BindingType;
 27  
 import org.seasar.framework.container.annotation.tiger.Component;
 28  
 import org.seasar.framework.util.AssertionUtil;
 29  
 import org.seasar.uruma.binding.context.ApplicationContextBinder;
 30  
 import org.seasar.uruma.binding.context.ApplicationContextDef;
 31  
 import org.seasar.uruma.component.Template;
 32  
 import org.seasar.uruma.component.jface.WindowComponent;
 33  
 import org.seasar.uruma.context.ApplicationContext;
 34  
 import org.seasar.uruma.context.ContextFactory;
 35  
 import org.seasar.uruma.context.WindowContext;
 36  
 import org.seasar.uruma.context.impl.ApplicationContextImpl;
 37  
 import org.seasar.uruma.core.TemplateManager;
 38  
 import org.seasar.uruma.core.UrumaMessageCodes;
 39  
 import org.seasar.uruma.core.UrumaWindowManager;
 40  
 import org.seasar.uruma.desc.PartActionDesc;
 41  
 import org.seasar.uruma.desc.PartActionDescFactory;
 42  
 import org.seasar.uruma.log.UrumaLogger;
 43  
 import org.seasar.uruma.ui.UrumaApplicationWindow;
 44  
 
 45  
 /**
 46  
  * ウィンドウを管理するためのクラスです。</br>
 47  
  * 
 48  
  * @author y-komori
 49  
  * @author bskuroneko
 50  
  */
 51  
 @Component
 52  128
 public class UrumaWindowManagerImpl implements UrumaWindowManager {
 53  4
     private static final UrumaLogger logger = UrumaLogger
 54  
             .getLogger(UrumaWindowManager.class);
 55  
 
 56  128
     private WindowManager windowManager = new WindowManager();
 57  
 
 58  128
     private Map<String, WindowComponent> windowMap = new HashMap<String, WindowComponent>();
 59  
 
 60  128
     private List<UrumaApplicationWindow> windowList = new ArrayList<UrumaApplicationWindow>();
 61  
 
 62  128
     private TemplateManager templateManager = new TemplateManagerImpl();
 63  
 
 64  
     /**
 65  
      * 画面間のパラメータ共有に使用する {@link ApplicationContext} オブジェクトです。
 66  
      */
 67  
     @Binding(bindingType = BindingType.MUST)
 68  
     public ApplicationContext applicationContext;
 69  
 
 70  
     /*
 71  
      * @see org.seasar.uruma.core.UrumaWindowManager#close(java.lang.String)
 72  
      */
 73  
     public void close(final String windowId) {
 74  112
         UrumaApplicationWindow window = findWindow(windowId);
 75  112
         if (window != null) {
 76  112
             logger.log(UrumaMessageCodes.CLOSE_WINDOW, windowId);
 77  
 
 78  112
             windowList.remove(window);
 79  112
             windowMap.remove(windowId);
 80  112
             ((ApplicationContextImpl) applicationContext)
 81  
                     .disposeWindowContext(windowId);
 82  
 
 83  112
             Shell shell = window.getShell();
 84  112
             if (shell != null && !shell.isDisposed()) {
 85  0
                 shell.close();
 86  
             }
 87  
         }
 88  112
     }
 89  
 
 90  
     /*
 91  
      * @see org.seasar.uruma.core.UrumaWindowManager#openWindow(java.lang.String,
 92  
      *      boolean)
 93  
      */
 94  
     public UrumaApplicationWindow openWindow(final String templatePath,
 95  
             final boolean modal) {
 96  112
         Template template = loadTemplate(templatePath);
 97  112
         UrumaApplicationWindow window = createWindow();
 98  112
         WindowComponent windowComponent = (WindowComponent) template
 99  
                 .getRootComponent();
 100  112
         String windowId = windowComponent.getId();
 101  
 
 102  112
         WindowContext windowContext = ContextFactory.createWindowContext(
 103  
                 applicationContext, windowId);
 104  
 
 105  112
         logger.log(UrumaMessageCodes.INIT_WINDOW, windowId);
 106  112
         window.init(windowContext, windowComponent, modal);
 107  
 
 108  112
         if (modal) {
 109  112
             window.setBlockOnOpen(true);
 110  
         }
 111  112
         windowManager.add(window);
 112  
 
 113  112
         logger.log(UrumaMessageCodes.OPEN_WINDOW, windowId);
 114  112
         window.open();
 115  112
         return window;
 116  
     }
 117  
 
 118  
     protected Template loadTemplate(final String path) {
 119  112
         Template template = templateManager.getTemplate(path);
 120  112
         WindowComponent window = (WindowComponent) template.getRootComponent();
 121  112
         windowMap.put(window.getId(), window);
 122  112
         return template;
 123  
     }
 124  
 
 125  
     /*
 126  
      * @see org.seasar.uruma.core.UrumaWindowManager#openDialog(java.lang.String,
 127  
      *      java.lang.Object)
 128  
      */
 129  
     public int openDialog(final String templatePath, final Object parentAction) {
 130  
         // TODO 仮実装
 131  
         // 親画面から ApplicationContext へのエクスポート処理
 132  0
         if (parentAction != null) {
 133  0
             PartActionDesc desc = PartActionDescFactory
 134  
                     .getPartActionDesc(parentAction.getClass());
 135  0
             List<ApplicationContextDef> defs = desc
 136  
                     .getApplicationContextDefList();
 137  0
             ApplicationContextBinder.exportObjects(parentAction, defs,
 138  
                     applicationContext);
 139  
         }
 140  
 
 141  0
         openWindow(templatePath, true);
 142  
 
 143  
         // ApplicationContext から親画面へのインポート処理
 144  0
         if (parentAction != null) {
 145  0
             PartActionDesc desc = PartActionDescFactory
 146  
                     .getPartActionDesc(parentAction.getClass());
 147  0
             List<ApplicationContextDef> defs = desc
 148  
                     .getApplicationContextDefList();
 149  0
             ApplicationContextBinder.importObjects(parentAction, defs,
 150  
                     applicationContext);
 151  
         }
 152  0
         return 0;
 153  
     }
 154  
 
 155  
     protected UrumaApplicationWindow createWindow() {
 156  112
         UrumaApplicationWindow window = new UrumaApplicationWindow(this);
 157  112
         windowList.add(window);
 158  112
         return window;
 159  
     }
 160  
 
 161  
     protected UrumaApplicationWindow findWindow(final String windowId) {
 162  112
         AssertionUtil.assertNotNull("windowId", windowId);
 163  
 
 164  112
         for (UrumaApplicationWindow window : windowList) {
 165  112
             if (windowId.equals(window.getWindowId())) {
 166  112
                 return window;
 167  
             }
 168  
         }
 169  0
         return null;
 170  
     }
 171  
 }