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.concern.controller.LoaderFactory;
07: import org.conform.hibernate.HibernateEnvironment;
08: import org.wings.session.SessionManager;
09:
10: import java.util.*;
11: import java.sql.Timestamp;
12:
13: public class TaskForm extends NestedObjectForm {
14: private Map<String, ObjectForm> documentForms = new HashMap<String, ObjectForm>();
15: private Map<String, List> environments = new HashMap<String, List>();
16:
17: public Work getTask() {
18: return (Work) getObject();
19: }
20:
21: public void setTask(Work task) {
22: if (task == null)
23: return;
24:
25: String key = task.getProcess() + "|" + task.getActivity();
26:
27: if (nestedForm != null)
28: nestedForm.getEnvironment().setActive(false);
29:
30: nestedForm = documentForms.get(key);
31:
32: if (nestedForm == null) {
33: Controller controller = ControllerLookup.getInstance()
34: .getController(task.getProcess());
35: org.concern.model.Process process = controller.getProcess();
36: Activity activity = process.getActivity(task.getActivity());
37: String formClassName = (String) activity
38: .getEnvironmentEntry("formClassName");
39: if (formClassName == null)
40: throw new UnsupportedOperationException(
41: "There's no TaskForm defined for this Task: "
42: + key);
43: try {
44: Class formClass = Class.forName(formClassName);
45: nestedForm = (ObjectForm) formClass.newInstance();
46: if (nestedForm instanceof ObjectContextAware) {
47: ObjectContextAware contextAware = (ObjectContextAware) nestedForm;
48: getContext().putObject("environment",
49: activity.getEnvironment());
50: getContext().putObject("process.environment",
51: process.getEnvironment());
52: contextAware.setContext(getContext());
53: }
54: nestedForm.getEnvironment().setDelegate(
55: nestedEnvironment);
56: } catch (Exception e) {
57: throw new RuntimeException(e);
58: }
59: documentForms.put(key, nestedForm);
60: environments.put(key, activity.getEnvironment());
61: }
62:
63: if (nestedForm instanceof ObjectContextAware) {
64: ObjectContextAware contextAware = (ObjectContextAware) nestedForm;
65: getContext()
66: .putObject("environment", environments.get(key));
67: contextAware.setContext(getContext());
68: }
69: nestedForm.getEnvironment().setActive(true);
70: }
71:
72: public void setObject(Object object) {
73: super .setObject(object);
74: if (object == null)
75: return;
76:
77: Work task = (Work) object;
78:
79: try {
80: Controller controller = ControllerLookup.getInstance()
81: .getController(task.getProcess());
82: HibernateEnvironment.getInstance().beginTransaction();
83: org.concern.controller.Loader loader = new LoaderFactory()
84: .getLoader(controller);
85: task.setSubject(loader.load(task.getSubjectId()));
86:
87: nestedForm.setObject(task.getSubject());
88: } catch (SubjectNotFoundException e) {
89: throw new RuntimeException(e);
90: } finally {
91: HibernateEnvironment.getInstance().endTransaction();
92: }
93: }
94:
95: private Timestamp fiveMinutes() {
96: return new Timestamp(System.currentTimeMillis() + 1000 * 60 * 5);
97: }
98: }
|