ColumnFactoryExt.java
上传用户:zhengdagz
上传日期:2014-03-06
资源大小:1956k
文件大小:3k
源码类别:

xml/soap/webservice

开发平台:

Java

  1. /*
  2.  * $Id $Exp
  3.  * Copyright 2005 Sun Microsystems, Inc., 4150 Network Circle,
  4.  * Santa Clara, California 95054, U.S.A. All rights reserved.
  5.  *
  6.  * This library is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU Lesser General Public
  8.  * License as published by the Free Software Foundation; either
  9.  * version 2.1 of the License, or (at your option) any later version.
  10.  * 
  11.  * This library is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  * Lesser General Public License for more details.
  15.  * 
  16.  * You should have received a copy of the GNU Lesser General Public
  17.  * License along with this library; if not, write to the Free Software
  18.  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  19.  */
  20. package org.jdesktop.binding.swingx.table;
  21. import java.text.Collator;
  22. import javax.swing.table.TableModel;
  23. import org.jdesktop.binding.metadata.MetaData;
  24. import org.jdesktop.binding.metadata.MetaDataProvider;
  25. import org.jdesktop.swingx.table.ColumnFactory;
  26. import org.jdesktop.swingx.table.TableColumnExt;
  27. /**
  28.  * @author Jeanette Winzenburg
  29.  */
  30. public class ColumnFactoryExt extends ColumnFactory {
  31.     
  32.     public void configureTableColumn(TableModel model, TableColumnExt column) {
  33.         if (model instanceof MetaDataProvider) {
  34.             configureTableColumn((MetaDataProvider) model, column);
  35.         } else {
  36.             super.configureTableColumn(model, column);
  37.             
  38.         }
  39.     }
  40.     public void configureTableColumn(MetaDataProvider provider,
  41.             TableColumnExt column) {
  42.         MetaData metaData = provider
  43.                 .getMetaData(provider.getFieldNames()[column.getModelIndex()]);
  44.         column.setIdentifier(metaData.getName());
  45.         column.setHeaderValue(metaData.getLabel());
  46.         if (metaData.getElementClass() == String.class) {
  47.             if (metaData.getDisplayWidth() > 0) {
  48.                 StringBuffer buf = new StringBuffer(metaData.getDisplayWidth());
  49.                 for (int i = 0; i < metaData.getDisplayWidth(); i++) {
  50.                     buf.append("r");
  51.                 }
  52.                 column.setPrototypeValue(buf.toString());
  53.             }
  54.         } else if (metaData.getElementClass() == Number.class) {
  55.             if (metaData.getDisplayWidth() > 0) {
  56.                 StringBuffer buf = new StringBuffer(metaData.getDisplayWidth());
  57.                 for (int i = 0; i < metaData.getDisplayWidth(); i++) {
  58.                     buf.append("1");
  59.                 }
  60.                 column.setPrototypeValue(buf.toString());
  61.                 
  62.             }
  63.             
  64.         }
  65.     }
  66. }