diff options
author | Johannes Dahlström <johannesd@vaadin.com> | 2015-03-23 12:10:07 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-03-24 09:04:25 +0000 |
commit | 2a671f2810dfb409cc4d30a1606868282d0925d3 (patch) | |
tree | ddc54f63c6dcbf82ced308659ed5a2b10869ebfe /server/src/com/vaadin/ui/CustomLayout.java | |
parent | 4f3397df74dc737a9c5592d5418e741433e20dee (diff) | |
download | vaadin-framework-2a671f2810dfb409cc4d30a1606868282d0925d3.tar.gz vaadin-framework-2a671f2810dfb409cc4d30a1606868282d0925d3.zip |
Fix declarative support for CustomLayout (#17210)
CustomLayout now has a public default constructor. If a template is not set
using one of the setters, a warning message is displayed like in the case where
the template file is specified but not found.
Change-Id: I5d56f24fafc5c82e6ab76dec393a0c25bd78aae5
Diffstat (limited to 'server/src/com/vaadin/ui/CustomLayout.java')
-rw-r--r-- | server/src/com/vaadin/ui/CustomLayout.java | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/server/src/com/vaadin/ui/CustomLayout.java b/server/src/com/vaadin/ui/CustomLayout.java index a9c266b0b9..ceb47e1e7a 100644 --- a/server/src/com/vaadin/ui/CustomLayout.java +++ b/server/src/com/vaadin/ui/CustomLayout.java @@ -23,12 +23,16 @@ import java.io.InputStreamReader; import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; +import org.jsoup.nodes.Element; + import com.vaadin.server.JsonPaintTarget; import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; import com.vaadin.shared.ui.customlayout.CustomLayoutState; +import com.vaadin.ui.declarative.DesignContext; /** * <p> @@ -71,8 +75,8 @@ public class CustomLayout extends AbstractLayout implements LegacyComponent { * {@link #setTemplateName(String)}, that makes layout fetch the template * from theme, or {@link #setTemplateContents(String)}. */ - protected CustomLayout() { - setWidth(100, UNITS_PERCENTAGE); + public CustomLayout() { + setWidth(100, Unit.PERCENTAGE); } /** @@ -305,4 +309,32 @@ public class CustomLayout extends AbstractLayout implements LegacyComponent { } } + @Override + public void readDesign(Element design, DesignContext designContext) { + super.readDesign(design, designContext); + + for (Element child : design.children()) { + + Component childComponent = designContext.readDesign(child); + + if (child.hasAttr(":location")) { + addComponent(childComponent, child.attr(":location")); + } else { + addComponent(childComponent); + } + } + } + + @Override + public void writeDesign(Element design, DesignContext designContext) { + super.writeDesign(design, designContext); + + for (Entry<String, Component> slot : slots.entrySet()) { + Element child = designContext.createElement(slot.getValue()); + if (slots.size() > 1 || !"".equals(slot.getKey())) { + child.attr(":location", slot.getKey()); + } + design.appendChild(child); + } + } } |