diff options
author | Mika Murtojarvi <mika@vaadin.com> | 2014-12-10 11:24:58 +0200 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2014-12-12 10:53:36 +0000 |
commit | e09ba97f64c19d5efcd2d99b7ebf9b7dfef144d7 (patch) | |
tree | 7cc1e42e9d46d1397e5199a33b4d7b6ba97a9b25 /server/src | |
parent | 7a73e9bd3bf469e4e16acfa0d7d2eb5a496de47a (diff) | |
download | vaadin-framework-e09ba97f64c19d5efcd2d99b7ebf9b7dfef144d7.tar.gz vaadin-framework-e09ba97f64c19d5efcd2d99b7ebf9b7dfef144d7.zip |
Declarative: add support for Panel (#7749).
Change-Id: I4e6414e2fd4941215a788f518862ce58f38f005f
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/com/vaadin/ui/AbstractSingleComponentContainer.java | 53 | ||||
-rw-r--r-- | server/src/com/vaadin/ui/Panel.java | 33 |
2 files changed, 85 insertions, 1 deletions
diff --git a/server/src/com/vaadin/ui/AbstractSingleComponentContainer.java b/server/src/com/vaadin/ui/AbstractSingleComponentContainer.java index e7b5205f2d..c6e78447d5 100644 --- a/server/src/com/vaadin/ui/AbstractSingleComponentContainer.java +++ b/server/src/com/vaadin/ui/AbstractSingleComponentContainer.java @@ -18,9 +18,13 @@ package com.vaadin.ui; import java.util.Collections; import java.util.Iterator; +import org.jsoup.nodes.Element; + import com.vaadin.server.ComponentSizeValidator; import com.vaadin.server.VaadinService; import com.vaadin.server.VaadinSession; +import com.vaadin.ui.declarative.DesignContext; +import com.vaadin.ui.declarative.DesignException; /** * Abstract base class for component containers that have only one child @@ -274,4 +278,51 @@ public abstract class AbstractSingleComponentContainer extends repaintChangedChildTree(dirtyChild, childrenMayBecomeUndefined, true); } -} + /* + * (non-Javadoc) + * + * @see + * com.vaadin.ui.AbstractComponent#synchronizeFromDesign(org.jsoup.nodes + * .Element, com.vaadin.ui.declarative.DesignContext) + */ + @Override + public void synchronizeFromDesign(Element design, + DesignContext designContext) { + // process default attributes + super.synchronizeFromDesign(design, designContext); + // handle child element, checking that the design specifies at most one + // child + int childCount = design.children().size(); + if (childCount > 1) { + throw new DesignException("The container of type " + + getClass().toString() + + " can have only one child component."); + } else if (childCount == 1) { + Element childElement = design.children().get(0); + DesignSynchronizable newChild = designContext + .createChild(childElement); + setContent(newChild); + } else { + setContent(null); + } + } + + /* + * (non-Javadoc) + * + * @see + * com.vaadin.ui.AbstractComponent#synchronizeToDesign(org.jsoup.nodes.Element + * , com.vaadin.ui.declarative.DesignContext) + */ + @Override + public void synchronizeToDesign(Element design, DesignContext designContext) { + // synchronize default attributes (also clears children and attributes) + super.synchronizeToDesign(design, designContext); + // handle child component + DesignSynchronizable child = (DesignSynchronizable) getContent(); + if (child != null) { + Element childNode = designContext.createNode(child); + design.appendChild(childNode); + } + } +}
\ No newline at end of file diff --git a/server/src/com/vaadin/ui/Panel.java b/server/src/com/vaadin/ui/Panel.java index 9b1d8fd5fa..46ad801a6d 100644 --- a/server/src/com/vaadin/ui/Panel.java +++ b/server/src/com/vaadin/ui/Panel.java @@ -16,8 +16,11 @@ package com.vaadin.ui; +import java.util.Collection; import java.util.Map; +import org.jsoup.nodes.Element; + import com.vaadin.event.Action; import com.vaadin.event.Action.Handler; import com.vaadin.event.ActionManager; @@ -31,6 +34,8 @@ import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.ui.panel.PanelServerRpc; import com.vaadin.shared.ui.panel.PanelState; import com.vaadin.ui.Component.Focusable; +import com.vaadin.ui.declarative.DesignAttributeHandler; +import com.vaadin.ui.declarative.DesignContext; /** * Panel - a simple single component container. @@ -339,4 +344,32 @@ public class Panel extends AbstractSingleComponentContainer implements return (PanelState) super.getState(markAsDirty); } + @Override + public void synchronizeFromDesign(Element design, + DesignContext designContext) { + super.synchronizeFromDesign(design, designContext); + // handle tabindex + Panel def = designContext.getDefaultInstance(this.getClass()); + int tabIndex = DesignAttributeHandler.readAttribute("tabindex", + design.attributes(), def.getTabIndex(), Integer.class); + setTabIndex(tabIndex); + } + + @Override + protected Collection<String> getCustomAttributes() { + Collection<String> attributes = super.getCustomAttributes(); + attributes.add("tabindex"); + attributes.add("tab-index"); + return attributes; + } + + @Override + public void synchronizeToDesign(Element design, DesignContext designContext) { + super.synchronizeToDesign(design, designContext); + // handle tabindex + Panel def = designContext.getDefaultInstance(this.getClass()); + DesignAttributeHandler.writeAttribute("tabindex", design.attributes(), + getTabIndex(), def.getTabIndex(), Integer.class); + } + } |