01: package com.xoetrope.xlib.data.test;
02:
03: import java.io.FileInputStream;
04: import java.io.FileNotFoundException;
05: import java.io.InputStreamReader;
06:
07: import java.awt.Frame;
08:
09: import junit.framework.TestCase;
10: import net.xoetrope.awt.XTable;
11: import net.xoetrope.optional.data.XOptionalDataSource;
12: import net.xoetrope.optional.data.sql.DatabaseTableModel;
13: import net.xoetrope.xui.data.XModel;
14:
15: /**
16: * <p>Copyright (c) Xoetrope Ltd. 2001-2004</p>
17: * $Revision: 1.2 $
18: */
19: public class TestXLibDataSource extends TestCase {
20: Frame frame;
21:
22: public TestXLibDataSource() {
23: }
24:
25: public void testTable() {
26: // XStyleManager.getInstance().load( "configurator.txt" );
27: XTable table = new XTable();
28: // String[] cols = {"col 1", "col 2", "col 3"};
29: // table.addColumns( cols );
30: // table.setStyle("base/TableData");
31: // table.setHeaderStyle("base/TableHeading");
32: createDataSource();
33: table.setModel(createDataSource());
34:
35: frame = new Frame("XTable test");
36: frame.setLayout(null);
37: frame.setSize(640, 480);
38: table.setBounds(20, 80, 600, 300);
39: table.setBackground(java.awt.Color.white);
40: frame.add(table);
41: frame.setVisible(true);
42: frame.show();
43: }
44:
45: public XModel createDataSource() {
46: FileInputStream fis = null;
47: InputStreamReader isr = null;
48: try {
49: fis = new FileInputStream(
50: "f:\\cvs\\Xui\\Resource\\configres\\datasets.xml");
51: isr = new InputStreamReader(fis);
52: } catch (Exception ex) {
53: try {
54: fis = new FileInputStream(
55: "c:\\cvs\\xlib\\resources\\xlib_datasets.xml");
56: isr = new InputStreamReader(fis);
57: } catch (FileNotFoundException ex1) {
58: isr = new InputStreamReader(fis);
59: }
60: }
61:
62: XOptionalDataSource dataSource = new XOptionalDataSource();
63: dataSource.read(isr);
64: /* End of setup */
65:
66: // XModel model = (XModel)XModel.getInstance().get( "base/FrozenGoods", null );
67: DatabaseTableModel temp = (DatabaseTableModel) ((XModel) XModel
68: .getInstance().get("Goods")).get();
69: temp.retrieve();
70: System.out.println(temp.getFieldValue(0, 1));
71: return temp;
72: }
73:
74: }
|