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