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.component.base;
17  
18  import java.util.ArrayList;
19  import java.util.Collections;
20  import java.util.List;
21  
22  import org.seasar.uruma.component.UIComponent;
23  import org.seasar.uruma.component.UIComponentContainer;
24  import org.seasar.uruma.component.UIElement;
25  import org.seasar.uruma.context.PartContext;
26  import org.seasar.uruma.context.WidgetHandle;
27  import org.seasar.uruma.context.WindowContext;
28  import org.seasar.uruma.util.AssertionUtil;
29  
30  /**
31   * {@link UIComponentContainer} のための基底クラスです。<br />
32   * 
33   * @author y-komori
34   */
35  public abstract class AbstractUIContainer extends AbstractUIComponent implements
36          UIComponentContainer {
37      protected List<UIElement> children = new ArrayList<UIElement>();
38  
39      /*
40       * @see org.seasar.uruma.component.UIElementContainer#addChild(org.seasar.uruma.component.UIElement)
41       */
42      public void addChild(final UIElement child) {
43          AssertionUtil.assertNotNull("child", child);
44          children.add(child);
45  
46          if (child instanceof UIComponent) {
47              ((UIComponent) child).setParent(this);
48          }
49      }
50  
51      /*
52       * @see org.seasar.uruma.component.UIElementContainer#getChildren()
53       */
54      public List<UIElement> getChildren() {
55          return Collections.unmodifiableList(children);
56      }
57  
58      /*
59       * @see org.seasar.uruma.component.jface.AbstractUIComponent#doPreRender(org.seasar.uruma.context.WidgetHandle,
60       *      org.seasar.uruma.context.WindowContext)
61       */
62      @Override
63      protected void doPreRender(final WidgetHandle parent,
64              final WindowContext context) {
65          for (UIElement child : children) {
66              if (child instanceof UIComponent) {
67                  ((UIComponent) child).preRender(parent, context);
68              }
69          }
70      }
71  
72      /*
73       * @see org.seasar.uruma.component.jface.AbstractUIComponent#doRender(org.seasar.uruma.context.WidgetHandle,
74       *      org.seasar.uruma.context.PartContext)
75       */
76      @Override
77      protected void doRender(final WidgetHandle parent, final PartContext context) {
78          for (UIElement child : children) {
79              if (child instanceof UIComponent) {
80                  ((UIComponent) child).render(parent, context);
81              }
82          }
83      }
84  
85  }