01: package org.osbl.client.wings.form;
02:
03: import org.osbl.client.wings.form.GenericObjectForm;
04: import org.osbl.client.wings.form.layouter.*;
05: import org.conform.*;
06: import org.wings.SComponent;
07:
08: import java.util.List;
09: import java.util.ArrayList;
10:
11: public abstract class ExtendableGenericObjectForm extends
12: GenericObjectForm {
13: protected List<GenericObjectSubForm> subForms = new ArrayList<GenericObjectSubForm>();
14:
15: protected void addSubForm(GenericObjectSubForm subForm) {
16: subForms.add(subForm);
17: subForm.setObjectForm(this );
18: }
19:
20: protected void initializeForm() {
21: for (GenericObjectSubForm subForm : subForms) {
22: subForm.initializeSubForm();
23: }
24: }
25:
26: public void setObject(Object object) {
27: System.out.println("setObject " + object);
28: deactivateValidation();
29: clearDatas();
30:
31: this .object = object;
32:
33: BeanData data = datas.get(ComponentProvider.ROOT);
34: if (object == null) {
35: System.out.println("initialize ROOT " + data);
36: this .object = data.createInstance();
37: data.setValue(this .object);
38: data.initialize();
39: } else {
40: data.setValue(this .object);
41: }
42:
43: for (GenericObjectSubForm subForm : subForms) {
44: subForm.setObject(this .object);
45: }
46:
47: if (layouter != null)
48: visibilityChanged(layouter.getVisibles());
49:
50: focus();
51:
52: environment.setTitle(getBeanMeta(ComponentProvider.ROOT)
53: .getType().getName()
54: + ".editor.title", titleArguments());
55:
56: clearChanges();
57: }
58:
59: protected Object getObject(String path) {
60: for (GenericObjectSubForm subForm : subForms) {
61: Object object = subForm.getObject(path);
62: if (object != null)
63: return object;
64: }
65: return null;
66: }
67:
68: protected void setObject(String path, Object object) {
69: for (GenericObjectSubForm subForm : subForms) {
70: subForm.setObject(path, object);
71: }
72: }
73:
74: protected BeanMeta createBeanMeta(String path) {
75: for (GenericObjectSubForm subForm : subForms) {
76: BeanMeta beanMeta = subForm.createBeanMeta(path);
77: if (beanMeta != null)
78: return beanMeta;
79: }
80: return null;
81: }
82:
83: protected SComponent createCustomComponent(String key) {
84: for (GenericObjectSubForm subForm : subForms) {
85: SComponent component = subForm.createCustomComponent(key);
86: if (component != null)
87: return component;
88: }
89: return super .createCustomComponent(key);
90: }
91:
92: protected Layouter initLayout(Instruction mainInstruction) {
93: for (GenericObjectSubForm subForm : subForms) {
94: subForm.appendLayoutInstructions(mainInstruction);
95: }
96: return super.initLayout(mainInstruction);
97: }
98: }
|