KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > swing > data > DataModelToListModelAdapter


1 /*
2  * Created on 28.02.2005
3  *
4  */

5 package org.jdesktop.swing.data;
6
7 import javax.swing.AbstractListModel JavaDoc;
8
9
10
11 public class DataModelToListModelAdapter extends AbstractListModel JavaDoc {
12     TabularDataModel tabModel = null;
13     String JavaDoc fieldName;
14
15     public DataModelToListModelAdapter(TabularDataModel model, String JavaDoc 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     /* (non-Javadoc)
33      * @see javax.swing.ListModel#getSize()
34      */

35     public int getSize() {
36         return tabModel.getRecordCount();
37     }
38
39     /* (non-Javadoc)
40      * @see javax.swing.ListModel#getElementAt(int)
41      */

42     public Object JavaDoc getElementAt(int index) {
43         return tabModel.getValueAt(fieldName, index);
44     }
45     
46 }
Popular Tags