diff --git a/pom.xml b/pom.xml index 1501a29..939edd7 100644 --- a/pom.xml +++ b/pom.xml @@ -1,12 +1,17 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 org.vaadin resetbuttonfortextfield-root pom - 1.2.2-SNAPSHOT + 2.0.0-SNAPSHOT ResetButtonForTextField Root Project + + + 3 + + resetbuttonfortextfield resetbuttonfortextfield-demo diff --git a/resetbuttonfortextfield-demo/pom.xml b/resetbuttonfortextfield-demo/pom.xml index 42d24ce..7ed1628 100644 --- a/resetbuttonfortextfield-demo/pom.xml +++ b/resetbuttonfortextfield-demo/pom.xml @@ -1,17 +1,26 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 org.vaadin resetbuttonfortextfield-demo war - 1.2.2-SNAPSHOT + 2.0.0-SNAPSHOT ResetButtonForTextField Demo UI + + + 3 + + UTF-8 - 7.6.4 - ${vaadin.version} + 1.8 + 1.8 + 8.0.5 + 8.0.5 + 9.3.9.v20160517 + Apache 2 @@ -19,34 +28,14 @@ repo + vaadin-addons http://maven.vaadin.com/vaadin-addons - - vaadin-snapshots - https://oss.sonatype.org/content/repositories/vaadin-snapshots/ - - false - - - true - - - - - vaadin-snapshots - https://oss.sonatype.org/content/repositories/vaadin-snapshots/ - - false - - - true - - - + @@ -58,6 +47,7 @@ + org.vaadin @@ -67,6 +57,7 @@ com.vaadin vaadin-client-compiler + provided com.vaadin @@ -75,124 +66,53 @@ javax.servlet javax.servlet-api - 3.1.0 + 3.0.1 provided + - - org.apache.maven.plugins - maven-compiler-plugin - 3.3 - - 1.6 - 1.6 - - - - maven-clean-plugin - 2.6.1 - - - - ${basedir}/src/main/webapp/VAADIN/widgetsets - - - ${basedir}/src/main/webapp/VAADIN/gwt-unitCache - - - - maven-war-plugin - 2.6 + 3.0.0 - - **/VAADIN/gwt-unitCache/**, - **/VAADIN/widgetsets/WEB-INF/**, - **/WEB-INF/lib/servlet-api-*.jar, - **/WEB-INF/lib/vaadin-client-*.jar, - **/WEB-INF/lib/jetty-*.jar, - **/WEB-INF/lib/ant-*.jar, - **/WEB-INF/classes/gwt-unitCache/**, - **/WEB-INF/classes/themes/**, - **/WEB-INF/classes/widgetsets/** - false + com.vaadin vaadin-maven-plugin ${vaadin.plugin.version} - - -Xmx512M -Xss1024k - ${basedir}/src/main/webapp/VAADIN/widgetsets - ${basedir}/src/main/webapp/VAADIN/widgetsets - true - ${basedir}/target/tmp/gwt-unitCache - true - true - http://localhost:8080/ - + + resources + update-widgetset compile + + + - org.mortbay.jetty + org.eclipse.jetty jetty-maven-plugin - 8.1.16.v20140903 + ${jetty.plugin.version} - STOP - 9999 - - / - + 2 + - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - com.vaadin - vaadin-maven-plugin - - [${vaadin.plugin.version},) - - - resources - update-widgetset - compile - update-theme - compile-theme - - - - - - - - - - - - + + diff --git a/resetbuttonfortextfield-demo/src/main/java/org/vaadin/resetbuttonfortextfield/DemoUI.java b/resetbuttonfortextfield-demo/src/main/java/org/vaadin/resetbuttonfortextfield/DemoUI.java index c2b332c..b661041 100644 --- a/resetbuttonfortextfield-demo/src/main/java/org/vaadin/resetbuttonfortextfield/DemoUI.java +++ b/resetbuttonfortextfield-demo/src/main/java/org/vaadin/resetbuttonfortextfield/DemoUI.java @@ -7,8 +7,6 @@ import com.vaadin.annotations.Theme; import com.vaadin.annotations.Title; import com.vaadin.annotations.VaadinServletConfiguration; -import com.vaadin.data.Property; -import com.vaadin.event.FieldEvents; import com.vaadin.server.VaadinRequest; import com.vaadin.server.VaadinServlet; import com.vaadin.ui.Button; @@ -33,20 +31,14 @@ protected void init(VaadinRequest request) { setContent(layout); final TextField tf = new TextField("Type something, please"); - tf.setInputPrompt("Some text here"); + tf.setPlaceholder("Some text here"); final ResetButtonForTextField resetButton = ResetButtonForTextField .extend(tf); layout.addComponent(tf); - tf.setImmediate(true); tf.setWidth("300px"); - final Label textChangeEventListenerLabel = new Label(); - textChangeEventListenerLabel.setHeight("20px"); - textChangeEventListenerLabel.setCaption("I show text changes!"); - layout.addComponent(textChangeEventListenerLabel); - final Label valueChangeListenerLabel = new Label(); valueChangeListenerLabel.setCaption("I show value changes!"); layout.addComponent(valueChangeListenerLabel); @@ -58,20 +50,7 @@ protected void init(VaadinRequest request) { layout.addComponent(resetButtonClickListenerLabel); resetButtonClickListenerLabel.setHeight("20px"); - tf.addValueChangeListener(new Property.ValueChangeListener() { - @Override - public void valueChange(Property.ValueChangeEvent event) { - valueChangeListenerLabel.setValue(event.getProperty() - .getValue().toString()); - } - }); - - tf.addTextChangeListener(new FieldEvents.TextChangeListener() { - @Override - public void textChange(FieldEvents.TextChangeEvent event) { - textChangeEventListenerLabel.setValue(event.getText()); - } - }); + tf.addValueChangeListener(event -> valueChangeListenerLabel.setValue(event.getValue())); resetButton .addResetButtonClickedListener(new ResetButtonClickListener() { @@ -87,38 +66,16 @@ public void resetButtonClicked() { }); Button b1 = new Button("Clear the value of the textfield", - new Button.ClickListener() { - @Override - public void buttonClick(Button.ClickEvent event) { - tf.setValue(""); - } - }); + event -> tf.setValue("")); Button b2 = new Button( "Set the value of the textfield to current date", - new Button.ClickListener() { + event -> tf.setValue(new Date().toString())); + Button b3 = new Button("Toggle Enabled", + event -> tf.setEnabled(!tf.isEnabled())); + Button b4 = new Button("Toggle ReadOnly", + event -> tf.setReadOnly(!tf.isReadOnly())); - @Override - public void buttonClick(Button.ClickEvent event) { - tf.setValue(new Date().toString()); - } - }); - Button b3 = new Button("Toggle Enabled", new Button.ClickListener() { - @Override - public void buttonClick(Button.ClickEvent event) { - tf.setEnabled(!tf.isEnabled()); - } - }); - Button b4 = new Button("Toggle ReadOnly", new Button.ClickListener() { - @Override - public void buttonClick(Button.ClickEvent event) { - tf.setReadOnly(!tf.isReadOnly()); - } - }); - - layout.addComponent(b1); - layout.addComponent(b2); - layout.addComponent(b3); - layout.addComponent(b4); + layout.addComponents(b1, b2, b3,b4); } } diff --git a/resetbuttonfortextfield/pom.xml b/resetbuttonfortextfield/pom.xml index 3963dcd..fd34dab 100644 --- a/resetbuttonfortextfield/pom.xml +++ b/resetbuttonfortextfield/pom.xml @@ -5,18 +5,29 @@ org.vaadin resetbuttonfortextfield jar - 1.2.2-SNAPSHOT + 2.0.0-SNAPSHOT ResetButtonForTextField + + + 3 + + UTF-8 - 7.6.4 - ${vaadin.version} + 1.8 + 1.8 + 8.0.5 + 8.0.5 + + ${project.version} + ${project.name} ${project.organization.name} Apache License 2.0 ${project.artifactId}-${project.version}.jar + Apache 2 @@ -24,34 +35,14 @@ repo + vaadin-addons http://maven.vaadin.com/vaadin-addons - - vaadin-snapshots - https://oss.sonatype.org/content/repositories/vaadin-snapshots/ - - false - - - true - - - - - vaadin-snapshots - https://oss.sonatype.org/content/repositories/vaadin-snapshots/ - - false - - - true - - - + com.vaadin @@ -64,18 +55,18 @@ ${vaadin.version} provided + + + + junit + junit + 4.8.1 + test + + - - org.apache.maven.plugins - maven-compiler-plugin - 3.3 - - 1.6 - 1.6 - - org.apache.maven.plugins maven-jar-plugin @@ -88,6 +79,7 @@ true + 1 ${Vaadin-License-Title} org.vaadin.resetbuttonfortextfield.WidgetSet @@ -95,10 +87,11 @@ + org.apache.maven.plugins maven-javadoc-plugin - 2.10.2 + 2.10.3 attach-javadoc @@ -108,10 +101,11 @@ + org.apache.maven.plugins maven-source-plugin - 2.4 + 3.0.0 attach-sources @@ -121,10 +115,10 @@ + org.apache.maven.plugins maven-assembly-plugin - 2.5.3 false @@ -140,7 +134,17 @@ + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.19.1 + + + src/main/java @@ -152,5 +156,7 @@ src/main/resources + + diff --git a/resetbuttonfortextfield/src/main/java/org/vaadin/resetbuttonfortextfield/client/ResetButtonForTextFieldConnector.java b/resetbuttonfortextfield/src/main/java/org/vaadin/resetbuttonfortextfield/client/ResetButtonForTextFieldConnector.java index fd50d10..67d185d 100644 --- a/resetbuttonfortextfield/src/main/java/org/vaadin/resetbuttonfortextfield/client/ResetButtonForTextFieldConnector.java +++ b/resetbuttonfortextfield/src/main/java/org/vaadin/resetbuttonfortextfield/client/ResetButtonForTextFieldConnector.java @@ -3,29 +3,24 @@ import org.vaadin.resetbuttonfortextfield.ResetButtonForTextField; import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Style.Display; -import com.google.gwt.event.dom.client.KeyUpEvent; -import com.google.gwt.event.dom.client.KeyUpHandler; -import com.google.gwt.event.logical.shared.AttachEvent; import com.google.gwt.user.client.DOM; -import com.vaadin.client.ComponentConnector; import com.vaadin.client.ServerConnector; import com.vaadin.client.communication.RpcProxy; -import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.extensions.AbstractExtensionConnector; import com.vaadin.client.ui.VTextField; +import com.vaadin.client.ui.textfield.AbstractTextFieldConnector; import com.vaadin.shared.ui.Connect; @Connect(ResetButtonForTextField.class) -public class ResetButtonForTextFieldConnector extends - AbstractExtensionConnector implements KeyUpHandler, - AttachEvent.Handler, StateChangeEvent.StateChangeHandler { - private static final long serialVersionUID = -737765038361894693L; +public class ResetButtonForTextFieldConnector extends AbstractExtensionConnector { + + private static final long serialVersionUID = -2256196181999395573L; public static final String CLASSNAME = "resetbuttonfortextfield"; + private AbstractTextFieldConnector textFieldConnector; private VTextField textField; private Element resetButtonElement; private final ResetButtonClickRpc resetButtonClickRpc = RpcProxy.create( @@ -33,28 +28,18 @@ public class ResetButtonForTextFieldConnector extends @Override protected void extend(ServerConnector target) { - target.addStateChangeHandler(new StateChangeEvent.StateChangeHandler() { - private static final long serialVersionUID = -8439729365677484553L; + textFieldConnector = (AbstractTextFieldConnector) target; + textFieldConnector.addStateChangeHandler(stateChangeEvent -> + Scheduler.get().scheduleDeferred(() -> updateResetButtonVisibility())); - @Override - public void onStateChanged(StateChangeEvent stateChangeEvent) { - Scheduler.get().scheduleDeferred(new ScheduledCommand() { - @Override - public void execute() { - updateResetButtonVisibility(); - } - }); - } - }); - - textField = (VTextField) ((ComponentConnector) target).getWidget(); + textField = (VTextField) textFieldConnector.getWidget(); textField.addStyleName(CLASSNAME + "-textfield"); resetButtonElement = DOM.createDiv(); resetButtonElement.addClassName(CLASSNAME + "-resetbutton"); - textField.addAttachHandler(this); - textField.addKeyUpHandler(this); + textField.addAttachHandler(event -> handleAttach(event.isAttached())); + textField.addKeyUpHandler(change -> updateResetButtonVisibility()); } public native void addResetButtonClickListener(Element el) @@ -70,9 +55,8 @@ public native void removeResetButtonClickListener(Element el) el.onclick = null; }-*/; - @Override - public void onAttachOrDetach(AttachEvent event) { - if (event.isAttached()) { + private void handleAttach(boolean isAttached) { + if (isAttached) { textField.getElement().getParentElement() .insertAfter(resetButtonElement, textField.getElement()); updateResetButtonVisibility(); @@ -86,11 +70,6 @@ public void onAttachOrDetach(AttachEvent event) { } } - @Override - public void onKeyUp(KeyUpEvent event) { - updateResetButtonVisibility(); - } - private void updateResetButtonVisibility() { if (textField.getValue().isEmpty() || textField.isReadOnly() || !textField.isEnabled() @@ -104,7 +83,7 @@ private void updateResetButtonVisibility() { private void clearTextField() { resetButtonClickRpc.resetButtonClick(); textField.setValue(""); - textField.valueChange(true); + textFieldConnector.sendValueChange(); updateResetButtonVisibility(); textField.getElement().focus(); } diff --git a/resetbuttonfortextfield/src/main/resources/org/vaadin/resetbuttonfortextfield/public/resetbuttonfortextfield/resetbutton-default.png b/resetbuttonfortextfield/src/main/resources/org/vaadin/resetbuttonfortextfield/public/resetbuttonfortextfield/resetbutton-default.png deleted file mode 100644 index f0322b3..0000000 Binary files a/resetbuttonfortextfield/src/main/resources/org/vaadin/resetbuttonfortextfield/public/resetbuttonfortextfield/resetbutton-default.png and /dev/null differ diff --git a/resetbuttonfortextfield/src/main/resources/org/vaadin/resetbuttonfortextfield/public/resetbuttonfortextfield/resetbutton-hover.png b/resetbuttonfortextfield/src/main/resources/org/vaadin/resetbuttonfortextfield/public/resetbuttonfortextfield/resetbutton-hover.png deleted file mode 100644 index c5640a3..0000000 Binary files a/resetbuttonfortextfield/src/main/resources/org/vaadin/resetbuttonfortextfield/public/resetbuttonfortextfield/resetbutton-hover.png and /dev/null differ diff --git a/resetbuttonfortextfield/src/main/resources/org/vaadin/resetbuttonfortextfield/public/resetbuttonfortextfield/styles.css b/resetbuttonfortextfield/src/main/resources/org/vaadin/resetbuttonfortextfield/public/resetbuttonfortextfield/styles.css index 0f219f5..e06d227 100644 --- a/resetbuttonfortextfield/src/main/resources/org/vaadin/resetbuttonfortextfield/public/resetbuttonfortextfield/styles.css +++ b/resetbuttonfortextfield/src/main/resources/org/vaadin/resetbuttonfortextfield/public/resetbuttonfortextfield/styles.css @@ -21,12 +21,3 @@ background-image: url('resetbutton-hover.svg'); cursor: pointer; } - -.v-ie8 .resetbuttonfortextfield-resetbutton { - background-image: url('resetbutton-default.png'); -} - -.v-ie8 .resetbuttonfortextfield-resetbutton:hover { - background-image: url('resetbutton-hover.png'); -} -