01: package org.osbl.client.wings.concern;
02:
03: import org.concern.Controller;
04: import org.concern.ControllerLookup;
05: import org.osbl.client.wings.form.ObjectForm;
06: import org.osbl.client.wings.form.NestedObjectForm;
07: import org.concern.model.Event;
08: import org.concern.model.Process;
09:
10: import java.util.*;
11:
12: public class CreateForm extends NestedObjectForm {
13: private Map<String, ObjectForm> documentForms = new HashMap<String, ObjectForm>();
14:
15: protected void setProcess(Process process) {
16: if (process == null)
17: return;
18:
19: nestedForm = documentForms.get(process.getName());
20:
21: if (nestedForm == null) {
22: Controller controller = ControllerLookup.getInstance()
23: .getController(process.getName());
24: String formClassName = findForm(controller);
25: if (formClassName == null)
26: throw new UnsupportedOperationException(
27: "There's no CreateForm defined for this Process: "
28: + process.getName());
29:
30: try {
31: Class formClass = Class.forName(formClassName);
32: nestedForm = (ObjectForm) formClass.newInstance();
33: nestedForm.getEnvironment().setDelegate(
34: nestedEnvironment);
35: } catch (Exception e) {
36: throw new RuntimeException(e);
37: }
38: documentForms.put(process.getName(), nestedForm);
39: }
40:
41: nestedForm.getEnvironment().setActive(true);
42: }
43:
44: private String findForm(Controller controller) {
45: Collection<Event> events = controller.getProcess().getEvents();
46: for (Event event : events) {
47: String formClassName = (String) event
48: .getEnvironmentEntry("formClassName");
49: if (formClassName != null)
50: return formClassName;
51: }
52: return null;
53: }
54:
55: public Object getObject() {
56: Process process = (Process) super .getObject();
57: process.set("new", nestedForm.getObject());
58: return process;
59: }
60:
61: public void setObject(Object object) {
62: super.setObject(object);
63: if (object == null)
64: return;
65:
66: nestedForm.setObject(null);
67: }
68: }
|