001: package net.xoetrope.xui.test;
002:
003: import java.io.File;
004:
005: import java.awt.Frame;
006:
007: import junit.framework.TestCase;
008: import net.xoetrope.awt.XTable;
009: import net.xoetrope.builder.editor.helper.XTableModelHelper;
010: import net.xoetrope.data.XDataSource;
011: import net.xoetrope.debug.DebugLogger;
012: import net.xoetrope.xui.XProjectManager;
013: import net.xoetrope.xui.XResourceManager;
014: import net.xoetrope.xui.data.XBaseModel;
015: import net.xoetrope.xui.data.XModel;
016:
017: /**
018: * <p>Title: Xui</p>
019: * <p>Description: </p>
020: * <p>Copyright: Copyright (c) Xoetrope Ltd., 1998-2003</p>
021: * <p>Company: Xoetrope Ltd.</p>
022: * @author not attributable
023: * @version 1.0
024: */
025:
026: public class TestXTable extends TestCase {
027: Frame frame;
028:
029: public TestXTable() {
030: XProjectManager.getStyleManager().load("appstyles.xml");
031: }
032:
033: public void testTable() {
034: XTable table = new XTable();
035: // String[] cols = {"col 1", "col 2", "col 3"};
036: // table.addColumns( cols );
037: table.setStyle("base/TableData");
038: table.setHeaderStyle("base/TableHeading");
039: table.setSelectedStyle("base/TableSelection");
040: // table.setModel( createManualDatasource() );
041: table.setModel(createDatasource());
042: table.setInteractiveTable(true);
043: table.setSelectedRow(2);
044:
045: frame = new Frame("XTable test");
046: frame.setLayout(null);
047: frame.setSize(640, 480);
048: table.setColWidth(0, 150);
049: table.setBounds(20, 80, 400, 200);
050: table.setBackground(java.awt.Color.white);
051: frame.add(table);
052: frame.setVisible(true);
053: frame.show();
054:
055: assertTrue(table.getSelectedRow() == 2);
056: }
057:
058: public XModel createManualDatasource() {
059: XBaseModel dset = (XBaseModel) XTableModelHelper
060: .createDataSet("events");
061: XBaseModel table = (XBaseModel) XTableModelHelper.createTable(
062: dset, "items");
063: XBaseModel header = (XBaseModel) XTableModelHelper
064: .addHeader(table);
065: XTableModelHelper.addData(header, "event", "event");
066: XTableModelHelper.addData(header, "control", "control");
067: XTableModelHelper.addData(header, "value", "value");
068: XBaseModel rowdata = (XBaseModel) XTableModelHelper
069: .addRow(table);
070: XTableModelHelper.addData(rowdata, "event", "click");
071: XTableModelHelper.addData(rowdata, "Control", "btnSubmit");
072: XTableModelHelper.addData(rowdata, "Value", "Submit");
073:
074: DebugLogger.dumpModel(XProjectManager.getModel());
075:
076: return table;
077: // return (XModel)XProjectManager.getModel().get( "base/events/items", null );
078: }
079:
080: public XModel createDatasource() {
081: XProjectManager.getResourceManager();
082: XDataSource modelDataSource = new XDataSource();
083: try {
084: String fileName = "samptabledatasets.xml";
085: File source = new File(fileName);
086: if (source.exists())
087: modelDataSource.read(XResourceManager
088: .getBufferedReader(source, null));
089: else
090: modelDataSource.read(XResourceManager
091: .getBufferedReader(fileName, null));
092: } catch (Exception ex) {
093: ex.printStackTrace();
094: }
095:
096: DebugLogger.dumpModel(XProjectManager.getModel());
097:
098: XModel model = (XModel) XProjectManager.getModel().get(
099: "base/componentlist/items");
100:
101: XBaseModel trNode = new XBaseModel();
102: trNode.setTagName("tr");
103:
104: model.append(trNode);
105: XBaseModel makeNode = new XBaseModel();
106: makeNode.setTagName("td");
107: makeNode.setId("make");
108: makeNode.set("Val");
109: trNode.append(makeNode);
110:
111: XBaseModel tdNode = new XBaseModel();
112: tdNode.setTagName("td");
113: tdNode.setId("model");
114: tdNode.set("Cassidy");
115: trNode.append(tdNode);
116:
117: tdNode = new XBaseModel();
118: tdNode.setTagName("td");
119: tdNode.setId("year");
120: tdNode.set("1968");
121: trNode.append(tdNode);
122:
123: tdNode = new XBaseModel();
124: tdNode.setTagName("td");
125: tdNode.setId("price");
126: tdNode.set("23433");
127: trNode.append(tdNode);
128: // XBaseModel.getInstance().
129:
130: return model;
131:
132: /* FileInputStream fis = null;
133: InputStreamReader isr = null;
134: try {
135: fis = new FileInputStream( "c:\\cvs\\Xui\\Resource\\configres\\datasets.xml" );
136: isr = new InputStreamReader( fis );
137: }
138: catch ( Exception ex ) {
139: ex.printStackTrace();
140: }
141: XDataSource dataSource = new XDataSource();
142: dataSource.read( isr );
143:
144: XModel model = (XModel)XProjectManager.getModel().get( "componentlist/items", null );
145: return model;
146: */
147: }
148:
149: }
|