diff options
5 files changed, 130 insertions, 3 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VTabsheet.java b/client/src/main/java/com/vaadin/client/ui/VTabsheet.java index 8fbd3bcd74..ee9ef52154 100644 --- a/client/src/main/java/com/vaadin/client/ui/VTabsheet.java +++ b/client/src/main/java/com/vaadin/client/ui/VTabsheet.java @@ -73,7 +73,6 @@ import com.vaadin.shared.ComponentConstants; import com.vaadin.shared.EventId; import com.vaadin.shared.communication.FieldRpc.FocusAndBlurServerRpc; import com.vaadin.shared.ui.ComponentStateUtil; -import com.vaadin.shared.ui.ContentMode; import com.vaadin.shared.ui.tabsheet.TabState; import com.vaadin.shared.ui.tabsheet.TabsheetServerRpc; import com.vaadin.shared.ui.tabsheet.TabsheetState; @@ -340,8 +339,8 @@ public class VTabsheet extends VTabsheetBase if (tabState.description != null || tabState.componentError != null) { setTooltipInfo(new TooltipInfo(tabState.description, - ContentMode.PREFORMATTED, tabState.componentError, - this)); + tabState.descriptionContentMode, + tabState.componentError, this)); } else { setTooltipInfo(null); } diff --git a/server/src/main/java/com/vaadin/ui/TabSheet.java b/server/src/main/java/com/vaadin/ui/TabSheet.java index b48d35592a..ec018e5fbf 100644 --- a/server/src/main/java/com/vaadin/ui/TabSheet.java +++ b/server/src/main/java/com/vaadin/ui/TabSheet.java @@ -40,6 +40,7 @@ import com.vaadin.server.KeyMapper; import com.vaadin.server.Resource; import com.vaadin.shared.ComponentConstants; import com.vaadin.shared.Registration; +import com.vaadin.shared.ui.ContentMode; import com.vaadin.shared.ui.tabsheet.TabState; import com.vaadin.shared.ui.tabsheet.TabsheetClientRpc; import com.vaadin.shared.ui.tabsheet.TabsheetServerRpc; @@ -1011,6 +1012,11 @@ public class TabSheet extends AbstractComponentContainer * Sets the description for the tab. The description can be used to * briefly describe the state of the tab to the user, and is typically * shown as a tooltip when hovering over the tab. + * <p> + * Setting a description through this method will additionally set the + * content mode of the description to preformatted. For setting a + * different content mode see the overload + * {@link #setDescription(String, ContentMode)}. * * @param description * the new description string for the tab. @@ -1018,6 +1024,22 @@ public class TabSheet extends AbstractComponentContainer public void setDescription(String description); /** + * Sets the description for the tab. The description can be used to + * briefly describe the state of the tab to the user, and is typically + * shown as a tooltip when hovering over the tab. + * + * @see ContentMode + * + * @param description + * the new description string for the tab + * @param mode + * content mode used to display the description + * + * @since 8.1 + */ + public void setDescription(String description, ContentMode mode); + + /** * Sets an error indicator to be shown in the tab. This can be used e.g. * to communicate to the user that there is a problem in the contents of * the tab. @@ -1217,7 +1239,13 @@ public class TabSheet extends AbstractComponentContainer @Override public void setDescription(String description) { + setDescription(description, ContentMode.PREFORMATTED); + } + + @Override + public void setDescription(String description, ContentMode mode) { tabState.description = description; + tabState.descriptionContentMode = mode; markAsDirty(); } diff --git a/shared/src/main/java/com/vaadin/shared/ui/tabsheet/TabState.java b/shared/src/main/java/com/vaadin/shared/ui/tabsheet/TabState.java index 7e6698ad6b..763f2cf20f 100644 --- a/shared/src/main/java/com/vaadin/shared/ui/tabsheet/TabState.java +++ b/shared/src/main/java/com/vaadin/shared/ui/tabsheet/TabState.java @@ -17,6 +17,8 @@ package com.vaadin.shared.ui.tabsheet; import java.io.Serializable; +import com.vaadin.shared.ui.ContentMode; + /** * Shared state of a single tab in a Tabsheet or an Accordion. * @@ -30,6 +32,7 @@ public class TabState implements Serializable { public boolean visible = true; public boolean closable = false; public String description = null; + public ContentMode descriptionContentMode = ContentMode.PREFORMATTED; public String styleName; public String key; public String componentError; diff --git a/uitest/src/main/java/com/vaadin/tests/components/tabsheet/TabDescriptionContentMode.java b/uitest/src/main/java/com/vaadin/tests/components/tabsheet/TabDescriptionContentMode.java new file mode 100644 index 0000000000..e398532f3e --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/tabsheet/TabDescriptionContentMode.java @@ -0,0 +1,44 @@ +package com.vaadin.tests.components.tabsheet; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.ContentMode; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Label; +import com.vaadin.ui.TabSheet; +import com.vaadin.ui.TabSheet.Tab; + +public class TabDescriptionContentMode extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + TabSheet tabSheet = new TabSheet(); + + Tab firstTab = tabSheet.addTab(new Label()); + firstTab.setCaption("First tab"); + firstTab.setDescription("First tab description", ContentMode.TEXT); + + Tab secondTab = tabSheet.addTab(new Label()); + secondTab.setCaption("Second tab"); + secondTab.setDescription("Second tab\ndescription", + ContentMode.PREFORMATTED); + + Tab thirdTab = tabSheet.addTab(new Label()); + thirdTab.setCaption("Third tab"); + thirdTab.setDescription("<b>Third tab description</b>", + ContentMode.HTML); + + Tab fourthTab = tabSheet.addTab(new Label()); + fourthTab.setCaption("Fourth tab"); + fourthTab.setDescription("Fourth tab description"); + + Button changeFourthTabDescription = new Button( + "Change fourth tab description"); + changeFourthTabDescription.addClickListener( + event -> fourthTab.setDescription( + "Fourth tab description, changed", + ContentMode.TEXT)); + + addComponents(tabSheet, changeFourthTabDescription); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/tabsheet/TabDescriptionContentModeTest.java b/uitest/src/test/java/com/vaadin/tests/components/tabsheet/TabDescriptionContentModeTest.java new file mode 100644 index 0000000000..a3de6ab147 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/tabsheet/TabDescriptionContentModeTest.java @@ -0,0 +1,53 @@ +package com.vaadin.tests.components.tabsheet; + +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class TabDescriptionContentModeTest extends SingleBrowserTest { + + @Test + public void tab_description_content_modes() { + openTestURL(); + List<WebElement> tabCaptions = findElements( + By.className("v-captiontext")); + + hoverCaption(tabCaptions.get(0)); + waitUntil(driver -> "First tab description" + .equals(getDescriptionElement().getText())); + + hoverCaption(tabCaptions.get(1)); + waitUntil(driver -> "Second tab\ndescription" + .equals(getDescriptionElement().findElement(By.tagName("pre")) + .getText())); + + hoverCaption(tabCaptions.get(2)); + waitUntil( + driver -> "Third tab description".equals(getDescriptionElement() + .findElement(By.tagName("b")).getText())); + + hoverCaption(tabCaptions.get(3)); + waitUntil(driver -> "Fourth tab description" + .equals(getDescriptionElement().findElement(By.tagName("pre")) + .getText())); + + $(ButtonElement.class).first().click(); + hoverCaption(tabCaptions.get(3)); + waitUntil(driver -> "Fourth tab description, changed" + .equals(getDescriptionElement().getText())); + } + + private void hoverCaption(WebElement captionElement) { + new Actions(getDriver()).moveToElement(captionElement, 1, 1).perform(); + } + + private WebElement getDescriptionElement() { + return findElement(By.className("v-tooltip-text")); + } +} |