01: /* $Id: DefaultEditor.java 746 2006-11-08 13:34:23Z hengels $ */
02: package org.conform.wings.editor;
03:
04: import org.conform.*;
05: import org.conform.format.*;
06: import org.conform.wings.Editor;
07: import org.conform.wings.PropertyAdapter;
08: import org.wings.SComponent;
09: import org.wings.SLabel;
10:
11: public class DefaultEditor implements Editor {
12: public SComponent createComponent(PropertyMeta propertyMeta) {
13: PropertyDataLabel propertyDataLabel = new PropertyDataLabel(
14: propertyMeta);
15: configureComponent(propertyMeta, propertyDataLabel, false);
16: return propertyDataLabel;
17: }
18:
19: public void configureComponent(PropertyMeta propertyMeta,
20: SComponent component, boolean erroneous) {
21: PropertyDataLabel propertyDataLabel = (PropertyDataLabel) component;
22: propertyDataLabel.setVisible(propertyMeta.isReadable());
23: propertyDataLabel.setEnabled(propertyMeta.isWritable());
24: DefaultEditorStyles.applyEditorAlignment(propertyMeta,
25: component);
26: DefaultEditorStyles.applyEditorState(propertyMeta, component,
27: erroneous);
28: }
29:
30: public void setPropertyData(SComponent component,
31: PropertyData propertyData) {
32: BeanData beanData = propertyData.getBeanData();
33: if (beanData != null)
34: beanData.addPropertyChangeListener(propertyData
35: .getPropertyMeta().getName(),
36: new ComponentInvalidator(component));
37: ((PropertyDataLabel) component).setPropertyData(propertyData);
38: }
39:
40: public PropertyData getPropertyData(SComponent component) {
41: return ((PropertyDataLabel) component).getPropertyData();
42: }
43:
44: static class PropertyDataLabel extends SLabel implements
45: PropertyAdapter {
46: private PropertyData propertyData;
47: private PropertyMeta propertyMeta;
48:
49: public PropertyDataLabel(PropertyMeta propertyMeta) {
50: this .propertyMeta = propertyMeta;
51: }
52:
53: public void setPropertyData(PropertyData propertyData) {
54: this .propertyData = propertyData;
55: }
56:
57: public PropertyData getPropertyData() {
58: return propertyData;
59: }
60:
61: public void setText(String string) {
62: }
63:
64: public String getText() {
65: Object value = propertyData.getValue();
66: if (value == null)
67: return " ";
68:
69: Format format = propertyMeta.getFormat();
70: if (format == null)
71: format = FormatFactory.NO_FORMAT;
72:
73: return format.format(value);
74: }
75: }
76: }
|