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.ArrayList;
19  import java.util.List;
20  
21  import org.eclipse.jface.viewers.TableViewer;
22  import org.eclipse.swt.widgets.Table;
23  import org.eclipse.swt.widgets.TableColumn;
24  import org.eclipse.swt.widgets.TableItem;
25  import org.seasar.uruma.annotation.EventListener;
26  import org.seasar.uruma.annotation.ExportValue;
27  import org.seasar.uruma.annotation.Form;
28  import org.seasar.uruma.annotation.ImportSelection;
29  import org.seasar.uruma.annotation.InitializeMethod;
30  import org.seasar.uruma.renderer.impl.AbstractGUITest;
31  
32  /**
33   * {@link TableViewerValueBinder} のためのテストクラスです。<br />
34   * 
35   * @author y-komori
36   */
37  public class TableViewerValueBinderGUITest extends AbstractGUITest {
38      @ExportValue(id = "table")
39      public List<Contents> contents;
40  
41      public TableViewer table;
42  
43      @ImportSelection(id = "table")
44      public Contents selected;
45  
46      @InitializeMethod
47      public void initialize() {
48          contents = new ArrayList<Contents>();
49          Contents row1 = new Contents("aaa", "bbb", "ccc", "ddd");
50          Contents row2 = new Contents("111", "222", "333", "444");
51          contents.add(row1);
52          contents.add(row2);
53      }
54  
55      @EventListener(id = "select")
56      public void onSelect() {
57          System.out.println("選択された : " + table);
58  
59          Table widget = table.getTable();
60          TableColumn[] columns = widget.getColumns();
61          for (int i = 0; i < columns.length; i++) {
62              System.out.println(columns[i].getText());
63              System.out.println(columns[i].getWidth());
64              columns[i].pack();
65          }
66  
67          TableItem[] items = widget.getItems();
68          for (int i = 0; i < items.length; i++) {
69              System.out.println(items[i].getBounds());
70          }
71          table.refresh(true);
72      }
73  
74      @EventListener(id = "table")
75      public void onTableSelect() {
76          System.out.println(selected);
77  
78      }
79  
80      /**
81       * @author y-komori
82       * 
83       */
84      private static class Contents {
85          public String column1;
86  
87          public String column2;
88  
89          public String column3;
90  
91          public String column4;
92  
93          /**
94           * {@link Contents} を構築します。<br />
95           * 
96           * @param column1
97           * @param column2
98           * @param column3
99           * @param column4
100          */
101         public Contents(final String column1, final String column2,
102                 final String column3, final String column4) {
103             this.column1 = column1;
104             this.column2 = column2;
105             this.column3 = column3;
106             this.column4 = column4;
107         }
108     }
109 }