Skip to content

Commit

Permalink
Make immediate mode the default
Browse files Browse the repository at this point in the history
Change-Id: I0a1fc0bf6f3de1b7d6975cd87cb7bb65c38dba4e
  • Loading branch information
Henri Sara committed Aug 11, 2016
1 parent 81b849c commit c726ae1
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 335 deletions.
18 changes: 0 additions & 18 deletions server/src/main/java/com/vaadin/legacy/ui/LegacyAbstractField.java
Expand Up @@ -1798,24 +1798,6 @@ private void removePropertyListeners() {
}
}

/**
* {@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)
*
Expand Down
15 changes: 3 additions & 12 deletions server/src/main/java/com/vaadin/ui/AbstractComponent.java
Expand Up @@ -39,9 +39,8 @@
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;
Expand Down Expand Up @@ -455,24 +454,16 @@ protected Boolean getExplicitImmediateValue() {
/**
* 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
*/
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;
}
}

Expand Down
21 changes: 21 additions & 0 deletions server/src/main/java/com/vaadin/ui/Upload.java
Expand Up @@ -1194,6 +1194,27 @@ public java.util.Collection<?> getListeners(java.lang.Class<?> eventType) {
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();
Expand Down
@@ -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
Expand Down Expand Up @@ -46,7 +46,7 @@

/**
* Test cases for reading and writing the properties of AbstractComponent.
*
*
* @since
* @author Vaadin Ltd
*/
Expand All @@ -73,7 +73,7 @@ public void testEmptyDesign() {
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");
Expand All @@ -97,7 +97,7 @@ public void testReadImmediate() {
"<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
Expand Down
@@ -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());
}
}
Expand Up @@ -68,15 +68,6 @@ public void testRemoveAllValidators() {
assertFalse(field.getValidators().contains(validator2));
}

@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);
Expand All @@ -85,33 +76,4 @@ public void nonImmediateFieldWithValidator() {
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());
}

}
Expand Up @@ -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
Expand Down
Expand Up @@ -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() {

Expand Down
@@ -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
Expand All @@ -22,7 +22,7 @@
import com.vaadin.ui.VerticalLayout;

/**
*
*
* @author Vaadin Ltd
*/
public class DisabledParentLayout extends AbstractTestUI {
Expand All @@ -35,7 +35,13 @@ protected void setup(VaadinRequest request) {
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);

Expand Down
Expand Up @@ -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");
Expand All @@ -51,6 +56,7 @@ protected void setup(VaadinRequest request) {
addComponent(role);

tf = new TextArea("Text", "Hello world");
tf.setImmediate(false);
tf.setRows(10);
addComponent(tf);
type = new ComboBox();
Expand Down

0 comments on commit c726ae1

Please sign in to comment.