summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/ui/PopupView.java
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2015-03-25 14:31:32 +0200
committerTeemu Suo-Anttila <teemusa@vaadin.com>2015-04-07 10:52:11 +0300
commitac6e06d57972601b4172b06a59076323e086a8b9 (patch)
tree5c526fb890ca72398c09b334c1a6c51b0aa2dd17 /server/src/com/vaadin/ui/PopupView.java
parentcd0b326851630d762b9e71631ef26c0385d4c850 (diff)
downloadvaadin-framework-ac6e06d57972601b4172b06a59076323e086a8b9.tar.gz
vaadin-framework-ac6e06d57972601b4172b06a59076323e086a8b9.zip
Add declarative support for PopupView (#16334)
Change-Id: Ic5fb0238f538fd05bb6d6e37ddff3ec06175f782
Diffstat (limited to 'server/src/com/vaadin/ui/PopupView.java')
-rw-r--r--server/src/com/vaadin/ui/PopupView.java88
1 files changed, 75 insertions, 13 deletions
diff --git a/server/src/com/vaadin/ui/PopupView.java b/server/src/com/vaadin/ui/PopupView.java
index 2a2da26b62..12034cb56c 100644
--- a/server/src/com/vaadin/ui/PopupView.java
+++ b/server/src/com/vaadin/ui/PopupView.java
@@ -20,8 +20,13 @@ import java.lang.reflect.Method;
import java.util.Collections;
import java.util.Iterator;
+import org.jsoup.nodes.Element;
+import org.jsoup.nodes.Node;
+import org.jsoup.parser.Tag;
+
import com.vaadin.shared.ui.popupview.PopupViewServerRpc;
import com.vaadin.shared.ui.popupview.PopupViewState;
+import com.vaadin.ui.declarative.DesignContext;
/**
*
@@ -61,9 +66,15 @@ public class PopupView extends AbstractComponent implements HasComponents {
/* Constructors */
- private PopupView() {
+ /**
+ * This is an internal constructor. Use
+ * {@link PopupView#PopupView(String, Component)} instead.
+ */
+ @Deprecated
+ public PopupView() {
registerRpc(rpc);
setHideOnMouseOut(true);
+ setContent(createContent("", new Label("")));
}
/**
@@ -77,18 +88,7 @@ public class PopupView extends AbstractComponent implements HasComponents {
* the full, Component-type representation
*/
public PopupView(final java.lang.String small, final Component large) {
- this(new PopupView.Content() {
- @Override
- public java.lang.String getMinimizedValueAsHTML() {
- return small;
- }
-
- @Override
- public Component getPopupComponent() {
- return large;
- }
- });
-
+ this(createContent(small, large));
}
/**
@@ -104,6 +104,30 @@ public class PopupView extends AbstractComponent implements HasComponents {
}
/**
+ * Creates a Content from given text representation and popup content.
+ *
+ * @param minimizedValue
+ * text representation when popup is hidden
+ * @param popupContent
+ * popup content
+ * @return content with given data
+ */
+ protected static Content createContent(final String minimizedValue,
+ final Component popupContent) {
+ return new Content() {
+ @Override
+ public String getMinimizedValueAsHTML() {
+ return minimizedValue;
+ }
+
+ @Override
+ public Component getPopupComponent() {
+ return popupContent;
+ }
+ };
+ }
+
+ /**
* This method will replace the current content of the panel with a new one.
*
* @param newContent
@@ -233,6 +257,44 @@ public class PopupView extends AbstractComponent implements HasComponents {
}
@Override
+ public void readDesign(Element design, DesignContext designContext) {
+
+ // Read content first to avoid NPE when setting popup visible
+ Component popupContent = null;
+ String minimizedValue = "";
+ for (Node childNode : design.childNodes()) {
+ if (childNode instanceof Element) {
+ Element child = (Element) childNode;
+ if (child.tagName().equals("popup-content")) {
+ popupContent = designContext.readDesign(child.child(0));
+ } else {
+ minimizedValue += child.toString();
+ }
+ } else {
+ minimizedValue += childNode.toString();
+ }
+ }
+ setContent(createContent(minimizedValue.trim(), popupContent));
+
+ super.readDesign(design, designContext);
+ }
+
+ @Override
+ public void writeDesign(Element design, DesignContext designContext) {
+ super.writeDesign(design, designContext);
+
+ Element popupContent = new Element(Tag.valueOf("popup-content"), "");
+ popupContent.appendChild(designContext.createElement(content
+ .getPopupComponent()));
+
+ String minimizedHTML = content.getMinimizedValueAsHTML();
+ if (minimizedHTML != null && !minimizedHTML.isEmpty()) {
+ design.append(minimizedHTML);
+ }
+ design.appendChild(popupContent);
+ }
+
+ @Override
protected PopupViewState getState() {
return (PopupViewState) super.getState();
}