]> source.dussan.org Git - vaadin-framework.git/commitdiff
Introduce "shouldWriteDefaultValues" property to DesignContext.
authorDenis Anisimov <denis@vaadin.com>
Mon, 24 Oct 2016 08:32:16 +0000 (11:32 +0300)
committerVaadin Code Review <review@vaadin.com>
Wed, 26 Oct 2016 05:59:27 +0000 (05:59 +0000)
Change-Id: I979448e5af032333a6a2f7b99b11ab16c41d7b18

36 files changed:
compatibility-server/src/main/java/com/vaadin/v7/ui/AbstractColorPicker.java
compatibility-server/src/main/java/com/vaadin/v7/ui/AbstractField.java
compatibility-server/src/main/java/com/vaadin/v7/ui/AbstractLegacyComponent.java
compatibility-server/src/main/java/com/vaadin/v7/ui/AbstractSelect.java
compatibility-server/src/main/java/com/vaadin/v7/ui/AbstractTextField.java
compatibility-server/src/main/java/com/vaadin/v7/ui/CheckBox.java
compatibility-server/src/main/java/com/vaadin/v7/ui/Grid.java
compatibility-server/src/main/java/com/vaadin/v7/ui/PasswordField.java
compatibility-server/src/main/java/com/vaadin/v7/ui/ProgressBar.java
compatibility-server/src/main/java/com/vaadin/v7/ui/Slider.java
compatibility-server/src/main/java/com/vaadin/v7/ui/Table.java
compatibility-server/src/main/java/com/vaadin/v7/ui/TextField.java
compatibility-server/src/main/java/com/vaadin/v7/ui/Tree.java
compatibility-server/src/main/java/com/vaadin/v7/ui/TreeTable.java
compatibility-server/src/test/java/com/vaadin/tests/server/ComponentDesignWriterUtility.java
server/src/main/java/com/vaadin/ui/AbstractColorPicker.java
server/src/main/java/com/vaadin/ui/AbstractComponent.java
server/src/main/java/com/vaadin/ui/AbstractEmbedded.java
server/src/main/java/com/vaadin/ui/AbstractField.java
server/src/main/java/com/vaadin/ui/AbstractLayout.java
server/src/main/java/com/vaadin/ui/AbstractMedia.java
server/src/main/java/com/vaadin/ui/AbstractTextField.java
server/src/main/java/com/vaadin/ui/Button.java
server/src/main/java/com/vaadin/ui/CheckBox.java
server/src/main/java/com/vaadin/ui/GridLayout.java
server/src/main/java/com/vaadin/ui/Link.java
server/src/main/java/com/vaadin/ui/MenuBar.java
server/src/main/java/com/vaadin/ui/PasswordField.java
server/src/main/java/com/vaadin/ui/ProgressBar.java
server/src/main/java/com/vaadin/ui/Slider.java
server/src/main/java/com/vaadin/ui/TabSheet.java
server/src/main/java/com/vaadin/ui/TextField.java
server/src/main/java/com/vaadin/ui/Video.java
server/src/main/java/com/vaadin/ui/Window.java
server/src/main/java/com/vaadin/ui/declarative/DesignAttributeHandler.java
server/src/main/java/com/vaadin/ui/declarative/DesignContext.java

index 668ffd568af00c57315c959d432d16ede4cb9c16..9f2224bed3b80cbcdf60119b6ca5b986244a4677 100644 (file)
@@ -572,12 +572,14 @@ public abstract class AbstractColorPicker extends AbstractLegacyComponent
 
         Attributes attribute = design.attributes();
         DesignAttributeHandler.writeAttribute("color", attribute,
-                color.getCSS(), Color.WHITE.getCSS(), String.class);
+                color.getCSS(), Color.WHITE.getCSS(), String.class,
+                designContext);
         DesignAttributeHandler.writeAttribute("popup-style", attribute,
                 popupStyle == PopupStyle.POPUP_NORMAL ? "normal" : "simple",
-                "normal", String.class);
+                "normal", String.class, designContext);
         DesignAttributeHandler.writeAttribute("position", attribute,
-                positionX + "," + positionY, "0,0", String.class);
+                positionX + "," + positionY, "0,0", String.class,
+                designContext);
     }
 
     @Override
index 8ac94f659223003d57ba36ad1ad0a8d236056540..eb6255e37a9dc0c530426f380c19fd5b2f09d44c 100644 (file)
@@ -1802,7 +1802,8 @@ public abstract class AbstractField<T> extends AbstractLegacyComponent
         Attributes attr = design.attributes();
         // handle readonly
         DesignAttributeHandler.writeAttribute("readonly", attr,
-                super.isReadOnly(), def.isReadOnly(), Boolean.class);
+                super.isReadOnly(), def.isReadOnly(), Boolean.class,
+                designContext);
     }
 
     private static final Logger getLogger() {
index 11ac3090897ab5471b870bc3e289b05fee5c20c7..28c1078de7327625189befe9bdecf6bf1e478365 100644 (file)
@@ -99,7 +99,8 @@ public class AbstractLegacyComponent extends AbstractComponent {
         // handle immediate
         if (explicitImmediateValue != null) {
             DesignAttributeHandler.writeAttribute("immediate", attr,
-                    explicitImmediateValue, def.isImmediate(), Boolean.class);
+                    explicitImmediateValue, def.isImmediate(), Boolean.class,
+                    designContext);
         }
     }
 
index 55962df2cfcf84e7d0f7b5bcbd8b23d519c4deba..127bdf6e7b9a31f992d20585f6292f483cedb8af 100644 (file)
@@ -2343,7 +2343,7 @@ public abstract class AbstractSelect extends AbstractField<Object> implements
         Resource icon = getItemIcon(itemId);
         if (icon != null) {
             DesignAttributeHandler.writeAttribute("icon", element.attributes(),
-                    icon, null, Resource.class);
+                    icon, null, Resource.class, context);
         }
 
         if (isSelected(itemId)) {
index 8a6b4849f8e6de59d67e5ca6f314839147b8d3cb..482dd0b2afcfba14c655e31ee16622b4db1b1a69 100644 (file)
@@ -806,7 +806,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements
                 .getDefaultInstance(this);
         Attributes attr = design.attributes();
         DesignAttributeHandler.writeAttribute("maxlength", attr, getMaxLength(),
-                def.getMaxLength(), Integer.class);
+                def.getMaxLength(), Integer.class, designContext);
     }
 
 }
index 779acb10eae446a90085fd18db41236e1548f1f9..d3c7b1a50c1bedf7967d7eab607852d9ecb05542 100644 (file)
@@ -252,7 +252,7 @@ public class CheckBox extends AbstractField<Boolean> {
         CheckBox def = (CheckBox) designContext.getDefaultInstance(this);
         Attributes attr = design.attributes();
         DesignAttributeHandler.writeAttribute("checked", attr, getValue(),
-                def.getValue(), Boolean.class);
+                def.getValue(), Boolean.class, designContext);
     }
 
     @Override
index e213d7d5851e8e918f8fd167fff85f276356209b..db4d75bbfce33e4ff3c89f891d54dd1ea1d97979 100644 (file)
@@ -3143,7 +3143,8 @@ public class Grid extends AbstractFocusable implements SelectionNotifier,
 
             if (section.grid.getDefaultHeaderRow() == this) {
                 DesignAttributeHandler.writeAttribute("default",
-                        trElement.attributes(), true, null, boolean.class);
+                        trElement.attributes(), true, null, boolean.class,
+                        designContext);
             }
         }
 
@@ -4071,31 +4072,35 @@ public class Grid extends AbstractFocusable implements SelectionNotifier,
             GridColumnState def = new GridColumnState();
 
             DesignAttributeHandler.writeAttribute("property-id", attributes,
-                    getPropertyId(), null, Object.class);
+                    getPropertyId(), null, Object.class, designContext);
 
             // Sortable is a special attribute that depends on the container.
             DesignAttributeHandler.writeAttribute("sortable", attributes,
-                    isSortable(), null, boolean.class);
+                    isSortable(), null, boolean.class, designContext);
             DesignAttributeHandler.writeAttribute("editable", attributes,
-                    isEditable(), def.editable, boolean.class);
+                    isEditable(), def.editable, boolean.class, designContext);
             DesignAttributeHandler.writeAttribute("resizable", attributes,
-                    isResizable(), def.resizable, boolean.class);
+                    isResizable(), def.resizable, boolean.class, designContext);
 
             DesignAttributeHandler.writeAttribute("hidable", attributes,
-                    isHidable(), def.hidable, boolean.class);
+                    isHidable(), def.hidable, boolean.class, designContext);
             DesignAttributeHandler.writeAttribute("hidden", attributes,
-                    isHidden(), def.hidden, boolean.class);
+                    isHidden(), def.hidden, boolean.class, designContext);
             DesignAttributeHandler.writeAttribute("hiding-toggle-caption",
-                    attributes, getHidingToggleCaption(), null, String.class);
+                    attributes, getHidingToggleCaption(), null, String.class,
+                    designContext);
 
             DesignAttributeHandler.writeAttribute("width", attributes,
-                    getWidth(), def.width, Double.class);
+                    getWidth(), def.width, Double.class, designContext);
             DesignAttributeHandler.writeAttribute("min-width", attributes,
-                    getMinimumWidth(), def.minWidth, Double.class);
+                    getMinimumWidth(), def.minWidth, Double.class,
+                    designContext);
             DesignAttributeHandler.writeAttribute("max-width", attributes,
-                    getMaximumWidth(), def.maxWidth, Double.class);
+                    getMaximumWidth(), def.maxWidth, Double.class,
+                    designContext);
             DesignAttributeHandler.writeAttribute("expand", attributes,
-                    getExpandRatio(), def.expandRatio, Integer.class);
+                    getExpandRatio(), def.expandRatio, Integer.class,
+                    designContext);
         }
 
         /**
@@ -7332,14 +7337,17 @@ public class Grid extends AbstractFocusable implements SelectionNotifier,
         Grid def = context.getDefaultInstance(this);
 
         DesignAttributeHandler.writeAttribute("editable", attrs,
-                isEditorEnabled(), def.isEditorEnabled(), boolean.class);
+                isEditorEnabled(), def.isEditorEnabled(), boolean.class,
+                context);
 
         DesignAttributeHandler.writeAttribute("frozen-columns", attrs,
-                getFrozenColumnCount(), def.getFrozenColumnCount(), int.class);
+                getFrozenColumnCount(), def.getFrozenColumnCount(), int.class,
+                context);
 
         if (getHeightMode() == HeightMode.ROW) {
             DesignAttributeHandler.writeAttribute("rows", attrs,
-                    getHeightByRows(), def.getHeightByRows(), double.class);
+                    getHeightByRows(), def.getHeightByRows(), double.class,
+                    context);
         }
 
         SelectionMode selectionMode = null;
@@ -7357,7 +7365,8 @@ public class Grid extends AbstractFocusable implements SelectionNotifier,
                 + selectionModel.getClass().getName();
 
         DesignAttributeHandler.writeAttribute("selection-mode", attrs,
-                selectionMode, getDefaultSelectionMode(), SelectionMode.class);
+                selectionMode, getDefaultSelectionMode(), SelectionMode.class,
+                context);
 
         if (columns.isEmpty()) {
             // Empty grid. Structure not needed.
index 787e024cc635db0f7f0d086942e1294e8530510d..cf00f64b8bca074c79e7e05d83e87ad0c2778e33 100644 (file)
@@ -112,7 +112,7 @@ public class PasswordField extends AbstractTextField {
                 .getDefaultInstance(this);
         Attributes attr = design.attributes();
         DesignAttributeHandler.writeAttribute("value", attr, getValue(),
-                def.getValue(), String.class);
+                def.getValue(), String.class, designContext);
     }
 
     @Override
index 14831d7d815d54f00b0c3f95eab2f23e25beccb7..12b02865771fa0093574551fbc40a0d0cd785354 100644 (file)
@@ -171,7 +171,7 @@ public class ProgressBar extends AbstractField<Float>
         Float defaultValue = ((ProgressBar) designContext
                 .getDefaultInstance(this)).getValue();
         DesignAttributeHandler.writeAttribute("value", design.attributes(),
-                getValue(), defaultValue, Float.class);
+                getValue(), defaultValue, Float.class, designContext);
     }
 
     @Override
index 15b083e38d9d24d206787d9cee26ce1eb03796a9..a898773f7c13544c12dc017850c787adde67ef60 100644 (file)
@@ -387,7 +387,7 @@ public class Slider extends AbstractField<Double> {
         }
         Slider defaultSlider = context.getDefaultInstance(this);
         DesignAttributeHandler.writeAttribute(this, "value",
-                design.attributes(), defaultSlider);
+                design.attributes(), defaultSlider, context);
     }
 
     @Override
index dc7b762c13f30d46e747dd46e3adb0f2980e2083..bc8f2eada461d223f1fb46be0c7d63f5142158d5 100644 (file)
@@ -6327,14 +6327,14 @@ public class Table extends AbstractSelect implements Action.Container,
         Table def = context.getDefaultInstance(this);
 
         DesignAttributeHandler.writeAttribute("sortable", design.attributes(),
-                isSortEnabled(), def.isSortEnabled(), boolean.class);
+                isSortEnabled(), def.isSortEnabled(), boolean.class, context);
 
         Element table = null;
         boolean hasColumns = getVisibleColumns().length != 0;
         if (hasColumns) {
             table = design.appendElement("table");
-            writeColumns(table, def);
-            writeHeader(table, def);
+            writeColumns(table, def, context);
+            writeHeader(table, def, context);
         }
         super.writeDesign(design, context);
         if (hasColumns) {
@@ -6342,7 +6342,7 @@ public class Table extends AbstractSelect implements Action.Container,
         }
     }
 
-    private void writeColumns(Element table, Table def) {
+    private void writeColumns(Element table, Table def, DesignContext context) {
         Object[] columns = getVisibleColumns();
         if (columns.length == 0) {
             return;
@@ -6361,23 +6361,24 @@ public class Table extends AbstractSelect implements Action.Container,
             }
 
             DesignAttributeHandler.writeAttribute("width", col.attributes(),
-                    getColumnWidth(id), def.getColumnWidth(null), int.class);
+                    getColumnWidth(id), def.getColumnWidth(null), int.class,
+                    context);
 
             DesignAttributeHandler.writeAttribute("expand", col.attributes(),
                     getColumnExpandRatio(id), def.getColumnExpandRatio(null),
-                    float.class);
+                    float.class, context);
 
             DesignAttributeHandler.writeAttribute("collapsible",
                     col.attributes(), isColumnCollapsible(id),
-                    def.isColumnCollapsible(null), boolean.class);
+                    def.isColumnCollapsible(null), boolean.class, context);
 
             DesignAttributeHandler.writeAttribute("collapsed", col.attributes(),
                     isColumnCollapsed(id), def.isColumnCollapsed(null),
-                    boolean.class);
+                    boolean.class, context);
         }
     }
 
-    private void writeHeader(Element table, Table def) {
+    private void writeHeader(Element table, Table def, DesignContext context) {
         Object[] columns = getVisibleColumns();
         if (columns.length == 0
                 || (columnIcons.isEmpty() && columnHeaders.isEmpty())) {
@@ -6389,7 +6390,8 @@ public class Table extends AbstractSelect implements Action.Container,
             Element th = header.appendElement("th");
             th.html(getColumnHeader(id));
             DesignAttributeHandler.writeAttribute("icon", th.attributes(),
-                    getColumnIcon(id), def.getColumnIcon(null), Resource.class);
+                    getColumnIcon(id), def.getColumnIcon(null), Resource.class,
+                    context);
         }
 
     }
index 2f958e629bbe8ee830e433ed60d2d2347d298993..d7f9d07b0bf6e981064035a4b0755b63a49d209b 100644 (file)
@@ -135,7 +135,7 @@ public class TextField extends AbstractTextField {
                 .getDefaultInstance(this);
         Attributes attr = design.attributes();
         DesignAttributeHandler.writeAttribute("value", attr, getValue(),
-                def.getValue(), String.class);
+                def.getValue(), String.class, designContext);
     }
 
     /*
index 9a3403e3d429abd7edd8894be521041d0a77c564..9be95578b4b7c7afa8810a1dcdb8bb755aef73ce 100644 (file)
@@ -1944,7 +1944,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
         Resource icon = getItemIcon(itemId);
         if (icon != null) {
             DesignAttributeHandler.writeAttribute("icon", element.attributes(),
-                    icon, null, Resource.class);
+                    icon, null, Resource.class, context);
         }
 
         if (isSelected(itemId)) {
index 41928830980c2af55c87ddeef730f951d151080f..e5b18472e8dc207898410e2eda58ed4cabfd3ce4 100644 (file)
@@ -962,7 +962,7 @@ public class TreeTable extends Table implements Hierarchical {
         for (Object itemId : itemIds) {
             Element tr = writeItem(tbody, itemId, context);
             DesignAttributeHandler.writeAttribute("depth", tr.attributes(),
-                    depth, 0, int.class);
+                    depth, 0, int.class, context);
 
             if (getChildren(itemId) != null) {
                 writeItems(tbody, getChildren(itemId), depth + 1, context);
@@ -975,7 +975,7 @@ public class TreeTable extends Table implements Hierarchical {
             DesignContext context) {
         Element tr = super.writeItem(tbody, itemId, context);
         DesignAttributeHandler.writeAttribute("collapsed", tr.attributes(),
-                isCollapsed(itemId), true, boolean.class);
+                isCollapsed(itemId), true, boolean.class, context);
         return tr;
     }
 
index 15ae1c9cf47056f4b01de9889a4cea8647698318..6009385ccca36f8b79e9af88afa9e0798a071686 100644 (file)
@@ -24,7 +24,6 @@ import com.vaadin.ui.components.colorpicker.ColorPickerPopup;
 import com.vaadin.ui.components.colorpicker.ColorPickerPreview;
 import com.vaadin.ui.components.colorpicker.ColorPickerSelect;
 import com.vaadin.ui.declarative.Design;
-import com.vaadin.ui.declarative.DesignAttributeHandler;
 import com.vaadin.ui.declarative.DesignContext;
 
 /**
@@ -33,6 +32,10 @@ import com.vaadin.ui.declarative.DesignContext;
 public class ComponentDesignWriterUtility {
 
     private static final Set<String> WHITE_LIST_FQNS = new HashSet<>();
+    private static final Document document = new Document("");
+    private static final DesignContext designContext = new DesignContext(
+            document);
+
     static {
         WHITE_LIST_FQNS.add(DragAndDropWrapper.class.getName());
         WHITE_LIST_FQNS.add(Navigator.EmptyView.class.getName());
@@ -86,11 +89,9 @@ public class ComponentDesignWriterUtility {
                 "com.vaadin.server.VaadinPortlet$VaadinWebSpherePortalRequest");
         WHITE_LIST_FQNS.add("com.vaadin.server.VaadinPortlet");
         WHITE_LIST_FQNS.add("com.vaadin.server.VaadinPortletRequest");
-    }
 
-    private static final Document document = new Document("");
-    private static final DesignContext designContext = new DesignContext(
-            document);
+        designContext.setShouldWriteDefaultValues(true);
+    }
 
     @SafeVarargs
     public static List<String> getDeclarativeSyntax(
@@ -100,13 +101,10 @@ public class ComponentDesignWriterUtility {
 
     public static List<String> getDeclarativeSyntax(
             List<Class<? extends Component>> components) {
-        DesignAttributeHandler.setWriteDefaultValues(true);
-
         List<String> declarativeStrings = components.stream()
                 .map(ComponentDesignWriterUtility::getDeclarativeSyntax)
                 .collect(Collectors.toList());
 
-        DesignAttributeHandler.setWriteDefaultValues(false);
         return declarativeStrings;
     }
 
@@ -156,10 +154,8 @@ public class ComponentDesignWriterUtility {
 
     private static void printFullDeclarativeSyntax(
             List<Class<? extends Component>> components) {
-        DesignAttributeHandler.setWriteDefaultValues(true);
         components.stream().forEach(component -> System.out
                 .println(getDeclarativeSyntax(component)));
-        DesignAttributeHandler.setWriteDefaultValues(false);
     }
 
     private static List<Class<? extends Component>> getVaadin8Components()
index a537df0b2139facb76a9a5c88d52b15e42cbe87f..b9503617987b1d417acd7b54add33d0b37ba7029 100644 (file)
@@ -514,12 +514,14 @@ public abstract class AbstractColorPicker extends AbstractField<Color> {
 
         Attributes attribute = design.attributes();
         DesignAttributeHandler.writeAttribute("color", attribute,
-                getValue().getCSS(), Color.WHITE.getCSS(), String.class);
+                getValue().getCSS(), Color.WHITE.getCSS(), String.class,
+                designContext);
         DesignAttributeHandler.writeAttribute("popup-style", attribute,
                 popupStyle == PopupStyle.POPUP_NORMAL ? "normal" : "simple",
-                "normal", String.class);
+                "normal", String.class, designContext);
         DesignAttributeHandler.writeAttribute("position", attribute,
-                positionX + "," + positionY, "0,0", String.class);
+                positionX + "," + positionY, "0,0", String.class,
+                designContext);
     }
 
     @Override
index 0681612996e54d027c8d67657d6b0f31e644b40c..94fa738dd352b4b948cc92030c7bb28a2035c20d 100644 (file)
@@ -1240,7 +1240,8 @@ public abstract class AbstractComponent extends AbstractClientConnector
         Attributes attr = design.attributes();
         // handle default attributes
         for (String attribute : getDefaultAttributes()) {
-            DesignAttributeHandler.writeAttribute(this, attribute, attr, def);
+            DesignAttributeHandler.writeAttribute(this, attribute, attr, def,
+                    designContext);
         }
         // handle locale
         if (getLocale() != null && (getParent() == null
@@ -1261,7 +1262,8 @@ public abstract class AbstractComponent extends AbstractClientConnector
         if (this instanceof Focusable) {
             DesignAttributeHandler.writeAttribute("tabindex", attr,
                     ((Focusable) this).getTabIndex(),
-                    ((Focusable) def).getTabIndex(), Integer.class);
+                    ((Focusable) def).getTabIndex(), Integer.class,
+                    designContext);
         }
         // handle custom attributes
         Map<String, String> customAttributes = designContext
index 978e82d4681380327fed7bdd718f4f9acb4069e5..a91332f9487e3b655c5799f4804dc98a8630b415 100644 (file)
@@ -100,7 +100,8 @@ public abstract class AbstractEmbedded extends AbstractComponent {
         super.writeDesign(design, designContext);
         AbstractEmbedded def = designContext.getDefaultInstance(this);
         DesignAttributeHandler.writeAttribute("alt", design.attributes(),
-                getAlternateText(), def.getAlternateText(), String.class);
+                getAlternateText(), def.getAlternateText(), String.class,
+                designContext);
     }
 
     @Override
index c87a72e4304e45ebdeefd48987d488dcb40794c0..4add30183eacd8e16405b5114ddada4ba2cf8b3e 100644 (file)
@@ -121,7 +121,8 @@ public abstract class AbstractField<T> extends AbstractComponent
         AbstractField<T> def = designContext.getDefaultInstance(this);
         Attributes attr = design.attributes();
         DesignAttributeHandler.writeAttribute("readonly", attr,
-                super.isReadOnly(), def.isReadOnly(), Boolean.class);
+                super.isReadOnly(), def.isReadOnly(), Boolean.class,
+                designContext);
     }
 
     @Override
index 3c31e59e2c1e894c92def646f94d8ce2808074e9..a4b4f06bf7469e0390e3d48b35ef331b5fd59a55 100644 (file)
@@ -102,24 +102,25 @@ public abstract class AbstractLayout extends AbstractComponentContainer
             MarginInfo defMargin, DesignContext context) {
         if (margin.hasAll()) {
             DesignAttributeHandler.writeAttribute("margin", design.attributes(),
-                    margin.hasAll(), defMargin.hasAll(), boolean.class);
+                    margin.hasAll(), defMargin.hasAll(), boolean.class,
+                    context);
         } else {
 
             DesignAttributeHandler.writeAttribute("margin-left",
                     design.attributes(), margin.hasLeft(), defMargin.hasLeft(),
-                    boolean.class);
+                    boolean.class, context);
 
             DesignAttributeHandler.writeAttribute("margin-right",
                     design.attributes(), margin.hasRight(),
-                    defMargin.hasRight(), boolean.class);
+                    defMargin.hasRight(), boolean.class, context);
 
             DesignAttributeHandler.writeAttribute("margin-top",
                     design.attributes(), margin.hasTop(), defMargin.hasTop(),
-                    boolean.class);
+                    boolean.class, context);
 
             DesignAttributeHandler.writeAttribute("margin-bottom",
                     design.attributes(), margin.hasBottom(),
-                    defMargin.hasBottom(), boolean.class);
+                    defMargin.hasBottom(), boolean.class, context);
         }
     }
 }
index f56f6a7f27cfad8726b820a93bdb251decc91579..a992554d67d724cb56e7ba0270075aca38488e05 100644 (file)
@@ -275,7 +275,7 @@ public abstract class AbstractMedia extends AbstractComponent {
         for (Resource r : getSources()) {
             Attributes attr = design.appendElement("source").attributes();
             DesignAttributeHandler.writeAttribute("href", attr, r, null,
-                    Resource.class);
+                    Resource.class, designContext);
         }
     }
 
index ee2ccc6604263afaf3d92f7fbeaf087ae318e83c..714f4b8e64242e12269ed293c5bc578ca7361d7d 100644 (file)
@@ -285,7 +285,7 @@ public abstract class AbstractTextField extends AbstractField<String>
                 .getDefaultInstance(this);
         Attributes attr = design.attributes();
         DesignAttributeHandler.writeAttribute("maxlength", attr, getMaxLength(),
-                def.getMaxLength(), Integer.class);
+                def.getMaxLength(), Integer.class, designContext);
     }
 
     @Override
index 499713ffbd2d696fcd81ef0fc9b6f146df677379..86321f357cd1bfb56170f1335c5cf0fac2af9492 100644 (file)
@@ -637,11 +637,11 @@ public class Button extends AbstractFocusable
         // icon-alt
         DesignAttributeHandler.writeAttribute("icon-alt", attr,
                 getIconAlternateText(), def.getIconAlternateText(),
-                String.class);
+                String.class, designContext);
         // click-shortcut
         if (clickShortcut != null) {
             DesignAttributeHandler.writeAttribute("click-shortcut", attr,
-                    clickShortcut, null, ShortcutAction.class);
+                    clickShortcut, null, ShortcutAction.class, designContext);
         }
     }
 }
index 02d7b0db8b185a861518036601851a2d6ff675ef..9a6394863e608d546cc8f6c1d619c7831e1496e1 100644 (file)
@@ -218,7 +218,7 @@ public class CheckBox extends AbstractField<Boolean>
         CheckBox def = (CheckBox) designContext.getDefaultInstance(this);
         Attributes attr = design.attributes();
         DesignAttributeHandler.writeAttribute("checked", attr, getValue(),
-                def.getValue(), Boolean.class);
+                def.getValue(), Boolean.class, designContext);
     }
 
 }
index 40b8575c36cec4c236811444f9521266e283d14e..08ca2cb2b30a043533a407e2f6d356254d14d5b8 100644 (file)
@@ -27,7 +27,6 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.Objects;
 import java.util.Set;
 
 import org.jsoup.nodes.Attributes;
@@ -1453,7 +1452,7 @@ public class GridLayout extends AbstractLayout
 
             // Row Expand
             DesignAttributeHandler.writeAttribute("expand", row.attributes(),
-                    (int) getRowExpandRatio(i), 0, int.class);
+                    (int) getRowExpandRatio(i), 0, int.class, designContext);
 
             int colspan = 1;
             Element col;
index 24c14339683d6b7c0e128c6f8bb739bed7fed490..b80e8cd2063564c129359a3a124bbfbf94df07cb 100644 (file)
@@ -226,9 +226,11 @@ public class Link extends AbstractComponent {
         super.writeDesign(design, designContext);
         Link def = designContext.getDefaultInstance(this);
         DesignAttributeHandler.writeAttribute("target", design.attributes(),
-                getTargetName(), def.getTargetName(), String.class);
+                getTargetName(), def.getTargetName(), String.class,
+                designContext);
         DesignAttributeHandler.writeAttribute("href", design.attributes(),
-                getResource(), def.getResource(), Resource.class);
+                getResource(), def.getResource(), Resource.class,
+                designContext);
     }
 
     @Override
index 24f2dd89b36894462a4468189af140d6f3b70e87..884c3d4eb3f27e917f1106a00c62bc330e647b32 100644 (file)
@@ -947,13 +947,14 @@ public class MenuBar extends AbstractComponent
     public void writeDesign(Element design, DesignContext designContext) {
         super.writeDesign(design, designContext);
         for (MenuItem item : getItems()) {
-            design.appendChild(createMenuElement(item));
+            design.appendChild(createMenuElement(item, designContext));
         }
 
         // in many cases there seems to be an empty more menu item
         if (getMoreMenuItem() != null
                 && !getMoreMenuItem().getText().isEmpty()) {
-            Element moreMenu = createMenuElement(getMoreMenuItem());
+            Element moreMenu = createMenuElement(getMoreMenuItem(),
+                    designContext);
             moreMenu.attr("more", true);
             design.appendChild(moreMenu);
         }
@@ -963,34 +964,35 @@ public class MenuBar extends AbstractComponent
         }
     }
 
-    protected Element createMenuElement(MenuItem item) {
+    protected Element createMenuElement(MenuItem item, DesignContext context) {
         Element menuElement = new Element(Tag.valueOf("menu"), "");
         // Defaults
         MenuItem def = new MenuItem("", null, null);
 
         Attributes attr = menuElement.attributes();
         DesignAttributeHandler.writeAttribute("icon", attr, item.getIcon(),
-                def.getIcon(), Resource.class);
+                def.getIcon(), Resource.class, context);
         DesignAttributeHandler.writeAttribute("disabled", attr,
-                !item.isEnabled(), !def.isEnabled(), boolean.class);
+                !item.isEnabled(), !def.isEnabled(), boolean.class, context);
         DesignAttributeHandler.writeAttribute("visible", attr, item.isVisible(),
-                def.isVisible(), boolean.class);
+                def.isVisible(), boolean.class, context);
         DesignAttributeHandler.writeAttribute("separator", attr,
-                item.isSeparator(), def.isSeparator(), boolean.class);
+                item.isSeparator(), def.isSeparator(), boolean.class, context);
         DesignAttributeHandler.writeAttribute("checkable", attr,
-                item.isCheckable(), def.isCheckable(), boolean.class);
+                item.isCheckable(), def.isCheckable(), boolean.class, context);
         DesignAttributeHandler.writeAttribute("checked", attr, item.isChecked(),
-                def.isChecked(), boolean.class);
+                def.isChecked(), boolean.class, context);
         DesignAttributeHandler.writeAttribute("description", attr,
-                item.getDescription(), def.getDescription(), String.class);
+                item.getDescription(), def.getDescription(), String.class,
+                context);
         DesignAttributeHandler.writeAttribute("style-name", attr,
-                item.getStyleName(), def.getStyleName(), String.class);
+                item.getStyleName(), def.getStyleName(), String.class, context);
 
         menuElement.append(item.getText());
 
         if (item.hasChildren()) {
             for (MenuItem subMenu : item.getChildren()) {
-                menuElement.appendChild(createMenuElement(subMenu));
+                menuElement.appendChild(createMenuElement(subMenu, context));
             }
         }
 
index 231236c01fdabef8da2ff1e1678eddd4720c5914..7a154b2b294662416744984b541162dd2ec1ed33 100644 (file)
@@ -76,6 +76,6 @@ public class PasswordField extends TextField {
                 .getDefaultInstance(this);
         Attributes attr = design.attributes();
         DesignAttributeHandler.writeAttribute("value", attr, getValue(),
-                def.getValue(), String.class);
+                def.getValue(), String.class, designContext);
     }
 }
index 7df0fc5f83f202821dd7e51b0ea8786b72207953..e5d82a62b05bb2399a597b79d26b18fda79b11fe 100644 (file)
@@ -126,7 +126,7 @@ public class ProgressBar extends AbstractComponent {
         Float defaultValue = ((ProgressBar) designContext
                 .getDefaultInstance(this)).getValue();
         DesignAttributeHandler.writeAttribute("value", design.attributes(),
-                getValue(), defaultValue, Float.class);
+                getValue(), defaultValue, Float.class, designContext);
     }
 
     /**
index 397e33e7c39ecf5d47efc1f758848164a2a129c3..3a1d77e38f1553e719cf429b360c6bd70831e1ec 100644 (file)
@@ -372,7 +372,7 @@ public class Slider extends AbstractField<Double> {
         }
         Slider defaultSlider = context.getDefaultInstance(this);
         DesignAttributeHandler.writeAttribute(this, "value",
-                design.attributes(), defaultSlider);
+                design.attributes(), defaultSlider, context);
     }
 
     @Override
index 7a154dd7528abd917353ead656836483d729092f..b19acf8ddb176585afc4e7ddf0475aa5887eebbb 100644 (file)
@@ -1556,29 +1556,32 @@ public class TabSheet extends AbstractComponentContainer
         Attributes attr = tabElement.attributes();
         // write attributes
         DesignAttributeHandler.writeAttribute("visible", attr, tab.isVisible(),
-                def.isVisible(), Boolean.class);
+                def.isVisible(), Boolean.class, designContext);
         DesignAttributeHandler.writeAttribute("closable", attr,
-                tab.isClosable(), def.isClosable(), Boolean.class);
+                tab.isClosable(), def.isClosable(), Boolean.class,
+                designContext);
         DesignAttributeHandler.writeAttribute("caption", attr, tab.getCaption(),
-                def.getCaption(), String.class);
+                def.getCaption(), String.class, designContext);
         DesignAttributeHandler.writeAttribute("enabled", attr, tab.isEnabled(),
-                def.isEnabled(), Boolean.class);
+                def.isEnabled(), Boolean.class, designContext);
         DesignAttributeHandler.writeAttribute("icon", attr, tab.getIcon(),
-                def.getIcon(), Resource.class);
+                def.getIcon(), Resource.class, designContext);
         DesignAttributeHandler.writeAttribute("icon-alt", attr,
                 tab.getIconAlternateText(), def.getIconAlternateText(),
-                String.class);
+                String.class, designContext);
         DesignAttributeHandler.writeAttribute("description", attr,
-                tab.getDescription(), def.getDescription(), String.class);
+                tab.getDescription(), def.getDescription(), String.class,
+                designContext);
         DesignAttributeHandler.writeAttribute("style-name", attr,
-                tab.getStyleName(), def.getStyleName(), String.class);
+                tab.getStyleName(), def.getStyleName(), String.class,
+                designContext);
         DesignAttributeHandler.writeAttribute("id", attr, tab.getId(),
-                def.getId(), String.class);
+                def.getId(), String.class, designContext);
         if (getSelectedTab() != null
                 && getSelectedTab().equals(tab.getComponent())) {
             // use write attribute to get consistent handling for boolean
             DesignAttributeHandler.writeAttribute("selected", attr, true, false,
-                    boolean.class);
+                    boolean.class, designContext);
         }
     }
 
index c01650fb60b16544e927849a5d7a31eecb78c08d..b6eec117954afa8cea05b643fa878ff101475d6f 100644 (file)
@@ -87,6 +87,6 @@ public class TextField extends AbstractTextField {
                 .getDefaultInstance(this);
         Attributes attr = design.attributes();
         DesignAttributeHandler.writeAttribute("value", attr, getValue(),
-                def.getValue(), String.class);
+                def.getValue(), String.class, designContext);
     }
 }
index a9c3f3e72966d8b8abdf6bba90e6effae91bf2c5..af0ef618a45171917296845fb46cc4bdbc326f6a 100644 (file)
@@ -118,7 +118,7 @@ public class Video extends AbstractMedia {
         if (getPoster() != null) {
             Attributes attr = design.appendElement("poster").attributes();
             DesignAttributeHandler.writeAttribute("href", attr, getPoster(),
-                    null, Resource.class);
+                    null, Resource.class, designContext);
         }
     }
 
index 82acf0ee6f42ad93dc7be608a9fdfa042dfb9b02..df06e5445735c08be693185cec660a9441a537b8 100644 (file)
@@ -1406,7 +1406,7 @@ public class Window extends Panel
         }
 
         DesignAttributeHandler.writeAttribute("position", design.attributes(),
-                getPosition(), def.getPosition(), String.class);
+                getPosition(), def.getPosition(), String.class, context);
 
         // Process keyboard shortcuts
         if (closeShortcuts.size() == 1 && hasCloseShortcut(KeyCode.ESCAPE)) {
@@ -1425,7 +1425,8 @@ public class Window extends Panel
 
             // Write everything except the last "," to the design
             DesignAttributeHandler.writeAttribute("close-shortcut",
-                    design.attributes(), attrString.trim(), null, String.class);
+                    design.attributes(), attrString.trim(), null, String.class,
+                    context);
         }
 
         for (Component c : getAssistiveDescription()) {
index 4d655e0cbf74238726fe257b4bac1e42d440a3b3..2eea59a046b27f8903fd44ab668fa64200cb41fd 100644 (file)
@@ -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)) {
index ecbd5e638c35dd19509a6c61ec8fc6c0fc4777c3..c8e794c46adfe946fa43dc5b24520990bb562a41 100644 (file)
@@ -94,6 +94,8 @@ public class DesignContext implements Serializable {
     // this cannot be static because of testability issues
     private Boolean legacyDesignPrefix = null;
 
+    private boolean shouldWriteDefaultValues = false;
+
     public DesignContext(Document doc) {
         this.doc = doc;
         // Initialize the mapping between prefixes and package names.
@@ -831,4 +833,31 @@ public class DesignContext implements Serializable {
         }
         map.put(attribute, value);
     }
+
+    /**
+     * Set whether default attribute values should be written by the
+     * {@code DesignAttributeHandler#writeAttribute(String, Attributes, Object, Object, Class, DesignContext)}
+     * method. Default is {@code false}.
+     *
+     * @since 8.0
+     * @param value
+     *            {@code true} to write default values of attributes,
+     *            {@code false} to disable writing of default values
+     */
+    public void setShouldWriteDefaultValues(boolean value) {
+        shouldWriteDefaultValues = value;
+    }
+
+    /**
+     * Determines whether default attribute values should be written by the
+     * {@code DesignAttributeHandler#writeAttribute(String, Attributes, Object, Object, Class, DesignContext)}
+     * method. Default is {@code false}.
+     *
+     * @since 8.0
+     * @return {@code true} if default values of attributes should be written,
+     *         otherwise {@code false}
+     */
+    public boolean shouldWriteDefaultValues() {
+        return shouldWriteDefaultValues;
+    }
 }