From 63cd521b095455af73a5b04fb9204674eb20886d Mon Sep 17 00:00:00 2001 From: Jerome Meyer Date: Thu, 6 Apr 2017 15:11:31 -0400 Subject: [PATCH] Port to Vaadin 8 --- pom.xml | 9 +- resetbuttonfortextfield-demo/pom.xml | 146 ++++-------------- .../resetbuttonfortextfield/DemoUI.java | 61 ++------ resetbuttonfortextfield/pom.xml | 80 +++++----- .../ResetButtonForTextFieldConnector.java | 49 ++---- .../resetbutton-default.png | Bin 676 -> 0 bytes .../resetbutton-hover.png | Bin 746 -> 0 bytes .../public/resetbuttonfortextfield/styles.css | 9 -- 8 files changed, 106 insertions(+), 248 deletions(-) delete mode 100644 resetbuttonfortextfield/src/main/resources/org/vaadin/resetbuttonfortextfield/public/resetbuttonfortextfield/resetbutton-default.png delete mode 100644 resetbuttonfortextfield/src/main/resources/org/vaadin/resetbuttonfortextfield/public/resetbuttonfortextfield/resetbutton-hover.png 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 f0322b339c952e2490db076c39482173dfafaee3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 676 zcmV;V0$crwP)LF+@*g&hpvKjEfl&NA1-l9LHXn?zB>+1Xi6#&H~)%_ac7UXRIS0`PM@9(x9O4O9SXwHlUX;kquK z=ixXGi;IhRo`-GQ*tX5e%1Yi;-F4kPOI7_G84L!fDr;+N*tU)5d58#>WdU$;alz%~ zWqC5+0ty3FWiS{J$1$~9jfI7Uf;k)xxw^WV57jq-GoSYT{r${4%d#SmIovTow+vRR zRW>&_3n73phDM{o>gwu@fib3QRJAbJ*w~<6uLF=I3H^S*$VEih+S+1$eZ4SH)vf`) z0ujJuGC@^|qKICv$7nR-`udvl^K-H+BTdtMg#f>eG2io#^j<_h0#qs$9v&XbL;#kT zmr2urk_OQ2;k=C<{vS@?d@$L1`dNDIE25q&~CSrIF6sI>W6%s zM{1<1Z(FU_eh$d|Id?jphB4-4mSw((_`no61-c?~5Cp-mGXD=4-UNHoZ9|8O zgNu+4QfL>uceBkDF)jtiQi_`p6E~$$mm&nZnXQ9J6;cQD5Q8RIc}>jiP+uFx_Dp{+ z_uT(E_i#m3X+$_2z9k}0MPwKlR#jI-@~XOZc6Rn@eSQ5$W4|;Gh{a-4s`>#4ay`DO z>WgeP`^765-Xj`~zEjn;|BwOhh)6CHiM+m~AQFi@6Om*})I!GiE0L;(NQ!Ew%_Iy6y z1EXHAKL=U?CMPEe1Ojw*bul+LM|*oa-QC?JlSwSg!m=zzM@KzTw_VqrGHu&_1>6V7 z=kr*WMNdx;EiEmKkB<`yg$M)!0Ho7t*4EbkCLmHUZQFhe+`KSGKA)$lsfoV6KKy<^ zKA#U&Woc=Njg5_~ORX9}b7MtSDHIAc##^h^{_NulnoZlbL%?0HGBGj1%*+fTLbY1O zFbqu7WNd5<$8p%--)|hSZVn6#+!K*U0Mpac#N%;9gwxYg78VxR-ri$)5q9C*K%{C@vO zQB`8G*c(+%0SpcfQY;p69OshR{{DVk*JXEi*GnM2va*sERV5S(-3SJQpMi(hZR#4N zGnq^rE^c9SbF=0+&Jz(ycy|7QvZ}uH$Z+Kv0m9*MzhM{=exLHNh`2x=*s9m-%d4xa c-y8dX0qr{o^Ktl}R{#J207*qoM6N<$f;+%F6#xJL 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'); -} -