1 5 package org.jdesktop.swing.data; 6 7 import javax.swing.AbstractListModel ; 8 9 10 11 public class DataModelToListModelAdapter extends AbstractListModel { 12 TabularDataModel tabModel = null; 13 String fieldName; 14 15 public DataModelToListModelAdapter(TabularDataModel model, String fieldName) { 16 this.tabModel = model; 17 this.fieldName = fieldName; 18 installDataModelListener(); 19 } 20 21 protected void installDataModelListener() { 22 TabularValueChangeListener l = new TabularValueChangeListener() { 23 24 public void tabularValueChanged(TabularValueChangeEvent e) { 25 fireContentsChanged(DataModelToListModelAdapter.this, 0, tabModel.getRecordCount() - 1); 26 27 } 28 }; 29 tabModel.addTabularValueChangeListener(l); 30 } 31 32 35 public int getSize() { 36 return tabModel.getRecordCount(); 37 } 38 39 42 public Object getElementAt(int index) { 43 return tabModel.getValueAt(fieldName, index); 44 } 45 46 } | Popular Tags |