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.*;
007: import org.osbl.persistence.model.Concrete;
008: import org.osbl.ServiceProvider;
009: import org.osbl.identity.model.Identity;
010: import org.osbl.inventory.model.*;
011: import org.conform.*;
012: import org.conform.modifier.InlineModifier;
013:
014: import java.beans.PropertyChangeListener;
015: import java.beans.PropertyChangeEvent;
016:
017: /**
018: * TODO: en-/disable elements by layout path or name
019: */
020: public class CostCenterSubForm extends GenericObjectSubForm {
021: Persistence persistence = (Persistence) ServiceProvider
022: .getInstance().getService("IdentityPersistence");
023: private Page costCenterPage;
024:
025: public void initializeSubForm() {
026: GenericObjectForm form = getGenericObjectForm();
027: BeanData beanData = form.getBeanData(ComponentProvider.ROOT);
028: beanData.addPropertyChangeListener("qualifications",
029: new PropertyChangeListener() {
030: public void propertyChange(PropertyChangeEvent evt) {
031: requalifyUI();
032: }
033: });
034: }
035:
036: private void requalifyUI() {
037: GenericObjectForm form = getGenericObjectForm();
038: Identity identity = (Identity) form.getObject();
039: boolean enable = identity != null
040: && identity.hasQualification("CostCenter");
041: form.setApplicability(costCenterPage, enable);
042: BeanData beanData = form.getBeanData("costCenter");
043: beanData.getBeanMeta().setApplicable(enable);
044: if (enable) {
045: form.initData(beanData);
046: boolean issuePublishingActive = form.getBeanData(
047: ComponentProvider.ROOT).isIssuePublishingActive();
048: beanData.setIssuePublishingActive(issuePublishingActive);
049: } else
050: beanData.setIssuePublishingActive(false);
051: }
052:
053: public Object getObject(String path) {
054: if (getIdentity() == null)
055: return null;
056:
057: if ("costCenter".equals(path)) {
058: Identity identity = getIdentity();
059: Concrete concrete = identity.getConcrete(CostCenter.class);
060: if (concrete == null && identity.getId() != null) {
061: GetCommand command = (GetCommand) persistence
062: .createCommand("get");
063: command.setType(CostCenter.class);
064: command.setId(identity.getId());
065: concrete = (Concrete) command.execute();
066: if (concrete != null
067: && concrete.getGeneral() != identity)
068: concrete.setGeneral(identity);
069: }
070: System.out.println("CostCenterSubForm returns " + concrete);
071: return concrete;
072: }
073:
074: return null;
075: }
076:
077: public void setObject(String path, Object object) {
078: if ("costCenter".equals(path)) {
079: System.out.println("CostCenterSubForm receives " + object);
080: ((CostCenter) object).setGeneral(getIdentity());
081: }
082: }
083:
084: public BeanMeta createBeanMeta(String path) {
085: if ("costCenter".equals(path)) {
086: final VariationBeanMetaProvider provider = new VariationBeanMetaProvider(
087: Client.getInstance().getBeanMetaProvider());
088: provider.addModifier(new InlineModifier() {
089: protected void configure() {
090: property("key").setAttribute(
091: PropertyMeta.ATTRIBUTE_CHANGE_LISTENER,
092: new PropertyChangeListener() {
093: public void propertyChange(
094: PropertyChangeEvent evt) {
095: GenericObjectForm form = getGenericObjectForm();
096: BeanData beanData = form
097: .getBeanData(ComponentProvider.ROOT);
098: PropertyMeta keyMeta = beanData
099: .getBeanMeta().getProperty(
100: "key");
101: PropertyData keyData = beanData
102: .getPropertyData(keyMeta);
103: if (beanData.getValue() != null
104: && keyData.getValue() == null)
105: keyData.setValue(evt
106: .getNewValue());
107: }
108: });
109: }
110: });
111: return provider.getBeanMeta(CostCenter.class);
112: }
113: return null;
114: }
115:
116: public void appendLayoutInstructions(Instruction mainInstruction) {
117: PageSet pageSet = (PageSet) mainInstruction;
118: costCenterPage = new Page(CostCenter.class.getName(),
119: new Division(new Column(new Title(CostCenter.class
120: .getName()), new LabelAndEditor("costCenter",
121: "key"),
122: new LabelAndEditor("costCenter", "name")),
123: new Column()));
124: pageSet.pages.add(costCenterPage);
125: }
126:
127: protected Identity getIdentity() {
128: return (Identity) getGenericObjectForm().getObject();
129: }
130: }
|