1 package org.jdesktop.swing.binding; 2 3 import javax.swing.JComponent ; 4 import javax.swing.JTable ; 5 import javax.swing.table.AbstractTableModel ; 6 import javax.swing.table.TableModel ; 7 import org.jdesktop.swing.data.DataModel; 8 import org.jdesktop.swing.data.DataModelToTableModelAdapter; 9 import org.jdesktop.swing.data.MetaData; 10 import org.jdesktop.swing.data.SelectionModel; 11 import org.jdesktop.swing.data.TabularDataModel; 12 import org.jdesktop.swing.data.ValueChangeEvent; 13 import org.jdesktop.swing.data.ValueChangeListener; 14 15 21 public class DirectTableBinding extends AbstractBinding { 22 private JTable table; 23 24 28 public DirectTableBinding(JTable component, TabularDataModel dataModel) { 29 this(component, dataModel, null); 30 } 35 36 public DirectTableBinding(JTable component, TabularDataModel dataModel, String [] fieldNames) { 37 this(component, dataModel, fieldNames, null); 42 } 43 44 public DirectTableBinding(JTable component, TabularDataModel dataModel, 45 String [] fieldNames, SelectionModel selectionModel) { 46 super(component, dataModel, "", DirectTableBinding.AUTO_VALIDATE_NONE); 47 TableModel tm = createAdapter(dataModel, fieldNames); 49 table.setModel(tm); 50 if (selectionModel != null) { 51 new ListSelectionBinding(selectionModel, table.getSelectionModel()); 52 } 53 } 54 55 public boolean push() { 56 return true; 57 } 58 59 public boolean pull() { 60 return true; 61 } 62 63 public boolean isValid() { 64 return true; 65 } 66 67 protected TableModel createAdapter(TabularDataModel tabularDataModel, String [] fieldNames) { 68 return new DataModelToTableModelAdapter(tabularDataModel, fieldNames); 69 } 70 73 protected JComponent getBoundComponent() { 74 return table; 75 } 76 77 80 protected void setBoundComponent(JComponent component) { 81 if (!(component instanceof JTable )) { 82 throw new IllegalArgumentException ("TableBindings only accept a JTable or one of its child classes"); 83 } 84 this.table = (JTable )component; 85 } 86 87 90 protected Object getComponentValue() { 91 return null; 93 } 94 95 98 protected void setComponentValue(Object value) { 99 } 101 102 105 175 178 public JComponent getComponent() { 179 return getBoundComponent(); 180 } 181 182 185 public void setComponent(JComponent component) { 186 setBoundComponent(component); 187 } 188 189 } 190 | Popular Tags |