001: package org.osbl.inventory.gui;
002:
003: import org.osbl.client.wings.form.*;
004: import org.osbl.client.wings.form.editor.ManyToOneAssociationEditor;
005: import org.osbl.client.wings.form.layouter.*;
006: import org.osbl.client.wings.shell.Client;
007: import org.osbl.persistence.*;
008: import org.osbl.persistence.model.Concrete;
009: import org.osbl.ServiceProvider;
010: import org.osbl.inventory.model.Employee;
011: import org.osbl.inventory.model.Location;
012: import org.osbl.identity.model.*;
013: import org.conform.*;
014: import org.conform.modifier.InlineModifier;
015:
016: import java.beans.PropertyChangeListener;
017: import java.beans.PropertyChangeEvent;
018: import java.util.List;
019:
020: /**
021: * TODO: en-/disable elements by layout path or name
022: */
023: public class EmployeeSubForm extends GenericObjectSubForm {
024: Persistence persistence = (Persistence) ServiceProvider
025: .getInstance().getService("IdentityPersistence");
026: private Page employeePage;
027:
028: private AbstractDynamicDomainProvider locationDomain = new AbstractDynamicDomainProvider(
029: "location") {
030: protected List createValues() {
031: Persistence persistence = (Persistence) ServiceProvider
032: .getInstance().getService("LocationPersistence");
033: SimpleQueryCommand queryCommand = (SimpleQueryCommand) persistence
034: .createCommand("list");
035: queryCommand.setType(Location.class);
036: List<Location> locations = (List<Location>) queryCommand
037: .execute();
038: locations.add(0, null);
039: return locations;
040: }
041: };
042:
043: public void initializeSubForm() {
044: GenericObjectForm form = getGenericObjectForm();
045: BeanData beanData = form.getBeanData(ComponentProvider.ROOT);
046: beanData.addPropertyChangeListener("qualifications",
047: new PropertyChangeListener() {
048: public void propertyChange(PropertyChangeEvent evt) {
049: requalifyUI();
050: }
051: });
052: }
053:
054: private void requalifyUI() {
055: GenericObjectForm form = getGenericObjectForm();
056: Identity identity = (Identity) form.getObject();
057: boolean enable = identity != null
058: && identity.hasQualification("Employee");
059: form.setApplicability(employeePage, enable);
060: BeanData beanData = form.getBeanData("employee");
061: beanData.getBeanMeta().setApplicable(enable);
062: if (enable) {
063: form.initData(beanData);
064: boolean issuePublishingActive = form.getBeanData(
065: ComponentProvider.ROOT).isIssuePublishingActive();
066: beanData.setIssuePublishingActive(issuePublishingActive);
067: } else
068: beanData.setIssuePublishingActive(false);
069: }
070:
071: public Object getObject(String path) {
072: if (getIdentity() == null)
073: return null;
074:
075: if ("employee".equals(path)) {
076: Identity identity = getIdentity();
077: Concrete concrete = identity.getConcrete(Employee.class);
078: if (concrete == null && identity.getId() != null) {
079: GetCommand command = (GetCommand) persistence
080: .createCommand("get");
081: command.setType(Employee.class);
082: command.setId(identity.getId());
083: concrete = (Concrete) command.execute();
084: if (concrete != null
085: && concrete.getGeneral() != identity)
086: concrete.setGeneral(identity);
087: }
088: System.out.println("EmployeeSubForm returns " + concrete);
089: return concrete;
090: }
091:
092: return null;
093: }
094:
095: public void setObject(String path, Object object) {
096: if ("employee".equals(path)) {
097: System.out.println("EmployeeSubForm receives " + object);
098: ((Employee) object).setGeneral(getIdentity());
099: }
100: }
101:
102: public BeanMeta createBeanMeta(String path) {
103: if ("employee".equals(path)) {
104: final VariationBeanMetaProvider provider = new VariationBeanMetaProvider(
105: Client.getInstance().getBeanMetaProvider());
106: provider.addModifier(new InlineModifier() {
107: protected void configure() {
108: property("location").setDomainProvider(
109: locationDomain);
110: property("location").setFormat(
111: Client.getInstance().getBeanMetaProvider()
112: .getBeanMeta(Location.class)
113: .getFormat());
114: property("location").setAttribute(
115: org.conform.wings.Editor.CUSTOM_EDITOR,
116: new ManyToOneAssociationEditor());
117: property("location").setAttribute("objectEditor",
118: new LocationEditor());
119: }
120: });
121: return provider.getBeanMeta(Employee.class);
122: }
123: return null;
124: }
125:
126: public void appendLayoutInstructions(Instruction mainInstruction) {
127: PageSet pageSet = (PageSet) mainInstruction;
128: employeePage = new Page(Employee.class.getName(), new Division(
129: new Column(new Title(Employee.class.getName()),
130: new LabelAndEditor("employee", "location")),
131: new Column()));
132: pageSet.pages.add(employeePage);
133: }
134:
135: protected Identity getIdentity() {
136: return (Identity) getGenericObjectForm().getObject();
137: }
138: }
|