001: /* $Id: PropertyCellRenderer.java 812 2007-01-15 20:48:12Z hengels $ */
002: package org.conform.wings;
003:
004: import java.util.Collection;
005:
006: import org.conform.AbstractPropertyData;
007: import org.conform.BeanData;
008: import org.conform.BeanMeta;
009: import org.conform.Data;
010: import org.conform.DomainProvider;
011: import org.conform.PropertyMeta;
012: import org.conform.TableData;
013: import org.conform.ValidationEvent;
014: import org.conform.ValidationListener;
015: import org.conform.format.*;
016: import org.wings.*;
017: import org.wings.table.STableCellRenderer;
018:
019: public class PropertyCellRenderer implements STableCellRenderer,
020: SListCellRenderer {
021: private RendererPropertyData propertyData;
022: private Editor editor;
023: protected SComponent component;
024: private SLabel label = new SLabel();
025: StringBuffer nameBuffer = new StringBuffer();
026: private PropertyMeta propertyMeta;
027:
028: public PropertyCellRenderer(Editor editor, PropertyMeta property) {
029: this .propertyMeta = property;
030: this .editor = editor;
031: this .component = editor.createComponent(property);
032: this .component.setStyle(component.getStyle().replaceFirst(
033: "formeditor", "formlabel"));
034: this .propertyData = new RendererPropertyData(property);
035: this .editor.setPropertyData(component, propertyData);
036: /*
037: String alignment = (String)property.getAttribute(PropertyMeta.ATTRIBUTE_ALIGNMENT);
038: if (alignment != null) {
039: if ("right".equals(alignment)) {
040: component.setHorizontalAlignment(SConstants.RIGHT_ALIGN);
041: component.setStyle(component.getStyle() + " right_align");
042: }
043: else if ("center".equals(alignment)) {
044: component.setHorizontalAlignment(SConstants.CENTER_ALIGN);
045: component.setStyle(component.getStyle() + " center_align");
046: }
047: }
048: */
049: }
050:
051: public PropertyMeta getPropertyMeta() {
052: return propertyMeta;
053: }
054:
055: public void configureComponent() {
056: editor.configureComponent(propertyMeta, component, false);
057: component.setStyle(component.getStyle().replaceFirst(
058: "formeditor", "formlabel"));
059: }
060:
061: public SComponent getTableCellRendererComponent(STable table,
062: Object value, boolean b, int row, int column) {
063: propertyData.setValue(value);
064: if (value == null && table.isCellEditable(row, column)) {
065: label.setText(null);
066: return label;
067: }
068:
069: if (propertyData.getPropertyMeta().isWritable()) {
070: if (table.getModel() instanceof TableData) {
071: TableData tableData = (TableData) table.getModel();
072: propertyData.setValue(value);
073: BeanData delegateBeanData = tableData.getRowData(row);
074: propertyData.setDelegateFormData(delegateBeanData);
075: }
076: return component;
077: } else {
078: /*
079: label.setText(getText());
080: label.setNameRaw(name(table, row, column));
081: return label;
082: */
083: return component;
084: }
085: }
086:
087: public SComponent getListCellRendererComponent(SComponent list,
088: Object value, boolean isSelected, int index) {
089: propertyData.setValue(value);
090: return component;
091: }
092:
093: public String getText() {
094: Object value = propertyData.getValue();
095: if (value == null)
096: return null;
097:
098: Format format = propertyData.getPropertyMeta().getFormat();
099: if (format == null)
100: format = FormatFactory.NO_FORMAT;
101:
102: return format.format(value);
103: }
104:
105: static class RendererPropertyData extends AbstractPropertyData {
106: private Object value;
107: private BeanData delegateBeanData;
108:
109: protected RendererPropertyData(PropertyMeta property) {
110: super (null, property);
111: }
112:
113: public BeanMeta getBean() {
114: return null;
115: }
116:
117: public void setValue(Object value) {
118: this .value = value;
119: }
120:
121: public Object getValue() {
122: return value;
123: }
124:
125: public Data getRelationData() {
126: return delegateBeanData.getPropertyData(getPropertyMeta())
127: .getRelationData();
128: }
129:
130: public void addValidationListener(ValidationListener listener) {
131: }
132:
133: public void removeValidationListener(ValidationListener listener) {
134: }
135:
136: public void fireAddIssue(ValidationEvent event) {
137: }
138:
139: public void fireRemoveIssue(ValidationEvent event) {
140: }
141:
142: public void clear() {
143: value = null;
144: }
145:
146: public void flush() {
147: }
148:
149: protected void doSetValue(Object value) {
150: }
151:
152: protected Object doGetValue() {
153: return null;
154: }
155:
156: public void update() {
157: }
158:
159: public void setDelegateFormData(BeanData delegateBeanData) {
160: this .delegateBeanData = delegateBeanData;
161: }
162:
163: public void setInvalidValue(Object text) {
164: }
165:
166: public Object getInvalidValue() {
167: return null;
168: }
169: }
170:
171: static class ReadOnlyProperty extends PropertyMeta {
172: private PropertyMeta property;
173:
174: public ReadOnlyProperty(PropertyMeta property) {
175: super (property.getBeanMeta(), property.getName(), property
176: .getType());
177: this .property = property;
178: }
179:
180: public String getName() {
181: return property.getName();
182: }
183:
184: public Class getType() {
185: return property.getType();
186: }
187:
188: public boolean isMandatory() {
189: return property.isMandatory();
190: }
191:
192: public boolean isWritable() {
193: return false;
194: }
195:
196: public boolean isReadable() {
197: return property.isReadable();
198: }
199:
200: public Collection getValidators() {
201: return property.getValidators();
202: }
203:
204: public int getPriority() {
205: return property.getPriority();
206: }
207:
208: public DomainProvider getDomainProvider() {
209: return property.getDomainProvider();
210: }
211:
212: public int getRelationType() {
213: return property.getRelationType();
214: }
215:
216: public BeanMeta getRelationBean() {
217: return property.getRelationBean();
218: }
219:
220: public PropertyMeta getRelationProperty() {
221: return property.getRelationProperty();
222: }
223:
224: public Object getAttribute(String name) {
225: return property.getAttribute(name);
226: }
227:
228: public void setName(String name) {
229: }
230:
231: public void setType(Class type) {
232: }
233:
234: public void setMandatory(boolean mandatory) {
235: }
236:
237: public void setWritable(boolean readonly) {
238: }
239:
240: public void setReadable(boolean visible) {
241: }
242:
243: public void setValidators(Collection validators) {
244: }
245:
246: public void setDefaultValue(Object defaultValue) {
247: }
248:
249: public void setDomainProvider(DomainProvider domainProvider) {
250: }
251:
252: public void setRelationType(int relationType) {
253: }
254:
255: public void setRelationBean(BeanMeta relationBean) {
256: }
257:
258: public void setRelationProperty(PropertyMeta relationProperty) {
259: }
260:
261: public void setAttribute(String name, Object value) {
262: }
263:
264: public void setPriority(int priority) {
265: }
266: }
267: }
|