Coverage Report - org.seasar.uruma.rcp.configuration.extension.PerspectivesBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
PerspectivesBuilder
0%
0/34
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.configuration.extension;
 17  
 
 18  
 import org.seasar.framework.util.StringUtil;
 19  
 import org.seasar.uruma.component.rcp.PerspectiveComponent;
 20  
 import org.seasar.uruma.component.rcp.WorkbenchComponent;
 21  
 import org.seasar.uruma.rcp.configuration.Extension;
 22  
 import org.seasar.uruma.rcp.configuration.ExtensionBuilder;
 23  
 import org.seasar.uruma.rcp.configuration.ExtensionFactory;
 24  
 import org.seasar.uruma.rcp.configuration.ExtensionPoints;
 25  
 import org.seasar.uruma.rcp.configuration.elements.PerspectiveElement;
 26  
 import org.seasar.uruma.rcp.ui.AutoPerspectiveFactory;
 27  
 import org.seasar.uruma.rcp.ui.BlankPerspectiveFactory;
 28  
 import org.seasar.uruma.rcp.ui.GenericPerspectiveFactory;
 29  
 
 30  
 /**
 31  
  * <code>perspectives</code> 拡張ポイントのための {@link ExtensionBuilder} です。<br />
 32  
  * 
 33  
  * @author y-komori
 34  
  */
 35  0
 public class PerspectivesBuilder extends AbstractExtensionBuilder {
 36  
 
 37  
     /*
 38  
      * @see org.seasar.uruma.rcp.configuration.ExtensionBuilder#buildExtension()
 39  
      */
 40  
     public Extension[] buildExtension() {
 41  0
         Extension extension = ExtensionFactory
 42  
                 .createExtension(ExtensionPoints.PERSPECTIVES);
 43  
 
 44  0
         WorkbenchComponent workbenchComponent = service.getWorkbenchComponent();
 45  0
         if (DUMMY_WORKBENCH_PATH.equals(workbenchComponent.getPath())) {
 46  0
             return new Extension[] { createBlankPerspective() };
 47  
         }
 48  
 
 49  0
         boolean defaultIdUsed = false;
 50  
 
 51  
         for (PerspectiveComponent perspective : workbenchComponent
 52  0
                 .getPerspectives()) {
 53  
 
 54  
             // ID のついていない最初のパースペクティブにはデフォルトIDをつける
 55  0
             if (StringUtil.isBlank(perspective.id) && !defaultIdUsed) {
 56  0
                 perspective.id = DEFAULT_PERSPECTIVE_ID;
 57  0
                 defaultIdUsed = true;
 58  
             }
 59  
 
 60  0
             PerspectiveElement element = new PerspectiveElement(perspective);
 61  0
             element.clazz = GenericPerspectiveFactory.class.getName();
 62  
 
 63  0
             extension.addElement(element);
 64  0
         }
 65  
 
 66  0
         if (extension.getElements().size() == 0) {
 67  
             // perspective 要素が定義されていないときにデフォルト設定を行う
 68  0
             PerspectiveComponent component = new PerspectiveComponent();
 69  0
             component.clazz = AutoPerspectiveFactory.class.getName();
 70  0
             component.id = DEFAULT_PERSPECTIVE_ID;
 71  0
             component.name = service.getPluginId();
 72  
 
 73  0
             workbenchComponent.addChild(component);
 74  0
             workbenchComponent.initialPerspectiveId = DEFAULT_PERSPECTIVE_ID;
 75  
 
 76  0
             PerspectiveElement element = new PerspectiveElement(component);
 77  0
             extension.addElement(element);
 78  
 
 79  0
         } else if (StringUtil.isBlank(workbenchComponent.initialPerspectiveId)) {
 80  
             // initialPerspectiveId が定義されていない場合は
 81  
             // 最初に記述されている perspective を表示する
 82  0
             PerspectiveComponent perspective = workbenchComponent
 83  
                     .getPerspectives().get(0);
 84  0
             workbenchComponent.initialPerspectiveId = perspective.id;
 85  
         }
 86  
 
 87  0
         return new Extension[] { extension };
 88  
     }
 89  
 
 90  
     protected Extension createBlankPerspective() {
 91  0
         Extension extension = ExtensionFactory
 92  
                 .createExtension(ExtensionPoints.PERSPECTIVES);
 93  
 
 94  0
         PerspectiveElement blank = new PerspectiveElement();
 95  0
         blank.clazz = BlankPerspectiveFactory.class.getName();
 96  0
         blank.id = service.createRcpId(DEFAULT_PERSPECTIVE_ID);
 97  0
         blank.name = "";
 98  
 
 99  0
         extension.addElement(blank);
 100  0
         return extension;
 101  
     }
 102  
 }