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.jface;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.seasar.framework.util.StringUtil;
22  import org.seasar.uruma.annotation.ComponentAttribute;
23  import org.seasar.uruma.annotation.ComponentElement;
24  import org.seasar.uruma.annotation.FieldDescription;
25  import org.seasar.uruma.annotation.RenderingPolicy;
26  import org.seasar.uruma.annotation.RenderingPolicy.TargetType;
27  import org.seasar.uruma.component.UIComponent;
28  import org.seasar.uruma.component.UIComponentContainer;
29  import org.seasar.uruma.component.UIElement;
30  import org.seasar.uruma.component.UIElementVisitor;
31  import org.seasar.uruma.component.rcp.ViewPartComponent;
32  import org.seasar.uruma.context.WidgetHandle;
33  import org.seasar.uruma.context.WindowContext;
34  import org.seasar.uruma.util.AssertionUtil;
35  
36  /**
37   * メニュー情報を保持するためのコンポーネントです。<br />
38   * 
39   * @author bskuroneko
40   * @author y-komori
41   */
42  @ComponentElement
43  public class MenuComponent extends MenuItemComponent implements
44          UIComponentContainer {
45      /**
46       * デフォルトアイテムIDです。<br />
47       */
48      @RenderingPolicy(targetType = TargetType.NONE)
49      @ComponentAttribute
50      @FieldDescription("デフォルトアイテムID")
51      public String defaultItemId;
52  
53      /**
54       * 可視状態です。<br />
55       */
56      @RenderingPolicy(targetType = TargetType.NONE)
57      @ComponentAttribute
58      @FieldDescription("可視状態")
59      public String visible;
60  
61      /**
62       * メニューの表示 X座標です。<br />
63       */
64      @RenderingPolicy(targetType = TargetType.NONE)
65      @ComponentAttribute
66      @FieldDescription("メニューの表示 X 座標")
67      public String x;
68  
69      /**
70       * メニューの表示 Y 座標です。<br />
71       */
72      @RenderingPolicy(targetType = TargetType.NONE)
73      @ComponentAttribute
74      @FieldDescription("メニューの表示 Y 座標")
75      public String y;
76  
77      private List<UIElement> children = new ArrayList<UIElement>();
78  
79      /*
80       * @see
81       * org.seasar.uruma.component.UIElementContainer#addChild(org.seasar.uruma
82       * .component.UIElement)
83       */
84      public void addChild(final UIElement child) {
85          AssertionUtil.assertNotNull("child", child);
86          AssertionUtil.assertInstanceOf("child", MenuItemComponent.class, child);
87  
88          this.children.add(child);
89      }
90  
91      /*
92       * @see org.seasar.uruma.component.UIElementContainer#getChildren()
93       */
94      public List<UIElement> getChildren() {
95          return this.children;
96      }
97  
98      /*
99       * @see
100      * org.seasar.uruma.component.jface.AbstractUIComponent#doPreRender(org.
101      * seasar.uruma.context.WidgetHandle,
102      * org.seasar.uruma.context.WindowContext)
103      */
104     @Override
105     protected void doPreRender(final WidgetHandle parent,
106             final WindowContext context) {
107         UIComponentContainer parentComponent = getParent();
108 
109         if (parentComponent instanceof WindowComponent) {
110             WindowComponent windowComponent = (WindowComponent) parentComponent;
111             if (StringUtil.isEmpty(windowComponent.menu)) {
112                 windowComponent.menu = getId();
113             }
114         } else if (parentComponent instanceof ViewPartComponent) {
115             // RCP版の場合は、メニューをレンダリングしない
116             return;
117         }
118 
119         for (UIElement child : children) {
120             if (child instanceof UIComponent) {
121                 ((UIComponent) child).preRender(context
122                         .getWidgetHandle(getId()), context);
123             }
124         }
125     }
126 
127     /*
128      * @see
129      * org.seasar.uruma.component.base.AbstractUIElement#accept(org.seasar.uruma
130      * .component.UIElementVisitor)
131      */
132     @Override
133     public void accept(final UIElementVisitor visitor) {
134         visitor.visit(this);
135     }
136 }