aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/main/java/com/vaadin/ui/declarative/DesignAttributeHandler.java
diff options
context:
space:
mode:
authorDenis Anisimov <denis@vaadin.com>2016-10-24 11:32:16 +0300
committerVaadin Code Review <review@vaadin.com>2016-10-26 05:59:27 +0000
commit9abe01a5881ae7fb43d2706ca9302aa68cc0221b (patch)
tree97b3fabfd917c5513b4adbce20b37af1a78dac87 /server/src/main/java/com/vaadin/ui/declarative/DesignAttributeHandler.java
parent5bc31e8267230fc4abfef34dcaa77ce5eae447b3 (diff)
downloadvaadin-framework-9abe01a5881ae7fb43d2706ca9302aa68cc0221b.tar.gz
vaadin-framework-9abe01a5881ae7fb43d2706ca9302aa68cc0221b.zip
Introduce "shouldWriteDefaultValues" property to DesignContext.
Change-Id: I979448e5af032333a6a2f7b99b11ab16c41d7b18
Diffstat (limited to 'server/src/main/java/com/vaadin/ui/declarative/DesignAttributeHandler.java')
-rw-r--r--server/src/main/java/com/vaadin/ui/declarative/DesignAttributeHandler.java30
1 files changed, 8 insertions, 22 deletions
diff --git a/server/src/main/java/com/vaadin/ui/declarative/DesignAttributeHandler.java b/server/src/main/java/com/vaadin/ui/declarative/DesignAttributeHandler.java
index 4d655e0cbf..2eea59a046 100644
--- a/server/src/main/java/com/vaadin/ui/declarative/DesignAttributeHandler.java
+++ b/server/src/main/java/com/vaadin/ui/declarative/DesignAttributeHandler.java
@@ -56,25 +56,10 @@ public class DesignAttributeHandler implements Serializable {
return Logger.getLogger(DesignAttributeHandler.class.getName());
}
- private static Map<Class<?>, AttributeCacheEntry> cache = new ConcurrentHashMap<>();
+ private final static Map<Class<?>, AttributeCacheEntry> cache = new ConcurrentHashMap<>();
// translates string <-> object
- private static DesignFormatter FORMATTER = new DesignFormatter();
-
- private static boolean writeDefaultValues = false;
-
- /**
- * Set whether default attribute values should be written by the
- * {@code DesignAttributeHandler#writeAttribute(String, Attributes, Object, Object, Class)}
- * method. Default is {@code false}.
- *
- * @param value
- * {@code true} to write default values of attributes,
- * {@code false} to disable writing of default values
- */
- public static void setWriteDefaultValues(boolean value) {
- writeDefaultValues = value;
- }
+ private final static DesignFormatter FORMATTER = new DesignFormatter();
/**
* Returns the currently used formatter. All primitive types and all types
@@ -212,7 +197,7 @@ public class DesignAttributeHandler implements Serializable {
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void writeAttribute(Object component, String attribute,
- Attributes attr, Object defaultInstance) {
+ Attributes attr, Object defaultInstance, DesignContext context) {
Method getter = findGetterForAttribute(component.getClass(), attribute);
if (getter == null) {
getLogger().warning(
@@ -223,7 +208,7 @@ public class DesignAttributeHandler implements Serializable {
Object value = getter.invoke(component);
Object defaultValue = getter.invoke(defaultInstance);
writeAttribute(attribute, attr, value, defaultValue,
- (Class) getter.getReturnType());
+ (Class) getter.getReturnType(), context);
} catch (Exception e) {
getLogger().log(Level.SEVERE,
"Failed to invoke getter for attribute " + attribute,
@@ -248,13 +233,14 @@ public class DesignAttributeHandler implements Serializable {
* the type of the input value
*/
public static <T> void writeAttribute(String attribute,
- Attributes attributes, T value, T defaultValue,
- Class<T> inputType) {
+ Attributes attributes, T value, T defaultValue, Class<T> inputType,
+ DesignContext context) {
if (!getFormatter().canConvert(inputType)) {
throw new IllegalArgumentException(
"input type: " + inputType.getName() + " not supported");
}
- if (writeDefaultValues || !SharedUtil.equals(value, defaultValue)) {
+ if (context.shouldWriteDefaultValues()
+ || !SharedUtil.equals(value, defaultValue)) {
String attributeValue = toAttributeValue(inputType, value);
if ("".equals(attributeValue) && (inputType == boolean.class
|| inputType == Boolean.class)) {