aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2014-12-13 12:12:12 +0200
committerArtur Signell <artur@vaadin.com>2014-12-14 21:24:26 +0200
commit3f7c75415bc73ab750f809bde0c5da02f5d8e7c2 (patch)
treeab81704a3c74a6ee6d4f5e431c220eaa155050a7 /server
parent2789f701678106e9f5141b096706ace0d6880780 (diff)
downloadvaadin-framework-3f7c75415bc73ab750f809bde0c5da02f5d8e7c2.tar.gz
vaadin-framework-3f7c75415bc73ab750f809bde0c5da02f5d8e7c2.zip
Support plain-text attribute for Label (#7749)
Change-Id: I4ef210d131f1e616b501468cb94ea518945a3b30
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/ui/AbstractComponent.java2
-rw-r--r--server/src/com/vaadin/ui/Button.java6
-rw-r--r--server/src/com/vaadin/ui/Label.java10
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/button/TestSynchronizeToDesign.java13
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/label/TestSynchronizeToDesign.java43
5 files changed, 68 insertions, 6 deletions
diff --git a/server/src/com/vaadin/ui/AbstractComponent.java b/server/src/com/vaadin/ui/AbstractComponent.java
index 1cda253b01..808b70386f 100644
--- a/server/src/com/vaadin/ui/AbstractComponent.java
+++ b/server/src/com/vaadin/ui/AbstractComponent.java
@@ -111,6 +111,8 @@ public abstract class AbstractComponent extends AbstractClientConnector
private Boolean explicitImmediateValue;
+ protected static final String DESIGN_ATTR_PLAIN_TEXT = "plain-text";
+
/* Constructor */
/**
diff --git a/server/src/com/vaadin/ui/Button.java b/server/src/com/vaadin/ui/Button.java
index 82666613bb..9a754c24d9 100644
--- a/server/src/com/vaadin/ui/Button.java
+++ b/server/src/com/vaadin/ui/Button.java
@@ -686,7 +686,7 @@ public class Button extends AbstractComponent implements
def.getTabIndex(), Integer.class));
// plain-text (default is html)
setHtmlContentAllowed(!DesignAttributeHandler.readAttribute(
- "plain-text", attr, false, Boolean.class));
+ DESIGN_ATTR_PLAIN_TEXT, attr, false, Boolean.class));
setIconAlternateText(DesignAttributeHandler.readAttribute("icon-alt",
attr, def.getIconAlternateText(), String.class));
// click-shortcut
@@ -707,7 +707,7 @@ public class Button extends AbstractComponent implements
protected Collection<String> getCustomAttributes() {
Collection<String> result = super.getCustomAttributes();
result.add("tabindex");
- result.add("plain-text");
+ result.add(DESIGN_ATTR_PLAIN_TEXT);
result.add("caption");
result.add("icon-alt");
result.add("click-shortcut");
@@ -736,7 +736,7 @@ public class Button extends AbstractComponent implements
def.getTabIndex(), Integer.class);
// plain-text (default is html)
if (!isHtmlContentAllowed()) {
- design.attr("plain-text", "");
+ design.attr(DESIGN_ATTR_PLAIN_TEXT, "");
}
// icon-alt
DesignAttributeHandler.writeAttribute("icon-alt", attr,
diff --git a/server/src/com/vaadin/ui/Label.java b/server/src/com/vaadin/ui/Label.java
index a4d9da752d..f882940fe6 100644
--- a/server/src/com/vaadin/ui/Label.java
+++ b/server/src/com/vaadin/ui/Label.java
@@ -590,6 +590,11 @@ public class Label extends AbstractComponent implements Property<String>,
if (innerHtml != null && !"".equals(innerHtml)) {
setValue(innerHtml);
}
+ if (design.hasAttr(DESIGN_ATTR_PLAIN_TEXT)) {
+ setContentMode(ContentMode.TEXT);
+ } else {
+ setContentMode(ContentMode.HTML);
+ }
}
/*
@@ -601,6 +606,7 @@ public class Label extends AbstractComponent implements Property<String>,
protected Collection<String> getCustomAttributes() {
Collection<String> result = super.getCustomAttributes();
result.add("value");
+ result.add("content-mode");
return result;
}
@@ -618,5 +624,9 @@ public class Label extends AbstractComponent implements Property<String>,
if (content != null) {
design.html(getValue());
}
+ // plain-text (default is html)
+ if (getContentMode() == ContentMode.TEXT) {
+ design.attr(DESIGN_ATTR_PLAIN_TEXT, "");
+ }
}
}
diff --git a/server/tests/src/com/vaadin/tests/server/component/button/TestSynchronizeToDesign.java b/server/tests/src/com/vaadin/tests/server/component/button/TestSynchronizeToDesign.java
index 7e9d673f35..c96fd36d5d 100644
--- a/server/tests/src/com/vaadin/tests/server/component/button/TestSynchronizeToDesign.java
+++ b/server/tests/src/com/vaadin/tests/server/component/button/TestSynchronizeToDesign.java
@@ -66,6 +66,19 @@ public class TestSynchronizeToDesign extends TestCase {
assertEquals("ctrl-shift-o", e.attr("click-shortcut"));
}
+ @Test
+ public void testUpdateContentMode() {
+ Button button = new Button("OK");
+ Element e = new Element(Tag.valueOf("v-button"), "", new Attributes());
+ button.synchronizeToDesign(e, ctx);
+ assertTrue("Button is plain text by default", e.hasAttr("plain-text"));
+
+ button.setHtmlContentAllowed(true);
+ button.synchronizeToDesign(e, ctx);
+ assertTrue("Button is updated to HTML", !e.hasAttr("plain-text"));
+
+ }
+
private void createAndTestButtons(String content) {
Button b1 = new Button(content);
// we need to set this on, since the plain-text attribute will appear
diff --git a/server/tests/src/com/vaadin/tests/server/component/label/TestSynchronizeToDesign.java b/server/tests/src/com/vaadin/tests/server/component/label/TestSynchronizeToDesign.java
index 462e6a087b..869546ac3d 100644
--- a/server/tests/src/com/vaadin/tests/server/component/label/TestSynchronizeToDesign.java
+++ b/server/tests/src/com/vaadin/tests/server/component/label/TestSynchronizeToDesign.java
@@ -17,9 +17,12 @@ package com.vaadin.tests.server.component.label;
import junit.framework.TestCase;
+import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Element;
+import org.jsoup.parser.Tag;
import org.junit.Test;
+import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Label;
import com.vaadin.ui.declarative.DesignContext;
@@ -57,6 +60,43 @@ public class TestSynchronizeToDesign extends TestCase {
}
@Test
+ public void testContentModeText() {
+ Label l = new Label("plain text label");
+ Element e = new Element(Tag.valueOf("v-label"), "", new Attributes());
+ l.synchronizeToDesign(e, ctx);
+ assertTrue("Label should be marked as plain text",
+ e.hasAttr("plain-text"));
+ }
+
+ @Test
+ public void testContentModeHtml() {
+ Label l = new Label("html label");
+ l.setContentMode(ContentMode.HTML);
+
+ Element e = new Element(Tag.valueOf("v-label"), "", new Attributes());
+ l.synchronizeToDesign(e, ctx);
+ assertFalse("Label should not be marked as plain text",
+ e.hasAttr("plain-text"));
+ }
+
+ @Test
+ public void testChangeContentMode() {
+ Label l = new Label("html label");
+ l.setContentMode(ContentMode.HTML);
+
+ Element e = new Element(Tag.valueOf("v-label"), "", new Attributes());
+ l.synchronizeToDesign(e, ctx);
+
+ assertFalse("Label should not be marked as plain text",
+ e.hasAttr("plain-text"));
+ l.setContentMode(ContentMode.TEXT);
+ l.synchronizeToDesign(e, ctx);
+
+ assertTrue("Label should be marked as plain text",
+ e.hasAttr("plain-text"));
+ }
+
+ @Test
public void testWithoutContentAndCaption() {
createAndTestLabel(null, null);
}
@@ -75,9 +115,6 @@ public class TestSynchronizeToDesign extends TestCase {
assertTrue("Unexpected content in the v-label element.",
e.html() == null || "".equals(e.html()));
}
- int numAttributes = (caption == null ? 0 : 1);
- assertEquals("Wrong number of attributes in v-label.", numAttributes, e
- .attributes().size());
if (caption != null) {
assertEquals("Wrong caption in the v-label element.", caption,
e.attr("caption"));