/* $Id: DefaultEditorFactory.java 722 2006-10-30 10:15:22Z hengels $ */
package org.conform.wings;
import org.conform.wings.editor.*;
import org.conform.*;
import java.util.*;
/**
* TODO: inline editors
*/
public class DefaultEditorFactory
implements EditorFactory
{
protected static final Editor ONE_TO_MANY_EDITOR = new OneToManyEditor();
protected static final Editor MANY_TO_MANY_EDITOR = new ManyToManyEditor();
protected static final Editor MANY_TO_ONE_EDITOR = new ManyToOneEditor();
protected static final Editor DYNAMIC_DOMAIN_EDITOR = new DynamicDomainEditor();
protected static final Editor DOMAIN_EDITOR = new DomainEditor();
protected static final Editor FORMATTED_TEXT_EDITOR = new FormattedTextEditor();
protected static final Editor TEXT_EDITOR = new StringEditor();
public static final Editor LABEL_EDITOR = new DefaultEditor();
protected final Map editorByType = new HashMap();
{
editorByType.put(char.class, new CharacterEditor());
editorByType.put(Character.class, new CharacterEditor());
editorByType.put(boolean.class, BOOLEAN_EDITOR);
editorByType.put(Boolean.class, BOOLEAN_EDITOR);
editorByType.put(java.sql.Date.class, new DateEditor());
editorByType.put(Class.class, new ClassEditor());
}
protected static final BooleanEditor BOOLEAN_EDITOR = new BooleanEditor();
protected static final BooleanEditor BOOLEAN_READONLY_EDITOR = new BooleanEditor(true);
public void setEditorForType(Class type, Editor editor) {
editorByType.put(type, editor);
}
public Editor getEditor(PropertyMeta property) {
if (property.getAttribute(Editor.CUSTOM_EDITOR) != null)
return (Editor)property.getAttribute(Editor.CUSTOM_EDITOR);
if (property.getDomainProvider() instanceof DynamicDomainProvider)
return DYNAMIC_DOMAIN_EDITOR;
if (property.getDomainProvider() != null)
return DOMAIN_EDITOR;
switch (property.getRelationType()) {
/*
case PropertyMeta.ONE_TO_ONE_RELATION:
return ONE_TO_ONE_EDITOR;
*/
case PropertyMeta.ONE_TO_MANY_RELATION:
return ONE_TO_MANY_EDITOR;
case PropertyMeta.MANY_TO_MANY_RELATION:
return MANY_TO_MANY_EDITOR;
case PropertyMeta.MANY_TO_ONE_RELATION:
return MANY_TO_ONE_EDITOR;
}
Editor editor = (Editor)editorByType.get(property.getType());
if (editor != null)
return editor;
return property.getFormat() != null ? FORMATTED_TEXT_EDITOR : TEXT_EDITOR;
}
public Editor getReadOnlyEditor(PropertyMeta property) {
if (property.getType() == Boolean.class || property.getType() == boolean.class)
return BOOLEAN_READONLY_EDITOR;
return LABEL_EDITOR;
}
}
|