diff options
author | Artur Signell <artur@vaadin.com> | 2015-02-05 01:35:09 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-02-05 13:28:06 +0000 |
commit | 620658687ec206bd3a631132e512b3e307890374 (patch) | |
tree | 393795d1be016129efcc223c6d1a79f218b7e8b8 /server/src/com/vaadin/ui/AbstractSelect.java | |
parent | 3c0a9961b0965b8cd0d88af8f3f4971c09ab271a (diff) | |
download | vaadin-framework-620658687ec206bd3a631132e512b3e307890374.tar.gz vaadin-framework-620658687ec206bd3a631132e512b3e307890374.zip |
Declarative support for AbstractSelect (#15545)
Change-Id: Ie66ee3f2b02ce7b6aa2edb66176bfbf5bdcd6c33
Diffstat (limited to 'server/src/com/vaadin/ui/AbstractSelect.java')
-rw-r--r-- | server/src/com/vaadin/ui/AbstractSelect.java | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/server/src/com/vaadin/ui/AbstractSelect.java b/server/src/com/vaadin/ui/AbstractSelect.java index 423ebcb46a..06790ca78d 100644 --- a/server/src/com/vaadin/ui/AbstractSelect.java +++ b/server/src/com/vaadin/ui/AbstractSelect.java @@ -29,6 +29,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.jsoup.nodes.Element; + import com.vaadin.data.Container; import com.vaadin.data.Item; import com.vaadin.data.Property; @@ -49,6 +51,9 @@ import com.vaadin.server.PaintTarget; import com.vaadin.server.Resource; import com.vaadin.shared.ui.combobox.FilteringMode; import com.vaadin.shared.ui.dd.VerticalDropLocation; +import com.vaadin.ui.declarative.DesignAttributeHandler; +import com.vaadin.ui.declarative.DesignContext; +import com.vaadin.ui.declarative.DesignException; /** * <p> @@ -2181,4 +2186,40 @@ public abstract class AbstractSelect extends AbstractField<Object> implements public String generateDescription(Component source, Object itemId, Object propertyId); } -} + + @Override + public void readDesign(Element design, DesignContext designContext) { + // handle default attributes + super.readDesign(design, designContext); + // handle children specifying selectable items (<option>) + Set<String> selected = new HashSet<String>(); + for (Element child : design.children()) { + if (!"option".equals(child.nodeName())) { + throw new DesignException( + "Unsupported child element in a select: " + + child.nodeName() + "."); + } + String itemId = child.html(); + addItem(itemId); + if (child.hasAttr("icon")) { + setItemIcon( + itemId, + DesignAttributeHandler.readAttribute("icon", + child.attributes(), Resource.class)); + } + if (child.hasAttr("selected")) { + selected.add(itemId); + } + } + if (!selected.isEmpty()) { + if (isMultiSelect()) { + setValue(selected); + } else if (selected.size() == 1) { + setValue(selected.iterator().next()); + } else { + throw new DesignException( + "Multiple values selected for a single select component"); + } + } + } +}
\ No newline at end of file |