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