diff options
-rw-r--r-- | client/src/main/java/com/vaadin/client/ui/textfield/TextFieldConnector.java | 55 | ||||
-rw-r--r-- | server/src/main/java/com/vaadin/ui/AbstractTextField.java | 52 | ||||
-rw-r--r-- | shared/src/main/java/com/vaadin/shared/ui/textfield/AbstractTextFieldServerRpc.java (renamed from shared/src/main/java/com/vaadin/shared/ui/textfield/TextFieldServerRpc.java) | 4 |
3 files changed, 51 insertions, 60 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/textfield/TextFieldConnector.java b/client/src/main/java/com/vaadin/client/ui/textfield/TextFieldConnector.java index 794160beec..aec7b0f3d5 100644 --- a/client/src/main/java/com/vaadin/client/ui/textfield/TextFieldConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/textfield/TextFieldConnector.java @@ -17,59 +17,44 @@ package com.vaadin.client.ui.textfield; import com.google.gwt.core.client.Scheduler; -import com.google.gwt.event.dom.client.ChangeEvent; -import com.google.gwt.event.dom.client.ChangeHandler; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.Timer; import com.vaadin.client.annotations.OnStateChange; import com.vaadin.client.event.InputEvent; -import com.vaadin.client.event.InputHandler; import com.vaadin.client.ui.AbstractComponentConnector; import com.vaadin.client.ui.ConnectorFocusAndBlurHandler; import com.vaadin.client.ui.VTextField; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.Connect.LoadStyle; -import com.vaadin.shared.ui.textfield.TextFieldServerRpc; +import com.vaadin.shared.ui.textfield.AbstractTextFieldServerRpc; import com.vaadin.shared.ui.textfield.TextFieldState; import com.vaadin.shared.ui.textfield.ValueChangeMode; import com.vaadin.ui.TextField; +/** + * Connector class for TextField. + */ @Connect(value = TextField.class, loadStyle = LoadStyle.EAGER) public class TextFieldConnector extends AbstractComponentConnector { + private Timer valueChangeTrigger = new Timer() { + @Override + public void run() { + Scheduler.get().scheduleDeferred(() -> sendValueChange()); + } + }; + @Override protected void init() { ConnectorFocusAndBlurHandler.addHandlers(this); - getWidget().addChangeHandler(new ChangeHandler() { - - @Override - public void onChange(ChangeEvent event) { - sendValueChange(); - } - }); - getWidget().addDomHandler(new InputHandler() { - - @Override - public void onInput(InputEvent event) { - if (getState().valueChangeMode != ValueChangeMode.BLUR) { - scheduleValueChange(); - } + getWidget().addChangeHandler(event -> sendValueChange()); + getWidget().addDomHandler(event -> { + if (getState().valueChangeMode != ValueChangeMode.BLUR) { + scheduleValueChange(); } }, InputEvent.getType()); } - private Timer valueChangeTrigger = new Timer() { - @Override - public void run() { - Scheduler.get().scheduleDeferred(new Command() { - @Override - public void execute() { - sendValueChange(); - } - }); - } - }; - private void scheduleValueChange() { switch (getState().valueChangeMode) { case LAZY: @@ -81,6 +66,9 @@ public class TextFieldConnector extends AbstractComponentConnector { case EAGER: eagerTextChange(); break; + case BLUR: + // Nothing to schedule for this mode + break; } } @@ -89,8 +77,9 @@ public class TextFieldConnector extends AbstractComponentConnector { } private void timeoutTextChange() { - if (valueChangeTrigger.isRunning()) + if (valueChangeTrigger.isRunning()) { return; + } valueChangeTrigger.schedule(getState().valueChangeTimeout); } @@ -147,8 +136,8 @@ public class TextFieldConnector extends AbstractComponentConnector { if (!hasStateChanged()) { return; } - getRpcProxy(TextFieldServerRpc.class).setText(getWidget().getValue(), - getWidget().getCursorPos()); + getRpcProxy(AbstractTextFieldServerRpc.class) + .setText(getWidget().getValue(), getWidget().getCursorPos()); getState().text = getWidget().getValue(); getState().cursorPosition = getWidget().getCursorPos(); } diff --git a/server/src/main/java/com/vaadin/ui/AbstractTextField.java b/server/src/main/java/com/vaadin/ui/AbstractTextField.java index d265ddf89e..f6e31d6da3 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractTextField.java +++ b/server/src/main/java/com/vaadin/ui/AbstractTextField.java @@ -26,7 +26,7 @@ import com.vaadin.event.FieldEvents.BlurListener; import com.vaadin.event.FieldEvents.FocusEvent; import com.vaadin.event.FieldEvents.FocusListener; import com.vaadin.shared.Registration; -import com.vaadin.shared.ui.textfield.TextFieldServerRpc; +import com.vaadin.shared.ui.textfield.AbstractTextFieldServerRpc; import com.vaadin.shared.ui.textfield.TextFieldState; import com.vaadin.shared.ui.textfield.ValueChangeMode; import com.vaadin.ui.declarative.DesignAttributeHandler; @@ -40,30 +40,31 @@ import com.vaadin.ui.declarative.DesignContext; */ public abstract class AbstractTextField extends AbstractField<String> { + private final class TextFieldServerRpcImpl + implements AbstractTextFieldServerRpc { + @Override + public void blur() { + fireEvent(new BlurEvent(AbstractTextField.this)); + } + + @Override + public void focus() { + fireEvent(new FocusEvent(AbstractTextField.this)); + } + + @Override + public void setText(String text, int cursorPosition) { + getUI().getConnectorTracker().getDiffState(AbstractTextField.this) + .put("text", text); + getUI().getConnectorTracker().getDiffState(AbstractTextField.this) + .put("cursorPosition", cursorPosition); + getState(false).cursorPosition = cursorPosition; + setValue(text, true); + } + } + protected AbstractTextField() { - registerRpc(new TextFieldServerRpc() { - - @Override - public void blur() { - fireEvent(new BlurEvent(AbstractTextField.this)); - } - - @Override - public void focus() { - fireEvent(new FocusEvent(AbstractTextField.this)); - } - - @Override - public void setText(String text, int cursorPosition) { - getUI().getConnectorTracker() - .getDiffState(AbstractTextField.this).put("text", text); - getUI().getConnectorTracker() - .getDiffState(AbstractTextField.this) - .put("cursorPosition", cursorPosition); - getState(false).cursorPosition = cursorPosition; - setValue(text, true); - } - }); + registerRpc(new TextFieldServerRpcImpl()); } @Override @@ -261,9 +262,10 @@ public abstract class AbstractTextField extends AbstractField<String> { * @see ValueChangeMode */ public void setValueChangeTimeout(int timeout) { - if (timeout < 0) + if (timeout < 0) { throw new IllegalArgumentException( "Timeout must be greater than 0"); + } getState().valueChangeTimeout = timeout; } diff --git a/shared/src/main/java/com/vaadin/shared/ui/textfield/TextFieldServerRpc.java b/shared/src/main/java/com/vaadin/shared/ui/textfield/AbstractTextFieldServerRpc.java index bb87f93b1a..3c1e77fa30 100644 --- a/shared/src/main/java/com/vaadin/shared/ui/textfield/TextFieldServerRpc.java +++ b/shared/src/main/java/com/vaadin/shared/ui/textfield/AbstractTextFieldServerRpc.java @@ -18,7 +18,7 @@ package com.vaadin.shared.ui.textfield; import com.vaadin.shared.communication.FieldRpc.FocusAndBlurServerRpc; -public interface TextFieldServerRpc extends FocusAndBlurServerRpc { +public interface AbstractTextFieldServerRpc extends FocusAndBlurServerRpc { - public void setText(String text, int cursorPosition); + void setText(String text, int cursorPosition); } |