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.binding.value.binder;
17  
18  import java.util.List;
19  
20  import org.eclipse.jface.viewers.ILabelProvider;
21  import org.eclipse.jface.viewers.ILabelProviderListener;
22  import org.eclipse.jface.viewers.TreeNode;
23  import org.eclipse.swt.graphics.Image;
24  import org.eclipse.swt.widgets.Text;
25  import org.seasar.uruma.annotation.EventListener;
26  import org.seasar.uruma.annotation.ExportValue;
27  import org.seasar.uruma.annotation.ImportSelection;
28  import org.seasar.uruma.renderer.impl.AbstractGUITest;
29  
30  /**
31   * {@link TreeViewerValueBinder} のためのテストクラスです。<br />
32   * 
33   * @author y-komori
34   */
35  public class TreeViewerValueBinderGUITest extends AbstractGUITest {
36      @ExportValue(id = "tree1")
37      public TreeNode[] tparent;
38  
39      @ImportSelection(id = "tree1")
40      public List<TreeNode> selected;
41  
42      @ImportSelection(id = "tree1")
43      public TreeNode selected2;
44  
45      public Text textArea;
46  
47      /**
48       * {@link TreeViewerValueBinderGUITest} を構築します。<br />
49       * 
50       */
51      public TreeViewerValueBinderGUITest() {
52          tparent = new TreeNode[2];
53          tparent[0] = new TreeNode("親1");
54          tparent[1] = new TreeNode("親2");
55  
56          TreeNode[] tchild = new TreeNode[2];
57          tchild[0] = new TreeNode("子1");
58          tchild[1] = new TreeNode("子2");
59          tparent[0].setChildren(tchild);
60  
61          TreeNode[] tgrandChild = new TreeNode[2];
62          tgrandChild[0] = new TreeNode("孫1");
63          tgrandChild[1] = new TreeNode("孫2");
64          tchild[0].setChildren(tgrandChild);
65      }
66  
67      @EventListener(id = "tree1")
68      public void onTreeSelected() {
69          String current = textArea.getText();
70  
71          if (current.length() > 0) {
72              current += "\r\n";
73          }
74  
75          current += "NodeSelected : ";
76          for (TreeNode selection : selected) {
77              current += selection.getValue() + ", ";
78          }
79          textArea.setText(current);
80      }
81  
82      /**
83       * 本テストで使用するラベルプロバイダです。<br />
84       * 
85       * @author y-komori
86       */
87      public static class TreeNodeLabelProvider implements ILabelProvider {
88  
89          public Image getImage(final Object element) {
90              return null;
91          }
92  
93          public String getText(final Object element) {
94              if (element instanceof TreeNode) {
95                  TreeNode treeNode = (TreeNode) element;
96                  return treeNode.getValue().toString();
97              }
98              return null;
99          }
100 
101         public void addListener(final ILabelProviderListener listener) {
102         }
103 
104         public void dispose() {
105         }
106 
107         public boolean isLabelProperty(final Object element,
108                 final String property) {
109             return false;
110         }
111 
112         public void removeListener(final ILabelProviderListener listener) {
113         }
114     }
115 }