From 775276d4a987844fbbb88730f0eb11e285ae6e09 Mon Sep 17 00:00:00 2001 From: Matti Hosio Date: Wed, 10 Dec 2014 17:01:33 +0200 Subject: Declarative support for AbstractTextField (#7749) Change-Id: Ice244cd73825bde44fe02cf3d4b53d4eff5a5c35 --- server/src/com/vaadin/ui/AbstractTextField.java | 56 +++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'server/src/com/vaadin/ui/AbstractTextField.java') diff --git a/server/src/com/vaadin/ui/AbstractTextField.java b/server/src/com/vaadin/ui/AbstractTextField.java index 9293d38119..31672a1f39 100644 --- a/server/src/com/vaadin/ui/AbstractTextField.java +++ b/server/src/com/vaadin/ui/AbstractTextField.java @@ -16,8 +16,12 @@ package com.vaadin.ui; +import java.util.Collection; import java.util.Map; +import org.jsoup.nodes.Attributes; +import org.jsoup.nodes.Element; + import com.vaadin.event.FieldEvents.BlurEvent; import com.vaadin.event.FieldEvents.BlurListener; import com.vaadin.event.FieldEvents.BlurNotifier; @@ -31,6 +35,8 @@ import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; import com.vaadin.shared.ui.textfield.AbstractTextFieldState; import com.vaadin.shared.ui.textfield.TextFieldConstants; +import com.vaadin.ui.declarative.DesignAttributeHandler; +import com.vaadin.ui.declarative.DesignContext; public abstract class AbstractTextField extends AbstractField implements BlurNotifier, FocusNotifier, TextChangeNotifier, LegacyComponent { @@ -757,4 +763,54 @@ public abstract class AbstractTextField extends AbstractField implements removeBlurListener(listener); } + /* + * (non-Javadoc) + * + * @see + * com.vaadin.ui.AbstractField#synchronizeFromDesign(org.jsoup.nodes.Element + * , com.vaadin.ui.declarative.DesignContext) + */ + @Override + public void synchronizeFromDesign(Element design, + DesignContext designContext) { + super.synchronizeFromDesign(design, designContext); + AbstractTextField def = designContext.getDefaultInstance(this + .getClass()); + Attributes attr = design.attributes(); + int maxLength = DesignAttributeHandler.readAttribute("maxlength", attr, + def.getMaxLength(), Integer.class); + setMaxLength(maxLength); + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.ui.AbstractField#getCustomAttributes() + */ + @Override + protected Collection getCustomAttributes() { + Collection customAttributes = super.getCustomAttributes(); + customAttributes.add("maxlength"); + customAttributes.add("max-length"); // to prevent this appearing in + // output + return customAttributes; + } + + /* + * (non-Javadoc) + * + * @see + * com.vaadin.ui.AbstractField#synchronizeToDesign(org.jsoup.nodes.Element, + * com.vaadin.ui.declarative.DesignContext) + */ + @Override + public void synchronizeToDesign(Element design, DesignContext designContext) { + super.synchronizeToDesign(design, designContext); + AbstractTextField def = designContext.getDefaultInstance(this + .getClass()); + Attributes attr = design.attributes(); + DesignAttributeHandler.writeAttribute("maxlength", attr, + getMaxLength(), def.getMaxLength(), Integer.class); + } + } -- cgit v1.2.3