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

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.adapter;
  21. import javax.swing.AbstractListModel;
  22. import org.jdesktop.binding.TabularDataModel;
  23. import org.jdesktop.binding.TabularValueChangeEvent;
  24. import org.jdesktop.binding.TabularValueChangeListener;
  25. public class DataModelToListModelAdapter extends AbstractListModel {
  26.     TabularDataModel tabModel = null;
  27.     String fieldName;
  28.     public DataModelToListModelAdapter(TabularDataModel model, String fieldName) {
  29.         this.tabModel = model;
  30.         this.fieldName = fieldName;
  31.         installDataModelListener();
  32.     }
  33.     
  34. protected void installDataModelListener() {
  35. TabularValueChangeListener l = new TabularValueChangeListener() {
  36.             public void tabularValueChanged(TabularValueChangeEvent e) {
  37.                 fireContentsChanged(DataModelToListModelAdapter.this, 0, tabModel.getRecordCount() - 1);
  38.                 
  39.             }
  40. };
  41.         tabModel.addTabularValueChangeListener(l);
  42. }
  43. /* (non-Javadoc)
  44.  * @see javax.swing.ListModel#getSize()
  45.  */
  46. public int getSize() {
  47. return tabModel.getRecordCount();
  48. }
  49. /* (non-Javadoc)
  50.  * @see javax.swing.ListModel#getElementAt(int)
  51.  */
  52. public Object getElementAt(int index) {
  53. return tabModel.getValueAt(fieldName, index);
  54. }
  55. }