001: package org.osbl.identity.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.ServiceProvider;
007: import org.osbl.persistence.GetCommand;
008: import org.osbl.persistence.Persistence;
009: import org.osbl.persistence.model.Concrete;
010: import org.osbl.identity.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 DepartmentSubForm extends GenericObjectSubForm {
021: Persistence persistence = (Persistence) ServiceProvider
022: .getInstance().getService("IdentityPersistence");
023: private Page departmentPage;
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("Department");
041: form.setApplicability(departmentPage, enable);
042:
043: BeanData beanData = form.getBeanData("department");
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 ("department".equals(path)) {
059: Identity identity = getIdentity();
060: Concrete concrete = identity.getConcrete(Department.class);
061: if (concrete == null && identity.getId() != null) {
062: GetCommand command = (GetCommand) persistence
063: .createCommand("get");
064: command.setType(Department.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("DepartmentSubForm returns " + concrete);
072: return concrete;
073: }
074:
075: return null;
076: }
077:
078: public void setObject(String path, Object object) {
079: if ("department".equals(path)) {
080: System.out.println("DepartmentSubForm receives " + object);
081: ((Department) object).setGeneral(getIdentity());
082: }
083: }
084:
085: public BeanMeta createBeanMeta(String path) {
086: if ("department".equals(path)) {
087: VariationBeanMetaProvider provider = new VariationBeanMetaProvider(
088: Client.getInstance().getBeanMetaProvider());
089: provider.addModifier(new InlineModifier() {
090: protected void configure() {
091: property("address").setApplicable(false);
092: property("address").setWritable(false);
093: property("address").setReadable(false);
094: }
095: });
096: return provider.getBeanMeta(Department.class);
097: }
098: return null;
099: }
100:
101: public void appendLayoutInstructions(Instruction mainInstruction) {
102: PageSet pageSet = (PageSet) mainInstruction;
103: departmentPage = new Page(Department.class.getName(),
104: new Division(new Column(new Title("Department"))));
105: pageSet.pages.add(departmentPage);
106: }
107:
108: protected Identity getIdentity() {
109: return (Identity) getGenericObjectForm().getObject();
110: }
111: }
|