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

xml/soap/webservice

开发平台:

Java

  1. /*
  2.  * $Id: SelectionInListMetaData.java,v 1.3 2005/10/10 17:01:08 rbair Exp $
  3.  *
  4.  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
  5.  * Santa Clara, California 95054, U.S.A. All rights reserved.
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  * 
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  * 
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  20.  */
  21. package org.jdesktop.binding.metadata;
  22. import org.jdesktop.binding.TabularDataModel;
  23. /**
  24.  * MetaData for declaring binding a ComboBox to
  25.  * dynamic drop-down data.
  26.  * 
  27.  * NOTE: this is experimental. 
  28.  * 
  29.  * @author Jeanette Winzenburg
  30.  */
  31. public class SelectionInListMetaData extends MetaData {
  32.     private String sourceFieldName;
  33.     private TabularDataModel sourceDataModel;
  34.     private String[] displayFieldNames;
  35.     
  36.     public SelectionInListMetaData() {
  37.         this("tabularvalue");
  38.     }
  39.     public SelectionInListMetaData(String name) {
  40.         super(name);
  41.      
  42.     }
  43.     public SelectionInListMetaData(String name, Class elementType) {
  44.         super(name, elementType);
  45.     }
  46.     
  47.     public SelectionInListMetaData(String name, String label, String sourceFieldName) {
  48.         this(name);
  49.         setLabel(label);
  50.         setSourceFieldName(sourceFieldName);
  51.     }
  52.     /**
  53.      * sets the bound column in the drop-down.<p>
  54.      * 
  55.      * @param sourceFieldName
  56.      */
  57.     public void setSourceFieldName(String sourceFieldName) {
  58.         String oldNames = getSourceFieldName();
  59.         // PENDING JW: make sure the bound field classe 
  60.         // is compatibel to the the element class
  61.         this.sourceFieldName = sourceFieldName;
  62.         firePropertyChange("sourceFieldName", oldNames, getSourceFieldName());
  63.         
  64.     }
  65.     /** 
  66.      * returns bound column in the drop-down.
  67.      * @return
  68.      */
  69.     public String getSourceFieldName() {
  70.         return sourceFieldName;
  71.     }
  72.  
  73.     /** 
  74.      * returns the model for the drop-down.
  75.      * @return
  76.      */
  77.     public TabularDataModel getSourceDataModel() {
  78.         return sourceDataModel;
  79.     }
  80.     
  81.     /**
  82.      * sets the model for the drop-down.
  83.      * @param sourceDataModel
  84.      */
  85.     public void setSourceDataModel(TabularDataModel sourceDataModel) {
  86.         TabularDataModel old = getSourceDataModel();
  87.         this.sourceDataModel = sourceDataModel;
  88.         firePropertyChange("sourceDataModel", old, getSourceDataModel());
  89.     }
  90.     
  91.     public String[] getDisplayFieldNames() {
  92.         return displayFieldNames;
  93.     }
  94.     
  95.     public void setDisplayFieldNames(String[] displayFieldNames) {
  96.         String[] old = getDisplayFieldNames();
  97.         this.displayFieldNames = displayFieldNames;
  98.         firePropertyChange("displayFieldNames", old, getDisplayFieldNames());
  99.     }
  100.     public int getBoundColumnIndex() {
  101.         if ((getSourceFieldName() == null) || getSourceDataModel() == null) return -1;
  102.         String[] fieldNames = getDisplayFieldNames();
  103.         if (fieldNames == null) {
  104.             fieldNames = getSourceDataModel().getFieldNames();
  105.         }
  106.         for (int i = 0; i < fieldNames.length; i++) {
  107.             if (getSourceFieldName().equals(fieldNames[i])) {
  108.                 return i;
  109.             }
  110.         }
  111.         return -1;
  112.     }
  113. }