01: /* $Id: ManyToOneEditor.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.*;
07: import org.wings.*;
08:
09: public class ManyToOneEditor implements Editor {
10: public SComponent createComponent(PropertyMeta propertyMeta) {
11: SComboBox comboBox = new SComboBox();
12: comboBox
13: .setModel(new ComboBoxModelPropertyAdapter(propertyMeta));
14: Format format = propertyMeta.getFormat();
15: if (format != null)
16: comboBox.setRenderer(new FormattedListCellRenderer(format));
17: configureComponent(propertyMeta, comboBox, false);
18: return comboBox;
19: }
20:
21: public void configureComponent(PropertyMeta propertyMeta,
22: SComponent component, boolean erroneous) {
23: SComboBox comboBox = (SComboBox) component;
24: comboBox.setVisible(propertyMeta.isReadable());
25: comboBox.setEnabled(propertyMeta.isWritable());
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: SComboBox comboBox = (SComboBox) component;
38: ((ComboBoxModelPropertyAdapter) comboBox.getModel())
39: .setPropertyData(propertyData);
40: }
41:
42: public PropertyData getPropertyData(SComponent component) {
43: SComboBox comboBox = (SComboBox) component;
44: return ((ComboBoxModelPropertyAdapter) comboBox.getModel())
45: .getPropertyData();
46: }
47:
48: static class ComboBoxModelPropertyAdapter extends
49: SDefaultComboBoxModel implements PropertyAdapter {
50: private PropertyData propertyData;
51: private PropertyMeta property;
52:
53: public ComboBoxModelPropertyAdapter(PropertyMeta property) {
54: this .property = property;
55: }
56:
57: public PropertyData getPropertyData() {
58: return propertyData;
59: }
60:
61: public void setPropertyData(PropertyData propertyData) {
62: this .propertyData = propertyData;
63: }
64:
65: public Object getElementAt(int i) {
66: return property.getRelationBean().getDomainProvider()
67: .getDomain().get(i);
68: }
69:
70: public int getSize() {
71: return property.getRelationBean().getDomainProvider()
72: .getDomain().size();
73: }
74:
75: public Object getSelectedItem() {
76: if (propertyData == null)
77: return null;
78:
79: return propertyData.getValue();
80: }
81:
82: public void setSelectedItem(Object value) {
83: propertyData.setValue(value);
84: fireContentsChanged(this , -1, -1);
85: }
86: }
87: }
|