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.ServiceProvider;
006: import org.osbl.authorization.gui.ProfileEditor;
007: import org.osbl.authorization.model.Profile;
008: import org.osbl.persistence.*;
009: import org.osbl.persistence.model.Concrete;
010: import org.osbl.client.wings.form.layouter.*;
011: import org.osbl.client.wings.form.*;
012: import org.osbl.client.wings.form.editor.ManyToManyAssociationEditor;
013: import org.osbl.client.wings.shell.Client;
014: import org.conform.*;
015: import org.conform.wings.editor.StringEditor;
016: import org.conform.modifier.InlineModifier;
017:
018: import java.beans.PropertyChangeListener;
019: import java.beans.PropertyChangeEvent;
020: import java.util.List;
021: import java.util.ArrayList;
022:
023: /**
024: * TODO: en-/disable elements by layout path or name
025: */
026: public class UserSubForm extends GenericObjectSubForm {
027: Persistence persistence = (Persistence) ServiceProvider
028: .getInstance().getService("IdentityPersistence");
029: private Page userPage;
030:
031: private AbstractDynamicDomainProvider profileDomain = new AbstractDynamicDomainProvider(
032: "profiles") {
033: protected List createValues() {
034: Persistence persistence = (Persistence) ServiceProvider
035: .getInstance().getService(
036: "AuthorizationPersistence");
037: SimpleQueryCommand queryCommand = (SimpleQueryCommand) persistence
038: .createCommand("list");
039: queryCommand.setType(Profile.class);
040: return (List<Profile>) queryCommand.execute();
041: }
042: };
043:
044: public void initializeSubForm() {
045: GenericObjectForm form = getGenericObjectForm();
046: BeanData beanData = form.getBeanData(ComponentProvider.ROOT);
047: beanData.addPropertyChangeListener("qualifications",
048: new PropertyChangeListener() {
049: public void propertyChange(PropertyChangeEvent evt) {
050: requalifyUI();
051: }
052: });
053: }
054:
055: private void requalifyUI() {
056: GenericObjectForm form = getGenericObjectForm();
057: Identity identity = (Identity) form.getObject();
058: boolean enable = identity != null
059: && identity.hasQualification("User");
060: form.setApplicability(userPage, enable);
061: BeanData beanData = form.getBeanData("user");
062: beanData.getBeanMeta().setApplicable(enable);
063: if (enable) {
064: form.initData(beanData);
065: boolean issuePublishingActive = form.getBeanData(
066: ComponentProvider.ROOT).isIssuePublishingActive();
067: beanData.setIssuePublishingActive(issuePublishingActive);
068: } else
069: beanData.setIssuePublishingActive(false);
070: }
071:
072: public Object getObject(String path) {
073: if (getIdentity() == null)
074: return null;
075:
076: if ("user".equals(path)) {
077: Identity identity = getIdentity();
078: Concrete concrete = identity.getConcrete(User.class);
079: if (concrete == null && identity.getId() != null) {
080: GetCommand command = (GetCommand) persistence
081: .createCommand("get");
082: command.setType(User.class);
083: command.setId(identity.getId());
084: concrete = (Concrete) command.execute();
085: if (concrete != null
086: && concrete.getGeneral() != identity)
087: concrete.setGeneral(identity);
088: }
089: System.out.println("UserSubForm returns " + concrete);
090: return concrete;
091: }
092:
093: return null;
094: }
095:
096: public void setObject(String path, Object object) {
097: if ("user".equals(path)) {
098: System.out.println("UserSubForm receives " + object);
099: ((User) object).setGeneral(getIdentity());
100: }
101: }
102:
103: public BeanMeta createBeanMeta(String path) {
104: if ("user".equals(path)) {
105: VariationBeanMetaProvider provider = new VariationBeanMetaProvider(
106: Client.getInstance().getBeanMetaProvider());
107: provider.addModifier(new InlineModifier() {
108: protected void configure() {
109: property("password").setAttribute(
110: DefaultBeanData.PROPERTY_DATA_CLASS,
111: PasswordPropertyData.class.getName());
112: property("password").setAttribute(
113: org.conform.wings.Editor.CUSTOM_EDITOR,
114: new StringEditor());
115: property("password").setAttribute(
116: StringEditor.PASSWORD, true);
117: property("locale").setDomainProvider(
118: new AbstractDomainProvider() {
119: protected List createValues() {
120: return Client.getInstance()
121: .getResourceProvider()
122: .getSupportedLocales();
123: }
124: });
125: property("profiles").setAttribute(
126: org.conform.wings.Editor.CUSTOM_EDITOR,
127: new ManyToManyAssociationEditor());
128: property("profiles").setAttribute("objectEditor",
129: new ProfileEditor());
130: property("profiles").setDomainProvider(
131: profileDomain);
132: property("profiles")
133: .setInitializer(
134: new NewInstanceInitializer(
135: ArrayList.class));
136: }
137: });
138: return provider.getBeanMeta(User.class);
139: }
140:
141: return null;
142: }
143:
144: public void appendLayoutInstructions(Instruction mainInstruction) {
145: PageSet pageSet = (PageSet) mainInstruction;
146: userPage = new Page(User.class.getName(), new Division(
147: new Column(new Title("User"), new LabelAndEditor(
148: "user", "account"), new LabelAndEditor("user",
149: "password"), new LabelAndEditor("user",
150: "locale")), new Column()), new Division(
151: new Column(new LabelAndEditor("user", "profiles"))));
152: pageSet.pages.add(userPage);
153: }
154:
155: protected Identity getIdentity() {
156: return (Identity) getGenericObjectForm().getObject();
157: }
158: }
|