From 9f98c3e1ba3a3e4249ac388a2d38c05a5349404d Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Thu, 18 Dec 2014 10:34:16 +0200 Subject: [PATCH] Minor declarative API improvement (#7749) Change-Id: Id5b11b27e7750085d30d2fa592b124ae474d6e9a --- .../src/com/vaadin/ui/AbstractComponent.java | 6 +-- .../declarative/DesignAttributeHandler.java | 38 ++++++------------- 2 files changed, 15 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/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 defaultInstance + * 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 - * defaultInstance + * 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, -- 2.39.5