KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > dataset > adapter > InteractiveTabularDataModelAdapterTest


1 /*
2  * $Id: InteractiveTabularDataModelAdapterTest.java,v 1.2 2005/03/01 13:28:00 kleopatra Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7 package org.jdesktop.dataset.adapter;
8
9 import javax.swing.JFrame JavaDoc;
10 import javax.swing.table.TableModel JavaDoc;
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 /**
27  * To see a DataTable.
28  *
29  * @author Jeanette Winzenburg
30  *
31  */

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         // needed to make it pass in the automatic build
43
}
44  
45     
46
47     protected JForm createForm(DefaultDataModel model) {
48         try {
49             return new JForm(model);
50         } catch (BindException e) {
51             // TODO Auto-generated catch block
52
e.printStackTrace();
53         }
54         return null;
55     }
56
57     /**
58      * show the synthetic DataTable.
59      *
60      */

61     public void interactiveTestShowAdapter() {
62         TabularDataModel adaptee = createFilledDataModel();
63         TableModel JavaDoc adapter = new DataModelToTableModelAdapter(adaptee);
64         JXTable table = new JXTable(adapter);
65         JFrame JavaDoc frame = wrapWithScrollingInFrame(table, "adapting all columns of a DataTable");
66         frame.setVisible(true);
67
68     }
69     
70     /**
71      * show a subset of the synthetic DataTable
72      *
73      */

74     public void interactiveTestShowSubSetAdapter() {
75         TabularDataModel adaptee = createFilledDataModel();
76         String JavaDoc[] fieldNames = adaptee.getFieldNames();
77         
78         TableModel JavaDoc adapter = new DataModelToTableModelAdapter(adaptee,
79                 new String JavaDoc[]{fieldNames[0], fieldNames[1]} );
80         JXTable table = new JXTable(adapter);
81         JFrame JavaDoc frame = wrapWithScrollingInFrame(table, "adapting a subset of columns");
82         frame.setVisible(true);
83
84     }
85     
86     /**
87      * opens a JTable on the shared DataTable
88      * edits in one must show up in the other
89      */

90     public void interactiveTestShowMultipleViews1() {
91         TableModel JavaDoc adapter = new DataModelToTableModelAdapter(sharedAdaptee);
92         JXTable table = new JXTable(adapter);
93         JFrame JavaDoc frame = wrapWithScrollingInFrame(table, "one view on top of shared DataTable ");
94         frame.setVisible(true);
95        
96     }
97
98     /**
99      * opens another JTable on the shared DataTable
100      * edits in one must show up in the other.
101      */

102     public void interactiveTestShowMultipleViews2() {
103         TableModel JavaDoc adapter = new DataModelToTableModelAdapter(sharedAdaptee);
104         JXTable table = new JXTable(adapter);
105         JFrame JavaDoc 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 JavaDoc {
115         super.setUp();
116         metaDataArray = DataSetTestSupport.createDefaultMetaData();
117         sharedAdaptee = (TabularDataModelAdapter) createFilledDataModel();
118     }
119     
120     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
121         InteractiveTabularDataModelAdapterTest test = new InteractiveTabularDataModelAdapterTest();
122         test.runInteractiveTests();
123
124     }
125
126 }
127
Popular Tags