001: package org.osbl.orga.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.orga.model.*;
007: import org.osbl.ServiceProvider;
008: import org.osbl.persistence.*;
009: import org.conform.*;
010: import org.conform.modifier.InlineModifier;
011:
012: import java.util.*;
013:
014: public class MemberShipForm extends GenericObjectForm implements
015: HierarchicalContextAware {
016: private GenericObjectTreeNode node;
017:
018: private AbstractDynamicDomainProvider membersDomain = new AbstractDynamicDomainProvider(
019: "identity") {
020: protected List createValues() {
021: Persistence persistence = (Persistence) ServiceProvider
022: .getInstance().getService("OrgaPersistence");
023: SimpleQueryCommand queryCommand = (SimpleQueryCommand) persistence
024: .createCommand("list");
025: queryCommand.setType(Member.class);
026: Organisation organisation = (Organisation) context
027: .getObject("organisation");
028: queryCommand.addFilter("organisation", Operator.EQUAL,
029: organisation);
030: List list = queryCommand.execute();
031: list.add(0, null);
032: return list;
033: }
034: };
035:
036: private AbstractDynamicDomainProvider rolesDomain = new AbstractDynamicDomainProvider(
037: "roles") {
038: protected List createValues() {
039: Organisation organisation = (Organisation) context
040: .getObject("organisation");
041: List<String> strings = new ArrayList(
042: organisation != null ? organisation.getRoles()
043: : Collections.EMPTY_LIST);
044: strings.add(0, null);
045: return strings;
046: }
047: };
048:
049: @Override
050: protected Object getObject(String path) {
051: if (ComponentProvider.ROOT.equals(path))
052: return object;
053:
054: return null;
055: }
056:
057: @Override
058: protected void setObject(String path, Object object) {
059: if (ComponentProvider.ROOT.equals(path))
060: this .object = object;
061: }
062:
063: public void setContext(ObjectContext context) {
064: super .setContext(context);
065: membersDomain.refresh();
066: rolesDomain.refresh();
067: }
068:
069: @Override
070: protected Instruction createLayoutInstruction() {
071: return new Page(Membership.class.getName(), new Division(
072: Membership.class.getName(), new Column(
073: new LabelAndEditor(ComponentProvider.ROOT,
074: "role")), new Column(
075: new LabelAndEditor(ComponentProvider.ROOT,
076: "member"))));
077: }
078:
079: @Override
080: protected BeanMeta createBeanMeta(String path) {
081: return new VariationBeanMetaProvider(Client.getInstance()
082: .getBeanMetaProvider()).addModifier(
083: new InlineModifier() {
084: protected void configure() {
085: property("role").setDomainProvider(rolesDomain);
086: property("member").setDomainProvider(
087: membersDomain);
088: property("member").setFormat(
089: Client.getInstance()
090: .getBeanMetaProvider()
091: .getBeanMeta(Member.class)
092: .getFormat());
093: //property("member").setAttribute(org.conform.wings.Editor.CUSTOM_EDITOR, new ManyToOneAssociationEditor());
094: //property("member").setAttribute("objectEditor", new IdentityEditor());
095: property("group").setApplicable(false);
096: }
097: }).getBeanMeta(Membership.class);
098: }
099:
100: public void setNode(GenericObjectTreeNode node) {
101: this.node = node;
102: }
103: }
|