001: package org.osbl.client.wings.form;
002:
003: import org.wings.*;
004: import org.conform.BeanMeta;
005: import org.conform.BeanData;
006: import org.conform.wings.ComponentFactory;
007: import org.osbl.client.wings.shell.Client;
008:
009: import java.util.Map;
010: import java.util.HashMap;
011:
012: public abstract class AbstractComponentProvider implements
013: ComponentProvider {
014: protected Map<String, SComponent> customComponents = new HashMap<String, SComponent>();
015: protected Map<String, SComponent> components = new HashMap<String, SComponent>();
016: protected Map<String, SLabel> customLabels = new HashMap<String, SLabel>();
017: protected Map<String, SLabel> labels = new HashMap<String, SLabel>();
018:
019: public SLabel createTitle(String titleCode) {
020: return new SLabel(Client.getInstance().getResourceProvider()
021: .getMessage(titleCode));
022: }
023:
024: public SLabel getLabel(String bean, String property) {
025: String key = bean != null ? bean + "." + property : property;
026:
027: SLabel label = labels.get(key);
028: if (label == null) {
029: label = createLabel(bean, property);
030: labels.put(key, label);
031: }
032: return label;
033: }
034:
035: protected SLabel createLabel(String bean, String property) {
036: return ComponentFactory.INSTANCE.createLabel(getBeanMeta(bean),
037: property);
038: }
039:
040: public SComponent getEditorComponent(String bean, String property) {
041: String key = bean != null ? bean + "." + property : property;
042:
043: SComponent component = components.get(key);
044: if (component == null) {
045: component = createComponent(bean, property);
046: components.put(key, component);
047: }
048: return component;
049: }
050:
051: protected SComponent createComponent(String bean, String property) {
052: return ComponentFactory.INSTANCE.createComponent(
053: getBeanMeta(bean), getBeanData(bean), property);
054: }
055:
056: public SComponent getReadOnlyEditorComponent(String bean,
057: String property) {
058: String key = bean != null ? bean + "." + property : property;
059:
060: SComponent component = components.get(key);
061: if (component == null) {
062: component = createReadOnlyComponent(bean, property);
063: components.put(key, component);
064: }
065: return component;
066: }
067:
068: protected SComponent createReadOnlyComponent(String bean,
069: String property) {
070: return ComponentFactory.INSTANCE.createReadOnlyComponent(
071: getBeanMeta(bean), getBeanData(bean), property);
072: }
073:
074: public SComponent getCustomComponent(String key) {
075: SComponent component = customComponents.get(key);
076: if (component == null) {
077: component = createCustomComponent(key);
078: customComponents.put(key, component);
079: }
080: return component;
081: }
082:
083: protected SComponent createCustomComponent(String key) {
084: throw new UnsupportedOperationException(
085: "Please override this method!");
086: }
087:
088: public SLabel getCustomLabel(String key) {
089: SLabel label = customLabels.get(key);
090: if (label == null) {
091: label = createCustomLabel(key);
092: customLabels.put(key, label);
093: }
094: return label;
095: }
096:
097: protected SLabel createCustomLabel(String key) {
098: SLabel label = new SLabel(Client.getInstance()
099: .getResourceProvider().getMessage(key));
100: label.setVerticalAlignment(SConstants.TOP_ALIGN);
101: label.setStyle("formlabel_normal");
102: return label;
103: }
104:
105: protected abstract BeanMeta getBeanMeta(String path);
106:
107: protected abstract BeanData getBeanData(String path);
108: }
|