01: package com.xoetrope.builder.database;
02:
03: import com.xoetrope.carousel.builder.XFormGenerator;
04: import com.xoetrope.carousel.builder.XFormGeneratorInfo;
05: import java.awt.Point;
06: import java.util.Hashtable;
07: import javax.swing.JComponent;
08: import net.xoetrope.editor.project.XEditorProject;
09: import net.xoetrope.editor.project.pages.BindingTransferHandler;
10: import net.xoetrope.editor.project.pages.PageDesigner;
11: import net.xoetrope.xui.XPage;
12:
13: /**
14: * A form generator for database tables
15: * <p> Copyright (c) Xoetrope Ltd., 2002-2007</p>
16: * <p> License: see License.txt</p>
17: */
18: public class DatabaseFormGenerator extends XFormGenerator {
19:
20: /** Creates a new instance of DatabaseFormGenerator */
21: public DatabaseFormGenerator(XEditorProject editorProject,
22: PageDesigner pd) {
23: super (editorProject, pd);
24: }
25:
26: public boolean generatePanel(XFormGeneratorInfo genInfo,
27: JComponent sourceComponent, Point p) {
28: String tableName = genInfo.getGenerationParameter("title");
29:
30: boolean rc = super .generatePanel(genInfo, sourceComponent, p);
31:
32: rc |= setupBindings(genInfo, tableName, pageDesigner);
33:
34: return rc;
35: }
36:
37: /**
38: * Sets up the bindings of the generated forms
39: */
40: private boolean setupBindings(XFormGeneratorInfo builderInfo,
41: String prefix, PageDesigner pd) {
42: XPage page = pd.getPageResource().getPage();
43: int numFields = builderInfo.getNumFields();
44: for (int i = 0; i < numFields; i++) {
45: String fieldName = builderInfo.getFieldName(i);
46: String compName = fieldName + "Input";
47: JComponent comp = (JComponent) page.findComponent(compName);
48:
49: String bindingPath = prefix + "/" + fieldName;
50: Hashtable properties = new Hashtable();
51: properties.put("sourcePath", bindingPath);
52: properties.put("outputPath", bindingPath);
53:
54: BindingTransferHandler.setBindingProperties(comp, "Data",
55: properties, pd);
56: }
57:
58: return true;
59: }
60: }
|