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.ui;
17  
18  import java.util.List;
19  
20  import org.eclipse.ui.IPageLayout;
21  import org.eclipse.ui.IPerspectiveFactory;
22  import org.seasar.uruma.component.Template;
23  import org.seasar.uruma.component.rcp.ViewPartComponent;
24  import org.seasar.uruma.core.TemplateManager;
25  import org.seasar.uruma.rcp.UrumaService;
26  import org.seasar.uruma.rcp.util.UrumaServiceUtil;
27  
28  /**
29   * パースペクティブを自動的に生成するための {@link IPerspectiveFactory} です。<br />
30   * 
31   * @author y-komori
32   */
33  public class AutoPerspectiveFactory implements IPerspectiveFactory {
34      protected UrumaService service;
35  
36      protected TemplateManager templateManager;
37  
38      /**
39       * {@link AutoPerspectiveFactory} を構築します。<br />
40       */
41      public AutoPerspectiveFactory() {
42          this.service = UrumaServiceUtil.getService();
43          this.templateManager = (TemplateManager) service.getContainer()
44                  .getComponent(TemplateManager.class);
45      }
46  
47      /*
48       * @see org.eclipse.ui.IPerspectiveFactory#createInitialLayout(org.eclipse.ui.IPageLayout)
49       */
50      public void createInitialLayout(final IPageLayout layout) {
51  
52          layout.setEditorAreaVisible(false);
53  
54          List<Template> templates = templateManager
55                  .getTemplates(ViewPartComponent.class);
56  
57          int size = templates.size();
58          for (int i = 0; i < size; i++) {
59              Template template = templates.get(i);
60              ViewPartComponent viewPart = (ViewPartComponent) template
61                      .getRootComponent();
62  
63              // 左から均等に配置されるように割合を計算
64              float ratio = (1 / (float) (size - i));
65              int position = IPageLayout.LEFT;
66              if (i == (templates.size() - 1)) {
67                  position = IPageLayout.RIGHT;
68              }
69  
70              layout.addStandaloneView(service.createRcpId(viewPart.getId()),
71                      true, position, ratio, layout.getEditorArea());
72          }
73      }
74  }