Skip to content

Commit

Permalink
Add possibility to configure the content mode of TabSheet tabs (#8920)
Browse files Browse the repository at this point in the history
Fixes #8590
  • Loading branch information
ahie authored and hesara committed Mar 24, 2017
1 parent b32d7b0 commit 8fcb2da
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 3 deletions.
5 changes: 2 additions & 3 deletions client/src/main/java/com/vaadin/client/ui/VTabsheet.java
Expand Up @@ -73,7 +73,6 @@
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;
Expand Down Expand Up @@ -340,8 +339,8 @@ private boolean update(TabState tabState) {
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);
}
Expand Down
28 changes: 28 additions & 0 deletions server/src/main/java/com/vaadin/ui/TabSheet.java
Expand Up @@ -40,6 +40,7 @@
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;
Expand Down Expand Up @@ -1011,12 +1012,33 @@ public interface Tab extends Serializable {
* 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.
*/
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
Expand Down Expand Up @@ -1217,7 +1239,13 @@ public String getDescription() {

@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();
}

Expand Down
Expand Up @@ -17,6 +17,8 @@

import java.io.Serializable;

import com.vaadin.shared.ui.ContentMode;

/**
* Shared state of a single tab in a Tabsheet or an Accordion.
*
Expand All @@ -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;
Expand Down
@@ -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);
}
}
@@ -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"));
}
}

0 comments on commit 8fcb2da

Please sign in to comment.