From 8be086b6cbabda2a65b3b970526ed3a69670b04c Mon Sep 17 00:00:00 2001 From: caalador Date: Fri, 27 Jan 2017 09:12:03 +0200 Subject: Add convenience constructors for TextField (#597) (#8341) Add convenience constructors for TextField (#597) Added TextField convenience constructors similar to the ones found in Vaadin framework 7 --- server/src/main/java/com/vaadin/ui/TextField.java | 51 ++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'server/src/main/java') diff --git a/server/src/main/java/com/vaadin/ui/TextField.java b/server/src/main/java/com/vaadin/ui/TextField.java index 3969fec202..a8171ba4f4 100644 --- a/server/src/main/java/com/vaadin/ui/TextField.java +++ b/server/src/main/java/com/vaadin/ui/TextField.java @@ -57,13 +57,62 @@ public class TextField extends AbstractTextField { * @param caption * the caption String for the editor. * @param value - * the initial text content of the editor. + * the initial text content of the editor, not {@code null} */ public TextField(String caption, String value) { setValue(value); setCaption(caption); } + /** + * Constructs a new {@code TextField} with a value change listener. The + * listener is called when the value of this {@code TextField} is changed + * either by the user or programmatically. + * + * @param valueChangeListener + * the value change listener, not {@code null} + */ + public TextField(ValueChangeListener valueChangeListener) { + addValueChangeListener(valueChangeListener); + } + + /** + * Constructs a new {@code TextField} with the given caption and a value + * change listener. + *

+ * The listener is called when the value of this {@code TextField} is + * changed either by the user or programmatically. + * + * @param caption + * the caption {@code String} for the editor. + * @param valueChangeListener + * the value change listener, not {@code null} + */ + public TextField(String caption, ValueChangeListener valueChangeListener) { + this(valueChangeListener); + setCaption(caption); + } + + /** + * Constructs a new {@code TextField} with the given caption, initial text + * contents and a value change listener. + *

+ * The listener is called when the value of this {@code TextField} is + * changed either by the user or programmatically. + * + * @param caption + * the caption {@code String} for the editor. + * @param value + * the initial text content of the editor, not {@code null} + * @param valueChangeListener + * the value change listener, not {@code null} + */ + public TextField(String caption, String value, + ValueChangeListener valueChangeListener) { + this(caption, value); + addValueChangeListener(valueChangeListener); + } + @Override protected TextFieldState getState() { return (TextFieldState) super.getState(); -- cgit v1.2.3