diff options
author | Artur Signell <artur@vaadin.com> | 2014-12-18 13:35:53 +0200 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2014-12-18 13:35:53 +0200 |
commit | 4e27233dbc454981b7a2f8e33697589c371e3238 (patch) | |
tree | 8f10338f4a01a632f27cdddc5bc2be600b541a97 /server | |
parent | 59df1753d6f1e3d9b28d4c9777353fb3b01aee0d (diff) | |
parent | dd8521407bb873a12d2c57100d6af5941b61fd6b (diff) | |
download | vaadin-framework-4e27233dbc454981b7a2f8e33697589c371e3238.tar.gz vaadin-framework-4e27233dbc454981b7a2f8e33697589c371e3238.zip |
Merge remote-tracking branch 'origin/master' into 7.4
Diffstat (limited to 'server')
-rw-r--r-- | server/src/com/vaadin/ui/AbstractComponent.java | 6 | ||||
-rw-r--r-- | server/src/com/vaadin/ui/CheckBox.java | 11 | ||||
-rw-r--r-- | server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java | 38 | ||||
-rw-r--r-- | server/tests/src/com/vaadin/ui/CheckBoxTest.java | 48 |
4 files changed, 74 insertions, 29 deletions
diff --git a/server/src/com/vaadin/ui/AbstractComponent.java b/server/src/com/vaadin/ui/AbstractComponent.java index a41d1b4056..46ad9a9c16 100644 --- a/server/src/com/vaadin/ui/AbstractComponent.java +++ b/server/src/com/vaadin/ui/AbstractComponent.java @@ -922,11 +922,11 @@ public abstract class AbstractComponent extends AbstractClientConnector Attributes attr = design.attributes(); // handle default attributes for (String attribute : getDefaultAttributes()) { - if (!design.hasAttr(attribute)) { - continue; + if (design.hasAttr(attribute)) { + DesignAttributeHandler.assignValue(this, attribute, + design.attr(attribute)); } - DesignAttributeHandler.readAttribute(this, attribute, attr); } // handle immediate if (attr.hasKey("immediate")) { diff --git a/server/src/com/vaadin/ui/CheckBox.java b/server/src/com/vaadin/ui/CheckBox.java index e26e5c4750..e98a2b61b9 100644 --- a/server/src/com/vaadin/ui/CheckBox.java +++ b/server/src/com/vaadin/ui/CheckBox.java @@ -253,4 +253,15 @@ public class CheckBox extends AbstractField<Boolean> { def.getValue(), Boolean.class); } + @Override + public void clear() { + setValue(Boolean.FALSE); + } + + @Override + public boolean isEmpty() { + return getValue() == null || getValue().equals(Boolean.FALSE); + + } + } diff --git a/server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java b/server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java index 1fc89c965d..be7d023ebf 100644 --- a/server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java +++ b/server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java @@ -87,48 +87,34 @@ public class DesignAttributeHandler implements Serializable { } /** - * Assigns the specified design attribute to the given component. If the - * attribute is not present, (value is null) the corresponding property is - * got from the <code>defaultInstance</code> + * Assigns the specified design attribute to the given component. * - * @param component - * the component to which the attribute should be set + * @param target + * the target to which the attribute should be set * @param attribute - * the attribute to be set - * @param attributes - * the attribute map. If the attributes does not contain the - * requested attribute, the value is retrieved from the - * <code> defaultInstance</code> + * the name of the attribute to be set + * @param value + * the string value of the attribute * @return true on success */ - public static boolean readAttribute(Component component, String attribute, - Attributes attributes) { - String value = null; - if (component == null || attribute == null || attributes == null) { + public static boolean assignValue(Object target, String attribute, + String value) { + if (target == null || attribute == null || value == null) { throw new IllegalArgumentException( "Parameters with null value not allowed"); } - if (attributes.hasKey(attribute)) { - value = attributes.get(attribute); - } boolean success = false; try { - Method setter = findSetterForAttribute(component.getClass(), - attribute); + Method setter = findSetterForAttribute(target.getClass(), attribute); if (setter == null) { // if we don't have the setter, there is no point in continuing success = false; - } else if (value != null) { + } else { // we have a value from design attributes, let's use that Object param = fromAttributeValue( setter.getParameterTypes()[0], value); - setter.invoke(component, param); + setter.invoke(target, param); success = true; - } else { - getLogger().log( - Level.WARNING, - "Attribute value for " + attribute - + " is null, this should not happen"); } } catch (Exception e) { getLogger().log(Level.WARNING, diff --git a/server/tests/src/com/vaadin/ui/CheckBoxTest.java b/server/tests/src/com/vaadin/ui/CheckBoxTest.java new file mode 100644 index 0000000000..7d699998de --- /dev/null +++ b/server/tests/src/com/vaadin/ui/CheckBoxTest.java @@ -0,0 +1,48 @@ +/* + * 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.ui; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.data.util.ObjectProperty; + +public class CheckBoxTest { + @Test + public void initiallyEmpty() { + CheckBox tf = new CheckBox(); + Assert.assertTrue(tf.isEmpty()); + } + + @Test + public void emptyAfterClearUsingPDS() { + CheckBox tf = new CheckBox(); + tf.setPropertyDataSource(new ObjectProperty<Boolean>(Boolean.TRUE)); + Assert.assertFalse(tf.isEmpty()); + tf.clear(); + Assert.assertTrue(tf.isEmpty()); + } + + @Test + public void emptyAfterClear() { + CheckBox tf = new CheckBox(); + tf.setValue(true); + Assert.assertFalse(tf.isEmpty()); + tf.clear(); + Assert.assertTrue(tf.isEmpty()); + } + +} |