Coverage Report - org.seasar.uruma.component.jface.TreeItemComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
TreeItemComponent
85%
11/13
100%
2/2
0
 
 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.Collections;
 20  
 import java.util.List;
 21  
 
 22  
 import org.eclipse.swt.widgets.TreeItem;
 23  
 import org.seasar.uruma.annotation.ComponentAttribute;
 24  
 import org.seasar.uruma.annotation.ComponentElement;
 25  
 import org.seasar.uruma.annotation.FieldDescription;
 26  
 import org.seasar.uruma.annotation.RenderingPolicy;
 27  
 import org.seasar.uruma.annotation.RenderingPolicy.ConversionType;
 28  
 import org.seasar.uruma.annotation.RenderingPolicy.TargetType;
 29  
 import org.seasar.uruma.component.base.AbstractUIComponent;
 30  
 import org.seasar.uruma.context.PartContext;
 31  
 import org.seasar.uruma.context.WidgetHandle;
 32  
 
 33  
 /**
 34  
  * {@link TreeItem} を表すコンポーネント。<br />
 35  
  * 
 36  
  * @author y-komori
 37  
  */
 38  
 @ComponentElement
 39  32
 public class TreeItemComponent extends AbstractUIComponent {
 40  
     /**
 41  
      * テキストです。
 42  
      */
 43  
     @RenderingPolicy(targetType = TargetType.NONE)
 44  
     @ComponentAttribute
 45  
     @FieldDescription("テキスト")
 46  
     // TreeItem には複数の setText() メソッドが存在するため、
 47  
     // 独自にレンダリングを行う
 48  
     public String text;
 49  
 
 50  
     /**
 51  
      * イメージパスです。
 52  
      */
 53  
     @RenderingPolicy(targetType = TargetType.NONE)
 54  
     @ComponentAttribute
 55  
     @FieldDescription("イメージ")
 56  
     // TreeItem には複数の setImage() メソッドが存在するため、
 57  
     // 独自にレンダリングを行う
 58  
     public String image;
 59  
 
 60  
     /**
 61  
      * 背景色です。
 62  
      */
 63  
     @RenderingPolicy(conversionType = ConversionType.COLOR)
 64  
     @ComponentAttribute
 65  
     @FieldDescription("背景色")
 66  
     public String background;
 67  
 
 68  
     /**
 69  
      * チェック状態です。
 70  
      */
 71  
     @RenderingPolicy(conversionType = ConversionType.BOOLEAN)
 72  
     @ComponentAttribute
 73  
     @FieldDescription("チェック状態")
 74  
     public String checked;
 75  
 
 76  
     /**
 77  
      * 展開状態です。
 78  
      */
 79  
     @RenderingPolicy(conversionType = ConversionType.BOOLEAN)
 80  
     @ComponentAttribute
 81  
     @FieldDescription("展開状態")
 82  
     public String expanded;
 83  
 
 84  
     /**
 85  
      * フォント高さです。
 86  
      */
 87  
     @RenderingPolicy(conversionType = ConversionType.INT)
 88  
     @ComponentAttribute
 89  
     @FieldDescription("フォント高さ")
 90  
     public String fontHeight;
 91  
 
 92  
     /**
 93  
      * フォント名称です。
 94  
      */
 95  
     @RenderingPolicy(conversionType = ConversionType.STRING)
 96  
     @ComponentAttribute
 97  
     @FieldDescription("フォント名称")
 98  
     public String fontName;
 99  
 
 100  
     /**
 101  
      * フォントスタイルです。
 102  
      */
 103  
     @RenderingPolicy(conversionType = ConversionType.STRING)
 104  
     @ComponentAttribute
 105  
     @FieldDescription("フォントスタイル")
 106  
     public String fontStyle;
 107  
 
 108  
     /**
 109  
      * 前景色です。
 110  
      */
 111  
     @RenderingPolicy(conversionType = ConversionType.COLOR)
 112  
     @ComponentAttribute
 113  
     @FieldDescription("前景色")
 114  
     public String foreground;
 115  
 
 116  
     /**
 117  
      * グレーアウト状態です。
 118  
      */
 119  
     @RenderingPolicy(conversionType = ConversionType.BOOLEAN)
 120  
     @ComponentAttribute
 121  
     @FieldDescription("グレーアウト状態")
 122  
     public String grayed;
 123  
 
 124  
     private TreeItemComponent parent;
 125  
 
 126  32
     private List<TreeItemComponent> children = new ArrayList<TreeItemComponent>();
 127  
 
 128  
     /*
 129  
      * @see org.seasar.uruma.component.jface.AbstractUIComponent#doRender(org.seasar.uruma.context.WidgetHandle,
 130  
      *      org.seasar.uruma.context.PartContext)
 131  
      */
 132  
     @Override
 133  
     protected void doRender(final WidgetHandle parent, final PartContext context) {
 134  32
         renderChildren(context.getWidgetHandle(getId()), context);
 135  32
     }
 136  
 
 137  
     protected void renderChildren(final WidgetHandle parent,
 138  
             final PartContext context) {
 139  32
         for (TreeItemComponent child : children) {
 140  24
             child.render(parent, context);
 141  
         }
 142  32
     }
 143  
 
 144  
     /**
 145  
      * 親ツリー項目を取得します。<br />
 146  
      * 
 147  
      * @return 親ツリー項目
 148  
      */
 149  
     public TreeItemComponent getParentTreeItem() {
 150  0
         return this.parent;
 151  
     }
 152  
 
 153  
     /**
 154  
      * 親ツリー項目を設定します。<br />
 155  
      * 
 156  
      * @param parent
 157  
      *            親ツリー項目
 158  
      */
 159  
     public void setParentTreeItem(final TreeItemComponent parent) {
 160  24
         this.parent = parent;
 161  24
     }
 162  
 
 163  
     /**
 164  
      * 子ツリー項目を追加します。<br />
 165  
      * 
 166  
      * @param treeItem
 167  
      *            子ツリー項目
 168  
      */
 169  
     public void addTreeItem(final TreeItemComponent treeItem) {
 170  24
         children.add(treeItem);
 171  24
     }
 172  
 
 173  
     /**
 174  
      * 子ツリー項目のリストを取得します。<br />
 175  
      * 
 176  
      * @return 子ツリー項目のリスト
 177  
      */
 178  
     public List<TreeItemComponent> getTreeItems() {
 179  0
         return Collections.unmodifiableList(this.children);
 180  
     }
 181  
 }