01: /* $Id: DefaultEditorFactory.java 722 2006-10-30 10:15:22Z hengels $ */
02: package org.conform.wings;
03:
04: import org.conform.wings.editor.*;
05: import org.conform.*;
06:
07: import java.util.*;
08:
09: /**
10: * TODO: inline editors
11: */
12: public class DefaultEditorFactory implements EditorFactory {
13: protected static final Editor ONE_TO_MANY_EDITOR = new OneToManyEditor();
14: protected static final Editor MANY_TO_MANY_EDITOR = new ManyToManyEditor();
15: protected static final Editor MANY_TO_ONE_EDITOR = new ManyToOneEditor();
16: protected static final Editor DYNAMIC_DOMAIN_EDITOR = new DynamicDomainEditor();
17: protected static final Editor DOMAIN_EDITOR = new DomainEditor();
18: protected static final Editor FORMATTED_TEXT_EDITOR = new FormattedTextEditor();
19: protected static final Editor TEXT_EDITOR = new StringEditor();
20: public static final Editor LABEL_EDITOR = new DefaultEditor();
21:
22: protected final Map editorByType = new HashMap();
23:
24: {
25: editorByType.put(char.class, new CharacterEditor());
26: editorByType.put(Character.class, new CharacterEditor());
27: editorByType.put(boolean.class, BOOLEAN_EDITOR);
28: editorByType.put(Boolean.class, BOOLEAN_EDITOR);
29: editorByType.put(java.sql.Date.class, new DateEditor());
30: editorByType.put(Class.class, new ClassEditor());
31: }
32:
33: protected static final BooleanEditor BOOLEAN_EDITOR = new BooleanEditor();
34: protected static final BooleanEditor BOOLEAN_READONLY_EDITOR = new BooleanEditor(
35: true);
36:
37: public void setEditorForType(Class type, Editor editor) {
38: editorByType.put(type, editor);
39: }
40:
41: public Editor getEditor(PropertyMeta property) {
42: if (property.getAttribute(Editor.CUSTOM_EDITOR) != null)
43: return (Editor) property.getAttribute(Editor.CUSTOM_EDITOR);
44:
45: if (property.getDomainProvider() instanceof DynamicDomainProvider)
46: return DYNAMIC_DOMAIN_EDITOR;
47:
48: if (property.getDomainProvider() != null)
49: return DOMAIN_EDITOR;
50:
51: switch (property.getRelationType()) {
52: /*
53: case PropertyMeta.ONE_TO_ONE_RELATION:
54: return ONE_TO_ONE_EDITOR;
55: */
56:
57: case PropertyMeta.ONE_TO_MANY_RELATION:
58: return ONE_TO_MANY_EDITOR;
59:
60: case PropertyMeta.MANY_TO_MANY_RELATION:
61: return MANY_TO_MANY_EDITOR;
62:
63: case PropertyMeta.MANY_TO_ONE_RELATION:
64: return MANY_TO_ONE_EDITOR;
65: }
66:
67: Editor editor = (Editor) editorByType.get(property.getType());
68: if (editor != null)
69: return editor;
70:
71: return property.getFormat() != null ? FORMATTED_TEXT_EDITOR
72: : TEXT_EDITOR;
73: }
74:
75: public Editor getReadOnlyEditor(PropertyMeta property) {
76: if (property.getType() == Boolean.class
77: || property.getType() == boolean.class)
78: return BOOLEAN_READONLY_EDITOR;
79:
80: return LABEL_EDITOR;
81: }
82: }
|