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.binding.value.binder;
17  
18  import org.eclipse.jface.viewers.TableViewer;
19  import org.eclipse.swt.widgets.Table;
20  import org.eclipse.swt.widgets.TableColumn;
21  import org.seasar.framework.beans.PropertyDesc;
22  import org.seasar.uruma.binding.value.ValueBinder;
23  import org.seasar.uruma.component.UIComponent;
24  import org.seasar.uruma.component.jface.TableColumnComponent;
25  import org.seasar.uruma.component.jface.TableComponent;
26  
27  /**
28   * {@link TableViewer} のための {@link ValueBinder} です。<br />
29   * 
30   * @author y-komori
31   */
32  public class TableViewerValueBinder extends AbstractValueBinder<TableViewer> {
33  
34      /**
35       * {@link TableViewerValueBinder} を構築します。<br />
36       * 
37       */
38      public TableViewerValueBinder() {
39          super(TableViewer.class);
40      }
41  
42      /*
43       * @see org.seasar.uruma.binding.value.binder.AbstractValueBinder#doExportValue(java.lang.Object,
44       *      java.lang.Object, org.seasar.framework.beans.PropertyDesc)
45       */
46      @Override
47      protected void doExportValue(final TableViewer widget,
48              final Object formObj, final PropertyDesc propDesc,
49              final UIComponent uiComp) {
50          super.doExportValue(widget, formObj, propDesc, uiComp);
51  
52          Table table = widget.getTable();
53          table.setRedraw(false);
54          TableColumn[] columns = table.getColumns();
55          TableComponent tableComp = (TableComponent) uiComp;
56          for (int i = 0; i < columns.length; i++) {
57              if (((TableColumnComponent) tableComp.getChildren().get(i)).width == null) {
58                  columns[i].pack();
59              }
60          }
61          table.setRedraw(true);
62      }
63  }