001: package org.osbl.orga.gui;
002:
003: import org.osbl.client.wings.form.*;
004: import org.osbl.client.wings.form.format.BusinessObjectFormat;
005: import org.osbl.client.wings.form.layouter.*;
006: import org.osbl.client.wings.shell.Client;
007: import org.osbl.identity.model.Identity;
008: import org.osbl.orga.model.*;
009: import org.osbl.persistence.*;
010: import org.osbl.ServiceProvider;
011: import org.conform.*;
012: import org.conform.wings.editor.DefaultEditor;
013: import org.conform.modifier.InlineModifier;
014:
015: import java.util.*;
016:
017: public class RelationshipForm extends GenericObjectForm {
018: private Initializer memberInitializer = new Initializer() {
019: public Object getValue() {
020: return context.getObject("member");
021: }
022: };
023:
024: private AbstractDynamicDomainProvider membersDomain = new AbstractDynamicDomainProvider(
025: "identity") {
026: protected List createValues() {
027: Persistence persistence = (Persistence) ServiceProvider
028: .getInstance().getService("OrgaPersistence");
029: SimpleQueryCommand queryCommand = (SimpleQueryCommand) persistence
030: .createCommand("list");
031: queryCommand.setType(Member.class);
032: queryCommand.addFilter("organisation", Operator.EQUAL,
033: context.getObject("organisation"));
034: List list = queryCommand.execute();
035: list.add(0, null);
036: return list;
037: }
038: };
039:
040: private AbstractDynamicDomainProvider relationsDomain = new AbstractDynamicDomainProvider(
041: "relations") {
042: protected List createValues() {
043: Organisation organisation = (Organisation) context
044: .getObject("organisation");
045: List<String> strings = new ArrayList(
046: organisation != null ? organisation.getRelations()
047: : Collections.EMPTY_LIST);
048: strings.add(0, null);
049: return strings;
050: }
051: };
052:
053: public RelationshipForm() {
054: }
055:
056: protected Instruction createLayoutInstruction() {
057: return new PageSet(new Page(Identity.class.getName(),
058: new Division(new Column(new Title(Relationship.class
059: .getName()), new LabelAndEditor(
060: ComponentProvider.ROOT, "member"),
061: new LabelAndEditor(ComponentProvider.ROOT,
062: "relation"), new LabelAndEditor(
063: ComponentProvider.ROOT, "peer")),
064: new Column())));
065: }
066:
067: protected Object getObject(String path) {
068: return object;
069: }
070:
071: protected void setObject(String path, Object object) {
072: this .object = object;
073: }
074:
075: public void setContext(ObjectContext context) {
076: super .setContext(context);
077: membersDomain.refresh();
078: relationsDomain.refresh();
079: }
080:
081: protected BeanMeta createBeanMeta(String path) {
082: VariationBeanMetaProvider provider = new VariationBeanMetaProvider(
083: Client.getInstance().getBeanMetaProvider());
084: provider.addModifier(new InlineModifier() {
085: protected void configure() {
086: property("member").setInitializer(memberInitializer);
087: property("member").setAttribute(
088: org.conform.wings.Editor.CUSTOM_EDITOR,
089: new DefaultEditor());
090: property("member")
091: .setFormat(new BusinessObjectFormat());
092: property("relation").setDomainProvider(relationsDomain);
093: property("peer").setDomainProvider(membersDomain);
094: property("peer").setFormat(
095: Client.getInstance().getBeanMetaProvider()
096: .getBeanMeta(Member.class).getFormat());
097: }
098: });
099: return provider.getBeanMeta(Relationship.class);
100: }
101: }
|