View Javadoc

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