01: package org.osbl.client.wings.concern;
02:
03: import org.concern.*;
04: import org.concern.model.*;
05: import org.osbl.client.wings.form.*;
06: import org.wings.session.SessionManager;
07:
08: import java.util.*;
09: import java.sql.Timestamp;
10:
11: public class OptionForm extends NestedObjectForm {
12: private Map<String, ObjectForm> documentForms = new HashMap<String, ObjectForm>();
13: private Map<String, List> environments = new HashMap<String, List>();
14:
15: public Work getOption() {
16: return (Work) getObject();
17: }
18:
19: protected void setOption(Work option) {
20: if (option == null)
21: return;
22:
23: String key = option.getProcess() + "|" + option.getActivity();
24:
25: if (nestedForm != null)
26: nestedForm.getEnvironment().setActive(false);
27:
28: nestedForm = documentForms.get(key);
29:
30: if (nestedForm == null) {
31: Controller controller = ControllerLookup.getInstance()
32: .getController(option.getProcess());
33: org.concern.model.Process process = controller.getProcess();
34: Activity activity = process.getActivity(option
35: .getActivity());
36: String formClassName = (String) activity
37: .getEnvironmentEntry("formClassName");
38: if (formClassName == null)
39: throw new UnsupportedOperationException(
40: "There's no OptionForm defined for this Option: "
41: + key);
42: try {
43: Class formClass = Class.forName(formClassName);
44: nestedForm = (ObjectForm) formClass.newInstance();
45: if (nestedForm instanceof ObjectContextAware) {
46: ObjectContextAware contextAware = (ObjectContextAware) nestedForm;
47: getContext().putObject("environment",
48: activity.getEnvironment());
49: getContext().putObject("process.environment",
50: process.getEnvironment());
51: contextAware.setContext(getContext());
52: }
53: nestedForm.getEnvironment().setDelegate(
54: nestedEnvironment);
55: } catch (Exception e) {
56: throw new RuntimeException(e);
57: }
58: documentForms.put(key, nestedForm);
59: environments.put(key, activity.getEnvironment());
60: }
61:
62: if (nestedForm instanceof ObjectContextAware) {
63: ObjectContextAware contextAware = (ObjectContextAware) nestedForm;
64: getContext()
65: .putObject("environment", environments.get(key));
66: contextAware.setContext(getContext());
67: }
68: nestedForm.getEnvironment().setActive(true);
69: }
70:
71: public void setObject(Object object) {
72: super .setObject(object);
73: if (object == null)
74: return;
75:
76: Work option = (Work) object;
77: setOption(option);
78: nestedForm.setObject(option.getSubject());
79: }
80: }
|