diff options
author | Henri Sara <hesara@vaadin.com> | 2016-08-10 11:26:01 +0300 |
---|---|---|
committer | Henri Sara <hesara@vaadin.com> | 2016-08-11 15:34:22 +0300 |
commit | c726ae1b276049282286db3b0934e90ac8d8a2ce (patch) | |
tree | 86cdf6ac65acd3bd6c2908652178b99c9dc6c1ae | |
parent | 81b849c1af199be481e00c86ca324cfaffe8a7a0 (diff) | |
download | vaadin-framework-c726ae1b276049282286db3b0934e90ac8d8a2ce.tar.gz vaadin-framework-c726ae1b276049282286db3b0934e90ac8d8a2ce.zip |
Make immediate mode the default
Change-Id: I0a1fc0bf6f3de1b7d6975cd87cb7bb65c38dba4e
12 files changed, 77 insertions, 335 deletions
diff --git a/server/src/main/java/com/vaadin/legacy/ui/LegacyAbstractField.java b/server/src/main/java/com/vaadin/legacy/ui/LegacyAbstractField.java index 402f1fb257..901cb78932 100644 --- a/server/src/main/java/com/vaadin/legacy/ui/LegacyAbstractField.java +++ b/server/src/main/java/com/vaadin/legacy/ui/LegacyAbstractField.java @@ -1798,24 +1798,6 @@ public abstract class LegacyAbstractField<T> extends AbstractComponent } } - /** - * {@inheritDoc} - * <p> - * Fields are automatically set to immediate if validators have been added. - */ - @Override - public boolean isImmediate() { - if (getExplicitImmediateValue() != null) { - return getExplicitImmediateValue(); - } - // Make field immediate when there is some kind of validation present - // (validator or required). This will avoid the UI being in a wrong - // state, e.g. user entered valid data but old validation error is still - // shown - return super.isImmediate() || !getValidators().isEmpty() - || isRequired(); - } - /* * (non-Javadoc) * diff --git a/server/src/main/java/com/vaadin/ui/AbstractComponent.java b/server/src/main/java/com/vaadin/ui/AbstractComponent.java index 24f1ef098b..61cd991116 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractComponent.java +++ b/server/src/main/java/com/vaadin/ui/AbstractComponent.java @@ -39,9 +39,8 @@ import com.vaadin.event.ConnectorActionManager; import com.vaadin.event.ContextClickEvent; import com.vaadin.event.ContextClickEvent.ContextClickListener; import com.vaadin.event.ContextClickEvent.ContextClickNotifier; -import com.vaadin.legacy.ui.LegacyField; -import com.vaadin.legacy.ui.LegacyField.ValueChangeEvent; import com.vaadin.event.ShortcutListener; +import com.vaadin.legacy.ui.LegacyField; import com.vaadin.server.AbstractClientConnector; import com.vaadin.server.AbstractErrorMessage.ContentMode; import com.vaadin.server.ComponentSizeValidator; @@ -455,9 +454,7 @@ public abstract class AbstractComponent extends AbstractClientConnector /** * Returns the immediate mode of the component. * <p> - * Certain operations such as adding a value change listener will set the - * component into immediate mode if {@link #setImmediate(boolean)} has not - * been explicitly called with false. + * Since Vaadin 8, the default mode is immediate. * * @return true if the component is in immediate mode (explicitly or * implicitly set), false if the component if not in immediate mode @@ -465,14 +462,8 @@ public abstract class AbstractComponent extends AbstractClientConnector public boolean isImmediate() { if (explicitImmediateValue != null) { return explicitImmediateValue; - } else if (hasListeners(ValueChangeEvent.class)) { - /* - * Automatic immediate for fields that developers are interested - * about. - */ - return true; } else { - return false; + return true; } } diff --git a/server/src/main/java/com/vaadin/ui/Upload.java b/server/src/main/java/com/vaadin/ui/Upload.java index a61bcf1bd9..0a88b40215 100644 --- a/server/src/main/java/com/vaadin/ui/Upload.java +++ b/server/src/main/java/com/vaadin/ui/Upload.java @@ -1194,6 +1194,27 @@ public class Upload extends AbstractComponent implements Component.Focusable, return super.getListeners(eventType); } + /** + * Returns the immediate mode of the component. + * <p> + * An immediate mode Upload component displays the browser file choosing + * button immediately, whereas a non-immediate upload only shows a Vaadin + * button. + * <p> + * The default mode of an Upload component is non-immediate. + * + * @return true if the component is in immediate mode, false if the + * component if not in immediate mode + */ + @Override + public boolean isImmediate() { + if (getExplicitImmediateValue() != null) { + return getExplicitImmediateValue(); + } else { + return false; + } + } + @Override protected UploadState getState() { return (UploadState) super.getState(); diff --git a/server/src/test/java/com/vaadin/tests/server/component/abstractcomponent/AbstractComponentDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/abstractcomponent/AbstractComponentDeclarativeTest.java index 1588471395..42eccd5052 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/abstractcomponent/AbstractComponentDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/abstractcomponent/AbstractComponentDeclarativeTest.java @@ -1,12 +1,12 @@ /* * Copyright 2000-2014 Vaadin Ltd. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -46,7 +46,7 @@ import com.vaadin.ui.declarative.DesignContext; /** * Test cases for reading and writing the properties of AbstractComponent. - * + * * @since * @author Vaadin Ltd */ @@ -73,7 +73,7 @@ public class AbstractComponentDeclarativeTest extends public void testProperties() { String design = "<vaadin-label id=\"testId\" primary-style-name=\"test-style\" " + "caption=\"test-caption\" locale=\"fi_FI\" description=\"test-description\" " - + "error=\"<div>test-error</div>\" immediate />"; + + "error=\"<div>test-error</div>\" />"; component.setId("testId"); component.setPrimaryStyleName("test-style"); component.setCaption("test-caption"); @@ -97,7 +97,7 @@ public class AbstractComponentDeclarativeTest extends "<vaadin-label immediate />" }; Boolean[] explicitImmediate = { null, Boolean.FALSE, Boolean.TRUE, Boolean.TRUE }; - boolean[] immediate = { false, false, true, true }; + boolean[] immediate = { true, false, true, true }; for (int i = 0; i < design.length; i++) { component = (AbstractComponent) Design .read(new ByteArrayInputStream(design[i].getBytes(Charset diff --git a/server/src/test/java/com/vaadin/tests/server/component/abstractcomponent/AbstractComponentTest.java b/server/src/test/java/com/vaadin/tests/server/component/abstractcomponent/AbstractComponentTest.java new file mode 100644 index 0000000000..1cc48ee3e2 --- /dev/null +++ b/server/src/test/java/com/vaadin/tests/server/component/abstractcomponent/AbstractComponentTest.java @@ -0,0 +1,23 @@ +package com.vaadin.tests.server.component.abstractcomponent; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.vaadin.ui.AbstractComponent; + +public class AbstractComponentTest { + AbstractComponent component = new AbstractComponent() { + }; + + @Test + public void testImmediate() { + assertTrue("Component should be immediate by default", + component.isImmediate()); + component.setImmediate(false); + assertFalse( + "Explicitly non-immediate component should not be immediate", + component.isImmediate()); + } +} diff --git a/server/src/test/java/com/vaadin/tests/server/component/abstractfield/AbsFieldValidatorsTest.java b/server/src/test/java/com/vaadin/tests/server/component/abstractfield/AbsFieldValidatorsTest.java index 47e8bc5a0e..08d8770ac4 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/abstractfield/AbsFieldValidatorsTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/abstractfield/AbsFieldValidatorsTest.java @@ -69,15 +69,6 @@ public class AbsFieldValidatorsTest { } @Test - public void validatorShouldMakeImmediate() { - assertFalse("field should not be immediate by default", - field.isImmediate()); - field.addValidator(validator); - assertTrue("field should be immediate when it has a validator", - field.isImmediate()); - } - - @Test public void nonImmediateFieldWithValidator() { field.setImmediate(false); field.addValidator(validator); @@ -85,33 +76,4 @@ public class AbsFieldValidatorsTest { field.isImmediate()); } - @Test - public void removeValidatorMakesNonImmediate() { - field.addValidator(validator); - field.removeValidator(validator); - assertFalse( - "field should be non-immediate after validator was removed", - field.isImmediate()); - } - - @Test - public void requiredMakesImmediate() { - assertFalse("field should not be immediate by default", - field.isImmediate()); - field.setRequired(true); - assertTrue("field should be immediate when it is required", - field.isImmediate()); - } - - @Test - public void removeRequiredMakesNonImmediate() { - assertFalse("field should not be immediate by default", - field.isImmediate()); - field.setRequired(true); - field.setRequired(false); - assertFalse( - "field should not be immediate even though it was required", - field.isImmediate()); - } - } diff --git a/uitest/src/main/java/com/vaadin/tests/application/ResynchronizeAfterAsyncRemoval.java b/uitest/src/main/java/com/vaadin/tests/application/ResynchronizeAfterAsyncRemoval.java index d8f7fface3..bc6ef22c9a 100644 --- a/uitest/src/main/java/com/vaadin/tests/application/ResynchronizeAfterAsyncRemoval.java +++ b/uitest/src/main/java/com/vaadin/tests/application/ResynchronizeAfterAsyncRemoval.java @@ -16,6 +16,9 @@ public class ResynchronizeAfterAsyncRemoval extends AbstractTestUIWithLog { @Override public void setup(VaadinRequest vaadinRequest) { final Window window = new Window("Asynchronously removed window"); + // without this, the size info sent in the background removes the + // window immediately after showing it, making the test fail + setImmediate(false); window.center(); // The window will enqueue a non-immediate message reporting its current diff --git a/uitest/src/main/java/com/vaadin/tests/components/OutOfSync.java b/uitest/src/main/java/com/vaadin/tests/components/OutOfSync.java index 8cefffc9d1..a4f80c4cc1 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/OutOfSync.java +++ b/uitest/src/main/java/com/vaadin/tests/components/OutOfSync.java @@ -10,6 +10,10 @@ public class OutOfSync extends AbstractTestUI { @Override protected void setup(VaadinRequest request) { + // Without this, there is an extra request from the UI that changes the + // request sequence compared to what the test expects + setImmediate(false); + Button b = new Button("Click me after 1s to be out of sync"); b.addClickListener(new ClickListener() { diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DisabledParentLayout.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DisabledParentLayout.java index 49d88630a8..5ba158aef8 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DisabledParentLayout.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DisabledParentLayout.java @@ -1,12 +1,12 @@ /* * Copyright 2000-2014 Vaadin Ltd. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -22,7 +22,7 @@ import com.vaadin.ui.DateField; import com.vaadin.ui.VerticalLayout; /** - * + * * @author Vaadin Ltd */ public class DisabledParentLayout extends AbstractTestUI { @@ -35,7 +35,13 @@ public class DisabledParentLayout extends AbstractTestUI { content.setMargin(true); final VerticalLayout pane = new VerticalLayout(); - pane.addComponent(new DateField()); + DateField dateField = new DateField(); + // If the field is immediate, the UI behaves differently (the value is + // updated and an error is indicated earlier instead of showing the date + // selector on the first click as the test expects. Keeping as + // non-immediate to test the old expected behavior. + dateField.setImmediate(false); + pane.addComponent(dateField); content.addComponent(pane); diff --git a/uitest/src/main/java/com/vaadin/tests/components/notification/NotificationsWaiAria.java b/uitest/src/main/java/com/vaadin/tests/components/notification/NotificationsWaiAria.java index e85d60d7c2..fd0a6caf8e 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/notification/NotificationsWaiAria.java +++ b/uitest/src/main/java/com/vaadin/tests/components/notification/NotificationsWaiAria.java @@ -38,10 +38,15 @@ public class NotificationsWaiAria extends AbstractTestUI { @Override protected void setup(VaadinRequest request) { prefix = new TextField("Prefix", "Info"); + // The text fields need to be non-immediate to avoid an extra event that + // hides the notification while the test is still trying to read its + // contents. + prefix.setImmediate(false); addComponent(prefix); postfix = new TextField("Postfix", " - closes automatically after 10 seconds"); + postfix.setImmediate(false); addComponent(postfix); role = new NativeSelect("NotificationRole"); @@ -51,6 +56,7 @@ public class NotificationsWaiAria extends AbstractTestUI { addComponent(role); tf = new TextArea("Text", "Hello world"); + tf.setImmediate(false); tf.setRows(10); addComponent(tf); type = new ComboBox(); diff --git a/uitest/src/main/java/com/vaadin/tests/components/textfield/AutomaticImmediate.java b/uitest/src/main/java/com/vaadin/tests/components/textfield/AutomaticImmediate.java deleted file mode 100644 index ac51b5fc87..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/textfield/AutomaticImmediate.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright 2000-2014 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.tests.components.textfield; - -import com.vaadin.data.Property.ValueChangeEvent; -import com.vaadin.data.Property.ValueChangeListener; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUIWithLog; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.CheckBox; -import com.vaadin.ui.TextField; - -/** - * Test to verify fields become implicitly "immediate" when adding value change - * listener to them. - * - * @since 7.2 - * @author Vaadin Ltd - */ -public class AutomaticImmediate extends AbstractTestUIWithLog { - - /** - * - */ - static final String BUTTON = "button"; - /** - * - */ - static final String EXPLICIT_FALSE = "explicit-false"; - /** - * - */ - static final String FIELD = "field"; - /** - * - */ - static final String LISTENER_TOGGLE = "listener-toggle"; - - /* - * (non-Javadoc) - * - * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server. - * VaadinRequest) - */ - @Override - protected void setup(VaadinRequest request) { - - final TextField textField = new TextField() { - - /* - * (non-Javadoc) - * - * @see com.vaadin.ui.AbstractField#fireValueChange(boolean) - */ - @Override - protected void fireValueChange(boolean repaintIsNotNeeded) { - log("fireValueChange"); - super.fireValueChange(repaintIsNotNeeded); - } - }; - textField.setId(FIELD); - - final ValueChangeListener listener = new ValueChangeListener() { - - @Override - public void valueChange(ValueChangeEvent event) { - log("Value changed: " + event.getProperty().getValue()); - } - }; - - final CheckBox checkBox = new CheckBox("Toggle listener"); - checkBox.addValueChangeListener(new ValueChangeListener() { - - @Override - public void valueChange(ValueChangeEvent event) { - if (checkBox.getValue()) { - textField.addValueChangeListener(listener); - } else { - textField.removeValueChangeListener(listener); - } - } - }); - checkBox.setId(LISTENER_TOGGLE); - - Button b = new Button( - "setImmediate(false), sets explicitly false and causes server roundtrip", - new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - textField.setImmediate(false); - } - }); - b.setId(EXPLICIT_FALSE); - - Button b2 = new Button("Hit server, causes server roundtrip", - new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - } - }); - b2.setId(BUTTON); - - addComponent(textField); - addComponent(checkBox); - addComponent(b); - addComponent(b2); - - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription() - */ - @Override - protected String getTestDescription() { - return "Field should be immediate automatically if it has value change listener"; - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber() - */ - @Override - protected Integer getTicketNumber() { - return 8029; - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/textfield/AutomaticImmediateTest.java b/uitest/src/test/java/com/vaadin/tests/components/textfield/AutomaticImmediateTest.java deleted file mode 100644 index 4d750d183f..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/textfield/AutomaticImmediateTest.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2000-2014 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.tests.components.textfield; - -import org.apache.commons.lang.RandomStringUtils; -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.Keys; -import org.openqa.selenium.WebElement; - -import com.vaadin.tests.tb3.MultiBrowserTest; - -public class AutomaticImmediateTest extends MultiBrowserTest { - - /* - * (non-Javadoc) - * - * @see com.vaadin.tests.tb3.AbstractTB3Test#getUIClass() - */ - @Override - protected Class<?> getUIClass() { - return AutomaticImmediate.class; - } - - @Test - public void test() { - openTestURL(); - - WebElement field = getDriver().findElement( - By.id(AutomaticImmediate.FIELD)); - - WebElement toggle = getDriver().findElement( - By.xpath("//input[@type = 'checkbox']")); - - WebElement explicitFalseButton = getDriver().findElement( - By.id(AutomaticImmediate.EXPLICIT_FALSE)); - - WebElement hitServerButton = getDriver().findElement( - By.id(AutomaticImmediate.BUTTON)); - - String string = getRandomString(); - field.sendKeys(string + Keys.ENTER); - - // Non immediate, just the initial server side valuechange - assertLastLog("1. fireValueChange"); - - hitServerButton.click(); - - // No value change, but value sent to server - assertLastLog("2. fireValueChange"); - - // listener on -> immediate on - toggle.click(); - - string = getRandomString(); - String delSequence = "" + Keys.BACK_SPACE + Keys.BACK_SPACE; - field.sendKeys(delSequence + string + Keys.ENTER); - assertLastLog("4. Value changed: " + string); - - // listener off -> immediate off - String lastvalue = string; - toggle.click(); - string = getRandomString(); - field.sendKeys(delSequence + string + Keys.ENTER); - // No new value change should happen... - assertLastLog("4. Value changed: " + lastvalue); - hitServerButton.click(); - // ... but server should receive value with roundtrip - assertLastLog("5. fireValueChange"); - - // explicitly non immediate, but with listener - explicitFalseButton.click(); - toggle.click(); - - string = getRandomString(); - field.sendKeys(delSequence + string + Keys.ENTER); - // non immediate, no change... - assertLastLog("5. fireValueChange"); - // ... until server round trip - hitServerButton.click(); - assertLastLog("7. Value changed: " + string); - - } - - private String getRandomString() { - String string = RandomStringUtils.randomAlphanumeric(2); - return string; - } - - private void assertLastLog(String string) { - String text = getDriver().findElement(By.id("Log_row_0")).getText(); - Assert.assertEquals(string, text); - } - -} |