001: package org.osbl.domain.gui;
002:
003: import org.conform.*;
004: import org.conform.modifier.*;
005: import org.osbl.client.wings.form.*;
006: import org.osbl.client.wings.form.format.LocalizationFormat;
007: import org.osbl.client.wings.form.editor.OneToManyCompositionEditor;
008: import org.osbl.client.wings.form.editor.OneToManyInlineEditor;
009: import org.osbl.client.wings.form.layouter.*;
010: import org.osbl.client.wings.shell.Client;
011: import org.osbl.domain.model.Domain;
012: import org.osbl.domain.model.DomainValue;
013: import org.wings.SComponent;
014: import org.wings.SListSelectionModel;
015: import org.wings.table.STableColumnModel;
016: import org.wingx.table.XTableColumnModel;
017:
018: import javax.swing.*;
019: import java.util.*;
020: import java.awt.event.ActionEvent;
021:
022: public class DomainForm extends GenericObjectForm {
023: protected Instruction createLayoutInstruction() {
024: return new PageSet(new Page(Domain.class.getName(),
025: new Division(Domain.class.getName(), new Column(
026: new LabelAndEditor(ComponentProvider.ROOT,
027: "key"), new LabelAndEditor(
028: ComponentProvider.ROOT, "type")),
029: new Column()), new Division(Domain.class
030: .getName()
031: + ".values", new Column(new LabelAndEditor(
032: ComponentProvider.ROOT, "values")))));
033: }
034:
035: protected Object getObject(String path) {
036: return object;
037: }
038:
039: protected void setObject(String path, Object object) {
040: this .object = object;
041: }
042:
043: protected BeanMeta createBeanMeta(String path) {
044: BeanMetaProvider metaProvider = Client.getInstance()
045: .getBeanMetaProvider();
046:
047: if (ComponentProvider.ROOT.equals(path)) {
048: VariationBeanMetaProvider provider = new VariationBeanMetaProvider(
049: metaProvider);
050: provider.addModifier(new InlineModifier() {
051: protected void configure() {
052: property("key").setFormat(new LocalizationFormat());
053: property("values").setAttribute(
054: org.conform.wings.Editor.CUSTOM_EDITOR,
055: new OneToManyInlineEditor());
056: property("values").setRelationBean(
057: getBeanMeta("values"));
058: bean().addValidator(new BeanValidator() {
059: public Object validate(Object value)
060: throws ValidationException {
061: Domain domain = (Domain) value;
062: List<DomainValue> values = domain
063: .getValues();
064: if (values == null)
065: return domain;
066:
067: for (Iterator<DomainValue> iterator = values
068: .iterator(); iterator.hasNext();) {
069: DomainValue domainValue = iterator
070: .next();
071: if (domainValue == null) {
072: iterator.remove();
073: continue;
074: }
075: if (domainValue.getName() == null
076: || domainValue.getName()
077: .length() == 0)
078: throw new ValidationException(
079: new ValidationException.Message(
080: "validation.required"));
081: if (domainValue.getValue() == null
082: || domainValue.getValue()
083: .length() == 0)
084: throw new ValidationException(
085: new ValidationException.Message(
086: "validation.required"));
087: }
088:
089: return domain;
090: }
091:
092: public String[] getAffectedPropertyNames() {
093: return new String[] { "values" };
094: }
095: });
096: }
097: });
098: return provider.getBeanMeta(Domain.class);
099: } else if ("values".equals(path)) {
100: return new VariationBeanMetaProvider(metaProvider)
101: .addModifier(new HiddenModifier()).addModifier(
102: new PropertyOrderModifier("value", "name"))
103: .addModifier(new InlineModifier() {
104: protected void configure() {
105: property("value").setReadable(true);
106: property("value").setWritable(true);
107: property("name").setReadable(true);
108: property("name").setWritable(true);
109: }
110: }).getBeanMeta(DomainValue.class);
111: }
112: throw new RuntimeException("No BeanMeta for path " + path);
113: }
114: }
|