01: package org.osbl.riskmanagement.gui;
02:
03: import org.conform.wings.Editor;
04: import org.conform.wings.PropertyAdapter;
05: import org.conform.wings.editor.*;
06: import org.conform.*;
07: import org.conform.format.Format;
08: import org.conform.format.FormatFactory;
09: import org.wings.*;
10:
11: import java.util.Map;
12:
13: public class EnumerationAsIconsEditor implements Editor {
14: public static final String ICONS = "editor.enumeration.icons";
15:
16: public SComponent createComponent(PropertyMeta propertyMeta) {
17: PropertyDataLabel propertyDataLabel = new PropertyDataLabel(
18: propertyMeta);
19: propertyDataLabel.setPreferredSize(SDimension.AUTOAREA);
20: configureComponent(propertyMeta, propertyDataLabel, false);
21: return propertyDataLabel;
22: }
23:
24: public void configureComponent(PropertyMeta propertyMeta,
25: SComponent component, boolean erroneous) {
26: PropertyDataLabel propertyDataLabel = (PropertyDataLabel) component;
27: propertyDataLabel.setVisible(propertyMeta.isReadable());
28: propertyDataLabel.setEnabled(propertyMeta.isWritable());
29: DefaultEditorStyles.applyEditorAlignment(propertyMeta,
30: component);
31: component.setStyle("formlabel_normal");
32: }
33:
34: public void setPropertyData(SComponent component,
35: PropertyData propertyData) {
36: BeanData beanData = propertyData.getBeanData();
37: if (beanData != null)
38: beanData.addPropertyChangeListener(propertyData
39: .getPropertyMeta().getName(),
40: new ComponentInvalidator(component));
41: ((PropertyDataLabel) component).setPropertyData(propertyData);
42: }
43:
44: public PropertyData getPropertyData(SComponent component) {
45: return ((PropertyDataLabel) component).getPropertyData();
46: }
47:
48: static class PropertyDataLabel extends SLabel implements
49: PropertyAdapter {
50: private PropertyData propertyData;
51: private PropertyMeta propertyMeta;
52: private Map<Object, SIcon> icons;
53:
54: public PropertyDataLabel(PropertyMeta propertyMeta) {
55: this .propertyMeta = propertyMeta;
56: this .icons = (Map<Object, SIcon>) propertyMeta
57: .getAttribute(ICONS);
58: }
59:
60: public void setPropertyData(PropertyData propertyData) {
61: this .propertyData = propertyData;
62: }
63:
64: public PropertyData getPropertyData() {
65: return propertyData;
66: }
67:
68: public SIcon getIcon() {
69: Object value = propertyData.getValue();
70: return icons.get(value);
71: }
72:
73: public SIcon getDisabledIcon() {
74: Object value = propertyData.getValue();
75: return icons.get(value);
76: }
77:
78: public String getText() {
79: Object value = propertyData.getValue();
80: if (value == null)
81: return null;
82:
83: Format format = propertyMeta.getFormat();
84: if (format == null)
85: format = FormatFactory.NO_FORMAT;
86:
87: return format.format(value);
88: }
89: }
90: }
|