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.renderer.impl;
17  
18  import org.eclipse.jface.viewers.IBaseLabelProvider;
19  import org.eclipse.jface.viewers.TableViewer;
20  import org.eclipse.swt.widgets.TableColumn;
21  import org.seasar.uruma.component.jface.TableColumnComponent;
22  import org.seasar.uruma.context.PartContext;
23  import org.seasar.uruma.context.WidgetHandle;
24  import org.seasar.uruma.viewer.GenericTableLabelProvider;
25  
26  /**
27   * {@link TableColumn} のレンダリングを行うクラスです。<br />
28   * 
29   * @author bskuroneko
30   */
31  public class TableColumnRenderer extends
32          AbstractWidgetRenderer<TableColumnComponent, TableColumn> {
33  
34      /*
35       * @see org.seasar.uruma.renderer.impl.AbstractWidgetRenderer#doRender(org.seasar.uruma.component.UIComponent,
36       *      org.eclipse.swt.widgets.Widget)
37       */
38      @Override
39      protected void doRender(final TableColumnComponent uiComponent,
40              final TableColumn widget) {
41          // widget.pack();
42  
43          setupColumnMap(uiComponent, widget);
44      }
45  
46      /*
47       * @see org.seasar.uruma.renderer.impl.AbstractWidgetRenderer#getWidgetType()
48       */
49      @Override
50      protected Class<TableColumn> getWidgetType() {
51          return TableColumn.class;
52      }
53  
54      private void setupColumnMap(final TableColumnComponent uiComponent,
55              final TableColumn widget) {
56          int columnNo = uiComponent.columnNo;
57          String id = uiComponent.getId();
58          String parentId = uiComponent.getParent().getId();
59  
60          PartContext context = getContext();
61          WidgetHandle parentHandle = context.getWidgetHandle(parentId);
62          if (parentHandle != null && parentHandle.instanceOf(TableViewer.class)) {
63              TableViewer viewer = parentHandle.<TableViewer> getCastWidget();
64              IBaseLabelProvider baseLabelProvider = viewer.getLabelProvider();
65  
66              if (baseLabelProvider instanceof GenericTableLabelProvider) {
67                  GenericTableLabelProvider provider = (GenericTableLabelProvider) baseLabelProvider;
68                  provider.addColumnMap(columnNo, id);
69              }
70          }
71      }
72  }