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.renderer.layout.impl;
17  
18  import org.eclipse.swt.widgets.Layout;
19  import org.seasar.uruma.annotation.RenderingPolicy.SetTiming;
20  import org.seasar.uruma.component.LayoutDataInfo;
21  import org.seasar.uruma.component.LayoutInfo;
22  import org.seasar.uruma.component.UIComponent;
23  import org.seasar.uruma.renderer.RendererSupportUtil;
24  import org.seasar.uruma.renderer.layout.LayoutSupport;
25  import org.seasar.uruma.util.ClassUtil;
26  
27  /**
28   * 汎用的な {@link LayoutSupport} の実装クラスです。
29   * 
30   * @author y-komori
31   */
32  public class GenericLayoutSupport implements LayoutSupport {
33      private Class<? extends Layout> layoutClass;
34  
35      private Class<? extends Object> layoutDataClass;
36  
37      /**
38       * {@link GenericLayoutSupport} を構築します。<br />
39       * 
40       * @param layoutClass
41       *            {@link Layout} クラス
42       * @param layoutDataClass
43       *            レイアウトデータクラス
44       */
45      public GenericLayoutSupport(final Class<? extends Layout> layoutClass,
46              final Class<? extends Object> layoutDataClass) {
47          this.layoutClass = layoutClass;
48          this.layoutDataClass = layoutDataClass;
49      }
50  
51      public Layout createLayout() {
52          return ClassUtil.newInstance(layoutClass);
53      }
54  
55      public Layout createLayout(final LayoutInfo<?> layoutInfo) {
56          Layout layout = createLayout();
57          RendererSupportUtil.setAttributes(layoutInfo, layout, SetTiming.RENDER);
58          return layout;
59      }
60  
61      public Object createLayoutData() {
62          if (layoutDataClass != null) {
63              return ClassUtil.newInstance(layoutDataClass);
64          } else {
65              return null;
66          }
67      }
68  
69      public Object createLayoutData(final UIComponent uiComponent,
70              final LayoutDataInfo layoutDataInfo) {
71          if (layoutDataClass != null) {
72              Object layoutData = createLayoutData();
73              RendererSupportUtil.setAttributes(layoutDataInfo, layoutData,
74                      SetTiming.RENDER);
75              return layoutData;
76          } else {
77              return null;
78          }
79      }
80  }