Преглед на файлове

Deprecate Button#setHtmlContentAllowed (#104)

Fixes vaadin/framework8-issues#525
tags/8.0.0.alpha9
Aleksi Hietanen преди 7 години
родител
ревизия
205efc49bf

+ 7
- 1
server/src/main/java/com/vaadin/ui/Button.java Целия файл

* @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,

+ 2
- 2
server/src/test/java/com/vaadin/tests/server/component/button/ButtonDeclarativeTest.java Целия файл

Assert.assertEquals(expectedCaptionHtml, nativeButton.getCaption()); Assert.assertEquals(expectedCaptionHtml, nativeButton.getCaption());


read = new Button("&amp; Test"); read = new Button("&amp; 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("&amp; Test", root.html()); assertEquals("&amp; 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;amp; Test", root.html()); assertEquals("&amp;amp; Test", root.html());

+ 2
- 3
uitest/src/main/java/com/vaadin/tests/components/button/ButtonHtml.java Целия файл



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);

+ 2
- 3
uitest/src/main/java/com/vaadin/tests/components/nativebutton/NativeButtonHtml.java Целия файл



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);

+ 3
- 3
uitest/src/main/java/com/vaadin/tests/themes/valo/ValoThemeUI.java Целия файл

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);

Loading…
Отказ
Запис