aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2015-04-08 13:40:49 +0300
committerMarkus Koivisto <markus@vaadin.com>2015-04-15 11:41:16 +0300
commitab6404f43fc5f9d6a9107307ee173d831a1397be (patch)
treef0443839606a9895ef2c507a76272b22bc8e5351 /server
parent8256a3a7c15a87b734bee6de18ee5a61bacca1f0 (diff)
downloadvaadin-framework-ab6404f43fc5f9d6a9107307ee173d831a1397be.tar.gz
vaadin-framework-ab6404f43fc5f9d6a9107307ee173d831a1397be.zip
Add DesignerAttributeHelper.readAttribute with default value (#17416)
Change-Id: Ic746e761942c3d801c8e1c71bd5866bbd5daeaf4
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java80
1 files changed, 51 insertions, 29 deletions
diff --git a/server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java b/server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java
index 215afd5041..be920a959e 100644
--- a/server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java
+++ b/server/src/com/vaadin/ui/declarative/DesignAttributeHandler.java
@@ -219,18 +219,68 @@ public class DesignAttributeHandler implements Serializable {
}
/**
- * Reads the given attribute from a set of attributes.
+ * Writes the given attribute value to a set of attributes if it differs
+ * from the default attribute value.
+ *
+ * @param attribute
+ * the attribute key
+ * @param attributes
+ * the set of attributes where the new attribute is written
+ * @param value
+ * the attribute value
+ * @param defaultValue
+ * the default attribute value
+ * @param inputType
+ * the type of the input value
+ */
+ public static <T> void writeAttribute(String attribute,
+ Attributes attributes, T value, T defaultValue, Class<T> inputType) {
+ if (!getFormatter().canConvert(inputType)) {
+ throw new IllegalArgumentException("input type: "
+ + inputType.getName() + " not supported");
+ }
+ if (!SharedUtil.equals(value, defaultValue)) {
+ String attributeValue = toAttributeValue(inputType, value);
+ attributes.put(attribute, attributeValue);
+ }
+ }
+
+ /**
+ * Reads the given attribute from a set of attributes. If attribute does not
+ * exist return a given default value.
*
* @param attribute
* the attribute key
* @param attributes
* the set of attributes to read from
+ * @param defaultValue
+ * the default value to return if attribute does not exist
* @param outputType
* the output type for the attribute
* @return the attribute value or the default value if the attribute is not
* found
*/
public static <T> T readAttribute(String attribute, Attributes attributes,
+ T defaultValue, Class<T> outputType) {
+ T value = readAttribute(attribute, attributes, outputType);
+ if (value != null) {
+ return value;
+ }
+ return defaultValue;
+ }
+
+ /**
+ * Reads the given attribute from a set of attributes.
+ *
+ * @param attribute
+ * the attribute key
+ * @param attributes
+ * the set of attributes to read from
+ * @param outputType
+ * the output type for the attribute
+ * @return the attribute value or null
+ */
+ public static <T> T readAttribute(String attribute, Attributes attributes,
Class<T> outputType) {
if (!getFormatter().canConvert(outputType)) {
throw new IllegalArgumentException("output type: "
@@ -250,33 +300,6 @@ public class DesignAttributeHandler implements Serializable {
}
/**
- * Writes the given attribute value to a set of attributes if it differs
- * from the default attribute value.
- *
- * @param attribute
- * the attribute key
- * @param attributes
- * the set of attributes where the new attribute is written
- * @param value
- * the attribute value
- * @param defaultValue
- * the default attribute value
- * @param inputType
- * the type of the input value
- */
- public static <T> void writeAttribute(String attribute,
- Attributes attributes, T value, T defaultValue, Class<T> inputType) {
- if (!getFormatter().canConvert(inputType)) {
- throw new IllegalArgumentException("input type: "
- + inputType.getName() + " not supported");
- }
- if (!SharedUtil.equals(value, defaultValue)) {
- String attributeValue = toAttributeValue(inputType, value);
- attributes.put(attribute, attributeValue);
- }
- }
-
- /**
* Returns the design attribute name corresponding the given method name.
* For example given a method name <code>setPrimaryStyleName</code> the
* return value would be <code>primary-style-name</code>
@@ -426,5 +449,4 @@ public class DesignAttributeHandler implements Serializable {
return (methods != null && methods.length > 1) ? methods[1] : null;
}
}
-
}