001: package org.osbl.client.wings.concern;
002:
003: import org.concern.*;
004: import org.osbl.client.action.*;
005: import org.osbl.client.wings.form.*;
006: import org.osbl.client.wings.*;
007: import org.osbl.client.wings.shell.Client;
008: import org.osbl.client.wings.shell.Environment;
009: import org.osbl.ObjectLocator;
010: import org.concern.controller.LoaderFactory;
011: import org.conform.hibernate.HibernateEnvironment;
012: import org.concern.model.Process;
013: import org.wings.session.SessionManager;
014:
015: import javax.swing.*;
016: import java.awt.event.ActionEvent;
017: import java.util.*;
018:
019: public class ProcessEditor extends GenericObjectEditor {
020: CreateEventAction createEventAction = new ProcessEditor.CreateEventAction(
021: base());
022: CancelCreateAction cancelCreateAction = new ProcessEditor.CancelCreateAction(
023: base());
024:
025: protected void initializeEditor() {
026: editAction = new CreateAction(base());
027: }
028:
029: protected ObjectForm initializeForm() {
030: return new CreateForm();
031: }
032:
033: protected void formControls(Environment environment) {
034: environment.addControl(new XButton(createEventAction));
035: environment.addControl(new XButton(cancelCreateAction));
036: }
037:
038: protected void listControls(Environment environment) {
039: }
040:
041: protected ObjectList initializeList() {
042: final ProcessList list = new ProcessList();
043: list.setLinkAction("name", new AbstractObjectAction() {
044: public void actionPerformed(ObjectActionEvent e) {
045: Object object = e.getTargets()[0];
046: list.setCurrent(object);
047: setObject(object);
048:
049: if (editAction.isEnabled())
050: editAction.actionPerformed(new ActionEvent(
051: ProcessEditor.this , 0, "edit"));
052: }
053: });
054: return list;
055: }
056:
057: public Class getType() {
058: return Process.class;
059: }
060:
061: public void showForm() {
062: ((CreateForm) getForm()).setProcess((Process) getObject());
063: super .showForm();
064: }
065:
066: public void saveObject(Object object) {
067: Process process = (Process) getObject();
068: Controller controller = ControllerLookup.getInstance()
069: .getController(process.getName());
070: Loader loader = new LoaderFactory().getLoader(controller);
071: if (loader instanceof Persister) {
072: Persister persister = (Persister) loader;
073: persister.save(process.get("new"));
074: }
075: }
076:
077: public void deleteObject(Object object) {
078: }
079:
080: public void revertObject(Object object) {
081: }
082:
083: protected boolean create() {
084: if (!objectForm.hasValidationIssues()) {
085: saveObject(objectForm.getObject());
086: return true;
087: } else
088: return false;
089: }
090:
091: protected class CreateAction extends EditAction {
092: public CreateAction(String base) {
093: super (base);
094: }
095:
096: public void actionPerformed(ActionEvent e) {
097: showForm();
098: previousAction.setEnabled(objectList.hasPrevious());
099: nextAction.setEnabled(objectList.hasNext());
100: }
101: }
102:
103: protected class CreateEventAction extends AbstractAction {
104: public CreateEventAction(String base) {
105: putValue(Action.ACTION_COMMAND_KEY, base
106: + ".buttons.create");
107: putValue(AuthorizedAction.PERMISSION_KEY, base + "[w]");
108: }
109:
110: public void actionPerformed(ActionEvent event) {
111: Process process = (Process) getObject();
112: Controller controller = ControllerLookup.getInstance()
113: .getController(process.getName());
114: boolean success = false;
115: try {
116: HibernateEnvironment.getInstance().beginTransaction();
117:
118: if (create()) {
119: Map annotations = new HashMap();
120: annotations.put("user", SessionManager.getSession()
121: .getServletRequest().getUserPrincipal()
122: .getName());
123:
124: Loader loader = new LoaderFactory()
125: .getLoader(controller);
126: Object subject = process.get("new");
127: String id = loader.idOf(subject);
128:
129: controller.createSubject(id);
130: controller.announceSubject(id);
131: success = true;
132: }
133: } catch (Exception e) {
134: e.printStackTrace();
135: } finally {
136: HibernateEnvironment.getInstance().endTransaction();
137: }
138:
139: if (success)
140: showList();
141: }
142: }
143:
144: protected class CancelCreateAction extends AbstractAction {
145: public CancelCreateAction(String base) {
146: putValue(Action.ACTION_COMMAND_KEY, base
147: + ".buttons.cancel");
148: }
149:
150: public void actionPerformed(ActionEvent event) {
151: showList();
152: }
153:
154: public void setEnabled(boolean newValue) {
155: }
156: }
157: }
|