1 7 package org.jdesktop.dataset.adapter; 8 9 import javax.swing.JFrame ; 10 import javax.swing.table.TableModel ; 11 12 import org.jdesktop.dataset.DataSet; 13 import org.jdesktop.dataset.DataTable; 14 import org.jdesktop.swing.InteractiveTestCase; 15 import org.jdesktop.swing.JXTable; 16 import org.jdesktop.swing.binding.BindException; 17 import org.jdesktop.swing.data.DataModel; 18 import org.jdesktop.swing.data.DataModelToTableModelAdapter; 19 import org.jdesktop.swing.data.DefaultDataModel; 20 import org.jdesktop.swing.data.MetaData; 21 import org.jdesktop.swing.data.TabularDataModel; 22 import org.jdesktop.swing.data.TabularMetaData; 23 import org.jdesktop.swing.form.JForm; 24 import org.jdesktop.swing.util.DataSetTestSupport; 25 26 32 public class InteractiveTabularDataModelAdapterTest extends InteractiveTestCase { 33 34 protected MetaData[] metaDataArray; 35 TabularDataModelAdapter sharedAdaptee; 36 37 public InteractiveTabularDataModelAdapterTest() { 38 super("TabularDataModel"); 39 } 40 41 public void testDummy() { 42 } 44 45 46 47 protected JForm createForm(DefaultDataModel model) { 48 try { 49 return new JForm(model); 50 } catch (BindException e) { 51 e.printStackTrace(); 53 } 54 return null; 55 } 56 57 61 public void interactiveTestShowAdapter() { 62 TabularDataModel adaptee = createFilledDataModel(); 63 TableModel adapter = new DataModelToTableModelAdapter(adaptee); 64 JXTable table = new JXTable(adapter); 65 JFrame frame = wrapWithScrollingInFrame(table, "adapting all columns of a DataTable"); 66 frame.setVisible(true); 67 68 } 69 70 74 public void interactiveTestShowSubSetAdapter() { 75 TabularDataModel adaptee = createFilledDataModel(); 76 String [] fieldNames = adaptee.getFieldNames(); 77 78 TableModel adapter = new DataModelToTableModelAdapter(adaptee, 79 new String []{fieldNames[0], fieldNames[1]} ); 80 JXTable table = new JXTable(adapter); 81 JFrame frame = wrapWithScrollingInFrame(table, "adapting a subset of columns"); 82 frame.setVisible(true); 83 84 } 85 86 90 public void interactiveTestShowMultipleViews1() { 91 TableModel adapter = new DataModelToTableModelAdapter(sharedAdaptee); 92 JXTable table = new JXTable(adapter); 93 JFrame frame = wrapWithScrollingInFrame(table, "one view on top of shared DataTable "); 94 frame.setVisible(true); 95 96 } 97 98 102 public void interactiveTestShowMultipleViews2() { 103 TableModel adapter = new DataModelToTableModelAdapter(sharedAdaptee); 104 JXTable table = new JXTable(adapter); 105 JFrame frame = wrapWithScrollingInFrame(table, "another view on top of shared DataTable"); 106 frame.setVisible(true); 107 108 } 109 110 protected TabularDataModel createFilledDataModel() { 111 return DataSetTestSupport.createDefaultFilledTabularDataModel(3); 112 } 113 114 protected void setUp() throws Exception { 115 super.setUp(); 116 metaDataArray = DataSetTestSupport.createDefaultMetaData(); 117 sharedAdaptee = (TabularDataModelAdapter) createFilledDataModel(); 118 } 119 120 public static void main(String [] args) throws Exception { 121 InteractiveTabularDataModelAdapterTest test = new InteractiveTabularDataModelAdapterTest(); 122 test.runInteractiveTests(); 123 124 } 125 126 } 127 | Popular Tags |