Fixes vaadin/framework8-issues#525tags/8.0.0.alpha9
* @param htmlContentAllowed | * @param htmlContentAllowed | ||||
* <code>true</code> if caption is rendered as HTML, | * <code>true</code> if caption is rendered as HTML, | ||||
* <code>false</code> otherwise | * <code>false</code> otherwise | ||||
* | |||||
* @deprecated as of 8.0.0, use {@link #setCaptionAsHtml(boolean)} instead. | |||||
*/ | */ | ||||
@Deprecated | |||||
public void setHtmlContentAllowed(boolean htmlContentAllowed) { | public void setHtmlContentAllowed(boolean htmlContentAllowed) { | ||||
getState().captionAsHtml = htmlContentAllowed; | getState().captionAsHtml = htmlContentAllowed; | ||||
} | } | ||||
* | * | ||||
* @return <code>true</code> if the caption text is to be rendered as HTML, | * @return <code>true</code> if the caption text is to be rendered as HTML, | ||||
* <code>false</code> otherwise | * <code>false</code> otherwise | ||||
* | |||||
* @deprecated as of 8.0.0, use {@link #isCaptionAsHtml()} instead. | |||||
*/ | */ | ||||
@Deprecated | |||||
public boolean isHtmlContentAllowed() { | public boolean isHtmlContentAllowed() { | ||||
return getState(false).captionAsHtml; | return getState(false).captionAsHtml; | ||||
} | } | ||||
Boolean plain = DesignAttributeHandler | Boolean plain = DesignAttributeHandler | ||||
.readAttribute(DESIGN_ATTR_PLAIN_TEXT, attr, Boolean.class); | .readAttribute(DESIGN_ATTR_PLAIN_TEXT, attr, Boolean.class); | ||||
if (plain == null || !plain) { | if (plain == null || !plain) { | ||||
setHtmlContentAllowed(true); | |||||
setCaptionAsHtml(true); | |||||
content = design.html(); | content = design.html(); | ||||
} else { | } else { | ||||
// content is not intended to be interpreted as HTML, | // content is not intended to be interpreted as HTML, |
Assert.assertEquals(expectedCaptionHtml, nativeButton.getCaption()); | Assert.assertEquals(expectedCaptionHtml, nativeButton.getCaption()); | ||||
read = new Button("& Test"); | read = new Button("& Test"); | ||||
read.setHtmlContentAllowed(true); | |||||
read.setCaptionAsHtml(true); | |||||
Element root = new Element(Tag.valueOf("vaadin-button"), ""); | Element root = new Element(Tag.valueOf("vaadin-button"), ""); | ||||
read.writeDesign(root, new DesignContext()); | read.writeDesign(root, new DesignContext()); | ||||
assertEquals("& Test", root.html()); | assertEquals("& Test", root.html()); | ||||
read.setHtmlContentAllowed(false); | |||||
read.setCaptionAsHtml(false); | |||||
root = new Element(Tag.valueOf("vaadin-button"), ""); | root = new Element(Tag.valueOf("vaadin-button"), ""); | ||||
read.writeDesign(root, new DesignContext()); | read.writeDesign(root, new DesignContext()); | ||||
assertEquals("&amp; Test", root.html()); | assertEquals("&amp; Test", root.html()); |
b = new Button( | b = new Button( | ||||
"<span style=\"color: red; font-weight: bold;\">HTML</span> button"); | "<span style=\"color: red; font-weight: bold;\">HTML</span> button"); | ||||
b.setHtmlContentAllowed(true); | |||||
b.setCaptionAsHtml(true); | |||||
addComponent(b); | addComponent(b); | ||||
final Button swapButton = new Button("<i>Swap button<i>"); | final Button swapButton = new Button("<i>Swap button<i>"); | ||||
@Override | @Override | ||||
public void buttonClick(ClickEvent event) { | public void buttonClick(ClickEvent event) { | ||||
swapButton.setHtmlContentAllowed( | |||||
!swapButton.isHtmlContentAllowed()); | |||||
swapButton.setCaptionAsHtml(!swapButton.isCaptionAsHtml()); | |||||
} | } | ||||
}); | }); | ||||
addComponent(swapButton); | addComponent(swapButton); |
b = new NativeButton( | b = new NativeButton( | ||||
"<span style=\"color: red; font-weight: bold;\">HTML</span> button"); | "<span style=\"color: red; font-weight: bold;\">HTML</span> button"); | ||||
b.setHtmlContentAllowed(true); | |||||
b.setCaptionAsHtml(true); | |||||
addComponent(b); | addComponent(b); | ||||
final NativeButton swapButton = new NativeButton("<i>Swap button<i>"); | final NativeButton swapButton = new NativeButton("<i>Swap button<i>"); | ||||
@Override | @Override | ||||
public void buttonClick(ClickEvent event) { | public void buttonClick(ClickEvent event) { | ||||
swapButton.setHtmlContentAllowed( | |||||
!swapButton.isHtmlContentAllowed()); | |||||
swapButton.setCaptionAsHtml(!swapButton.isCaptionAsHtml()); | |||||
} | } | ||||
}); | }); | ||||
addComponent(swapButton); | addComponent(swapButton); |
import com.vaadin.ui.Label; | import com.vaadin.ui.Label; | ||||
import com.vaadin.ui.MenuBar; | import com.vaadin.ui.MenuBar; | ||||
import com.vaadin.ui.MenuBar.MenuItem; | import com.vaadin.ui.MenuBar.MenuItem; | ||||
import com.vaadin.ui.themes.ValoTheme; | |||||
import com.vaadin.ui.Notification; | import com.vaadin.ui.Notification; | ||||
import com.vaadin.ui.UI; | import com.vaadin.ui.UI; | ||||
import com.vaadin.ui.themes.ValoTheme; | |||||
import com.vaadin.v7.data.Container; | import com.vaadin.v7.data.Container; | ||||
import com.vaadin.v7.data.Container.Hierarchical; | import com.vaadin.v7.data.Container.Hierarchical; | ||||
import com.vaadin.v7.data.Item; | import com.vaadin.v7.data.Item; | ||||
b.setIcon(FontAwesome.TH_LIST); | b.setIcon(FontAwesome.TH_LIST); | ||||
b.setPrimaryStyleName(ValoTheme.MENU_ITEM); | b.setPrimaryStyleName(ValoTheme.MENU_ITEM); | ||||
b.addStyleName("selected"); | b.addStyleName("selected"); | ||||
b.setHtmlContentAllowed(true); | |||||
b.setCaptionAsHtml(true); | |||||
menu.addComponent(b); | menu.addComponent(b); | ||||
b = new Button("API"); | b = new Button("API"); | ||||
b.setCaption(b.getCaption() | b.setCaption(b.getCaption() | ||||
+ " <span class=\"valo-menu-badge\">123</span>"); | + " <span class=\"valo-menu-badge\">123</span>"); | ||||
} | } | ||||
b.setHtmlContentAllowed(true); | |||||
b.setCaptionAsHtml(true); | |||||
b.setPrimaryStyleName(ValoTheme.MENU_ITEM); | b.setPrimaryStyleName(ValoTheme.MENU_ITEM); | ||||
b.setIcon(testIcon.get()); | b.setIcon(testIcon.get()); | ||||
menuItemsLayout.addComponent(b); | menuItemsLayout.addComponent(b); |