} | } | ||||
/** For internal use only. May be removed or replaced in the future. */ | /** For internal use only. May be removed or replaced in the future. */ | ||||
public void setCaption(String text) { | |||||
DOM.setInnerHTML(captionText, text); | |||||
public void setCaption(String text, boolean captionAsHtml) { | |||||
if (captionAsHtml) { | |||||
captionText.setInnerHTML(text); | |||||
} else { | |||||
captionText.setInnerText(text); | |||||
} | |||||
} | } | ||||
/** For internal use only. May be removed or replaced in the future. */ | /** For internal use only. May be removed or replaced in the future. */ |
// Affects size calculations | // Affects size calculations | ||||
// Restore default stylenames | // Restore default stylenames | ||||
getWidget().contentNode.setClassName(VPanel.CLASSNAME + "-content"); | getWidget().contentNode.setClassName(VPanel.CLASSNAME + "-content"); | ||||
getWidget().bottomDecoration | getWidget().bottomDecoration | ||||
.setClassName(VPanel.CLASSNAME + "-deco"); | .setClassName(VPanel.CLASSNAME + "-deco"); | ||||
getWidget().captionNode.setClassName(VPanel.CLASSNAME + "-caption"); | getWidget().captionNode.setClassName(VPanel.CLASSNAME + "-caption"); | ||||
boolean hasCaption = false; | |||||
if (getState().caption != null && !"".equals(getState().caption)) { | |||||
getWidget().setCaption(getState().caption); | |||||
hasCaption = true; | |||||
boolean hasCaption = hasCaption(); | |||||
if (hasCaption) { | |||||
getWidget().setCaption(getState().caption,getState().captionAsHtml); | |||||
} else { | } else { | ||||
getWidget().setCaption(""); | |||||
getWidget().captionNode | |||||
.setClassName(VPanel.CLASSNAME + "-nocaption"); | |||||
getWidget().setCaption("",false); | |||||
getWidget().captionNode.setClassName(VPanel.CLASSNAME + "-nocaption"); | |||||
} | } | ||||
// Add proper stylenames for all elements. This way we can prevent | // Add proper stylenames for all elements. This way we can prevent | ||||
getWidget().contentNode.setTabIndex(getState().tabIndex); | getWidget().contentNode.setTabIndex(getState().tabIndex); | ||||
} | } | ||||
/** | |||||
* Detects if caption div should be visible. | |||||
* | |||||
* @return {@code true} if caption div should be shown | |||||
*/ | |||||
protected boolean hasCaption() { | |||||
return getState().caption != null && !getState().caption.isEmpty(); | |||||
} | |||||
@Override | @Override | ||||
public void updateCaption(ComponentConnector component) { | public void updateCaption(ComponentConnector component) { | ||||
// NOP: layouts caption, errors etc not rendered in Panel | // NOP: layouts caption, errors etc not rendered in Panel |
buttons.addComponent(companiesButton); | buttons.addComponent(companiesButton); | ||||
buttons.addComponent(settingsButton); | buttons.addComponent(settingsButton); | ||||
panel = new Panel(); | panel = new Panel(); | ||||
panel.setCaption("<div class=\"caption-with-html\">Caption</div>"); | |||||
panel.setSizeFull(); | panel.setSizeFull(); | ||||
panel.setContent(stats); | panel.setContent(stats); | ||||
content.addComponent(buttons); | content.addComponent(buttons); |
package com.vaadin.tests.components.panel; | |||||
import com.vaadin.server.VaadinRequest; | |||||
import com.vaadin.tests.components.AbstractTestUI; | |||||
import com.vaadin.ui.Panel; | |||||
import com.vaadin.ui.Button; | |||||
import com.vaadin.ui.VerticalLayout; | |||||
public class PanelHTMLCaption extends AbstractTestUI { | |||||
public static final String caption = "<b> <div id='divId'>BOLD CAPTION</div></b>"; | |||||
private Panel panel; | |||||
@Override | |||||
protected void setup(VaadinRequest request) { | |||||
panel = new Panel(); | |||||
panel.setId("panelId"); | |||||
panel.setWidth("200px"); | |||||
panel.setHeight("200px"); | |||||
panel.setCaption(caption); | |||||
panel.setCaptionAsHtml(false); | |||||
panel.setContent(new VerticalLayout()); | |||||
addComponent(panel); | |||||
Button changeCaptionFormat = new Button( | |||||
"Set Caption as HTML", new Button.ClickListener() { | |||||
@Override | |||||
public void buttonClick(Button.ClickEvent event) { | |||||
panel.setCaptionAsHtml(true); | |||||
} | |||||
}); | |||||
changeCaptionFormat.setId("buttonId"); | |||||
addComponent(changeCaptionFormat); | |||||
} | |||||
} |
import org.junit.Assert; | import org.junit.Assert; | ||||
import org.junit.Test; | import org.junit.Test; | ||||
import com.vaadin.testbench.By; | |||||
import com.vaadin.tests.tb3.MultiBrowserTest; | import com.vaadin.tests.tb3.MultiBrowserTest; | ||||
public class PanelChangeContentsTest extends MultiBrowserTest { | public class PanelChangeContentsTest extends MultiBrowserTest { | ||||
"/VVerticalLayout[0]/Slot[1]/VPanel[0]/VVerticalLayout[0]/Slot[0]/VLabel[0]") | "/VVerticalLayout[0]/Slot[1]/VPanel[0]/VVerticalLayout[0]/Slot[0]/VLabel[0]") | ||||
.getText()); | .getText()); | ||||
assertElementNotPresent(By.className("caption-with-html")); | |||||
} | } | ||||
} | } |
package com.vaadin.tests.components.panel; | |||||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||||
import org.junit.Test; | |||||
import org.openqa.selenium.By; | |||||
public class PanelHTMLCaptionTest extends MultiBrowserTest { | |||||
@Test | |||||
public void testCaptionDisplayedAsText() { | |||||
openTestURL(); | |||||
assertElementNotPresent(By.id("divId")); | |||||
findElement(By.id("buttonId")).click(); | |||||
assertElementPresent(By.id("divId")); | |||||
} | |||||
} |