[jboss-cvs] jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/preferences/editor ...
Christian Bauer
christian at hibernate.org
Sat Dec 29 21:33:23 EST 2007
User: cbauer
Date: 07/12/29 21:33:23
Added: examples/wiki/src/main/org/jboss/seam/wiki/core/preferences/editor
EditorAdaptiveTextInput.java EditorSelectOne.java
EditorNumberRange.java
Log:
Complete overhaul of the preferences system
Revision Changes Path
1.1 date: 2007/12/30 02:33:23; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/preferences/editor/EditorAdaptiveTextInput.java
Index: EditorAdaptiveTextInput.java
===================================================================
package org.jboss.seam.wiki.core.preferences.editor;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.ScopeType;
import org.jboss.seam.wiki.preferences.metamodel.PreferenceEntity;
import org.hibernate.validator.Length;
import java.io.Serializable;
@Name("editorAdaptiveTextInput")
@Scope(ScopeType.CONVERSATION)
public class EditorAdaptiveTextInput implements Serializable {
public static final Long DEFAULT_TEXTINPUT_LENGTH = 25l;
public static final Long DEFAULT_TEAXTAREA_LENGTH = 255l;
public static final Long DEFAULT_TEAXTAREA_COLS = 25l;
public static final Long DEFAULT_TEAXTAREA_ROWS = 10l;
public long getSize(PreferenceEntity.Property property) {
return getMaxLength(property) <= DEFAULT_TEXTINPUT_LENGTH ? getMaxLength(property) : DEFAULT_TEXTINPUT_LENGTH;
}
public long getMaxLength(PreferenceEntity.Property property) {
checkAnnotation(property);
return property.getField().getAnnotation(Length.class).max();
}
public boolean isRenderTextArea(PreferenceEntity.Property property) {
return getMaxLength(property) > DEFAULT_TEAXTAREA_LENGTH;
}
public long getTextAreaCols(PreferenceEntity.Property property) {
return DEFAULT_TEAXTAREA_COLS;
}
public long getTextAreaRows(PreferenceEntity.Property property) {
return DEFAULT_TEAXTAREA_ROWS;
}
private void checkAnnotation(PreferenceEntity.Property property) {
if (!property.getField().isAnnotationPresent(Length.class)) {
throw new IllegalArgumentException("property does not have @Length annotation " + property);
}
}
}
1.1 date: 2007/12/30 02:33:23; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/preferences/editor/EditorSelectOne.java
Index: EditorSelectOne.java
===================================================================
package org.jboss.seam.wiki.core.preferences.editor;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.ScopeType;
import org.jboss.seam.Component;
import org.jboss.seam.wiki.preferences.metamodel.PreferenceEntity;
import org.jboss.seam.wiki.preferences.PreferenceValueTemplate;
import org.hibernate.validator.NotNull;
import java.util.List;
import java.io.Serializable;
@Name("editorSelectOne")
@Scope(ScopeType.CONVERSATION)
public class EditorSelectOne implements Serializable {
public List<String> getAllValues(PreferenceEntity.Property property) {
if (property.getTemplateComponentName() == null || property.getTemplateComponentName().length() == 0)
throw new RuntimeException("No value template component name " + property);
PreferenceValueTemplate template =
(PreferenceValueTemplate)Component.getInstance(property.getTemplateComponentName());
if (template == null)
throw new RuntimeException("Couldn't find template component name: " + property.getTemplateComponentName());
return template.getTemplateValues();
}
public boolean isNullable(PreferenceEntity.Property property) {
return !property.getField().isAnnotationPresent(NotNull.class);
}
}
1.1 date: 2007/12/30 02:33:23; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/preferences/editor/EditorNumberRange.java
Index: EditorNumberRange.java
===================================================================
package org.jboss.seam.wiki.core.preferences.editor;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.ScopeType;
import org.jboss.seam.wiki.preferences.metamodel.PreferenceEntity;
import org.hibernate.validator.Range;
import java.io.Serializable;
@Name("editorNumberRange")
@Scope(ScopeType.CONVERSATION)
public class EditorNumberRange implements Serializable {
public long getRangeMin(PreferenceEntity.Property property) {
checkAnnotation(property);
return property.getField().getAnnotation(Range.class).min();
}
public long getRangeMax(PreferenceEntity.Property property) {
checkAnnotation(property);
return property.getField().getAnnotation(Range.class).max();
}
private void checkAnnotation(PreferenceEntity.Property property) {
if (!property.getField().isAnnotationPresent(Range.class)) {
throw new IllegalArgumentException("property does not have @Range annotation " + property);
}
}
}
More information about the jboss-cvs-commits
mailing list