01: package org.osbl.agent.gui;
02:
03: import org.osbl.client.wings.form.*;
04: import org.concern.*;
05: import org.concern.controller.LoaderFactory;
06: import org.conform.hibernate.HibernateEnvironment;
07:
08: import java.util.*;
09:
10: public class NestingObjectForm extends NestedObjectForm {
11: private Map<String, ObjectForm> nestedForms = new HashMap<String, ObjectForm>();
12: private Map<String, List> environments = new HashMap<String, List>();
13: private boolean edit;
14:
15: public NestingObjectForm() {
16: }
17:
18: public NestingObjectForm(boolean edit) {
19: this .edit = edit;
20: }
21:
22: public boolean isEdit() {
23: return edit;
24: }
25:
26: public void setEdit(boolean edit) {
27: this .edit = edit;
28: }
29:
30: public Subject getSubject() {
31: return (Subject) getObject();
32: }
33:
34: public void setType(Class type) {
35: if (type == null)
36: return;
37:
38: String key = type.getName();
39:
40: if (nestedForm != null)
41: nestedForm.getEnvironment().setActive(false);
42:
43: nestedForm = nestedForms.get(key);
44:
45: if (nestedForm == null) {
46: try {
47: nestedForm = (ObjectForm) type.newInstance();
48: if (nestedForm instanceof ObjectContextAware) {
49: ObjectContextAware contextAware = (ObjectContextAware) nestedForm;
50: contextAware.setContext(getContext());
51: }
52: nestedForm.getEnvironment().setDelegate(
53: nestedEnvironment);
54: } catch (Exception e) {
55: throw new RuntimeException(e);
56: }
57: nestedForms.put(key, nestedForm);
58: }
59:
60: if (nestedForm instanceof ObjectContextAware) {
61: ObjectContextAware contextAware = (ObjectContextAware) nestedForm;
62: getContext()
63: .putObject("environment", environments.get(key));
64: contextAware.setContext(getContext());
65: }
66: nestedForm.getEnvironment().setActive(true);
67: }
68:
69: public void setObject(Object object) {
70: super .setObject(object);
71:
72: if (object == null)
73: return;
74:
75: Subject subject = (Subject) object;
76:
77: try {
78: Controller controller = ControllerLookup.getInstance()
79: .getController(subject.getProcess());
80: HibernateEnvironment.getInstance().beginTransaction();
81: org.concern.controller.Loader loader = new LoaderFactory()
82: .getLoader(controller);
83: subject.setSubject(loader.load(subject.getSubjectId()));
84: nestedForm.setObject(subject.getSubject());
85: } catch (Exception e) {
86: throw new RuntimeException(e);
87: } finally {
88: HibernateEnvironment.getInstance().endTransaction();
89: }
90: }
91: }
|