01: package com.xoetrope.builder.pojo;
02:
03: import com.xoetrope.carousel.builder.XFormGenerator;
04: import com.xoetrope.carousel.builder.XFormGeneratorInfo;
05: import java.awt.Dimension;
06: import java.awt.Point;
07: import java.util.Hashtable;
08: import javax.swing.JComponent;
09: import net.xoetrope.editor.project.XEditorProject;
10: import net.xoetrope.editor.project.pages.BindingTransferHandler;
11: import net.xoetrope.editor.project.pages.PageDesigner;
12: import net.xoetrope.xui.XPage;
13:
14: /**
15: * A form generator for POJOs, sets up the bindings of the generated
16: * components.
17: * <p> Copyright (c) Xoetrope Ltd., 2002-2007</p>
18: * <p> License: see License.txt</p>
19: */
20: public class PojoFormGenerator extends XFormGenerator {
21: /**
22: * Creates a new instance of PojoFormGenerator
23: * @param editorProject the current project
24: * @param pd page designer object
25: */
26: public PojoFormGenerator(XEditorProject editorProject,
27: PageDesigner pd) {
28: super (editorProject, pd);
29: }
30:
31: protected boolean generatePanel(XFormGeneratorInfo genInfo,
32: JComponent sourceComponent, Point p, Dimension size) {
33: boolean rc = super .generatePanel(genInfo, sourceComponent, p,
34: size);
35: rc |= setupBindings(genInfo, pageDesigner);
36: return rc;
37: }
38:
39: public boolean generatePanel(XFormGeneratorInfo genInfo,
40: JComponent sourceComponent, Point p) {
41: return generatePanel(genInfo, sourceComponent, p,
42: new Dimension());
43: }
44:
45: private boolean setupBindings(XFormGeneratorInfo builderInfo,
46: PageDesigner pd) {
47: XPage page = pd.getPageResource().getPage();
48: int numFields = builderInfo.getNumFields();
49: for (int i = 0; i < numFields; i++) {
50: String fieldName = builderInfo.getFieldName(i);
51: String compName = (fieldName + "Input");
52:
53: JComponent comp = (JComponent) page.findComponent(compName);
54: String bindingPath = (String) builderInfo.getProperty(
55: fieldName, "bindingPath");
56: if (bindingPath == null)
57: continue;
58:
59: Hashtable properties = new Hashtable();
60:
61: String outputPath = bindingPath;
62:
63: // TODO: What a List binding output path should be set to?
64: String componentType = (String) builderInfo.getProperty(
65: fieldName, "component");
66: if (!"List".equals(componentType))
67: outputPath = "/" + outputPath;
68:
69: properties.put("sourcePath", bindingPath);
70: properties.put("outputPath", outputPath);
71: properties.put("reeval", "true");
72:
73: BindingTransferHandler.setBindingProperties(comp, "Data",
74: properties, pd);
75: }
76:
77: return true;
78: }
79:
80: }
|