]> source.dussan.org Git - vaadin-framework.git/commitdiff
Add possibility to configure the content mode of TabSheet tabs (#8920)
authorAleksi Hietanen <aleksi@vaadin.com>
Fri, 24 Mar 2017 08:34:05 +0000 (10:34 +0200)
committerHenri Sara <henri.sara@gmail.com>
Fri, 24 Mar 2017 08:34:05 +0000 (10:34 +0200)
Fixes #8590

client/src/main/java/com/vaadin/client/ui/VTabsheet.java
server/src/main/java/com/vaadin/ui/TabSheet.java
shared/src/main/java/com/vaadin/shared/ui/tabsheet/TabState.java
uitest/src/main/java/com/vaadin/tests/components/tabsheet/TabDescriptionContentMode.java [new file with mode: 0644]
uitest/src/test/java/com/vaadin/tests/components/tabsheet/TabDescriptionContentModeTest.java [new file with mode: 0644]

index 8fbd3bcd74a5aa3ce0bdccfa6c5b7b3a07e21b02..ee9ef52154d48059594eef91af971d339c02268d 100644 (file)
@@ -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);
             }
index b48d35592ac368f157c004b8925384ca133f424a..ec018e5fbfdc5558feaef279635601c6ad983e2d 100644 (file)
@@ -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,12 +1012,33 @@ 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.
          */
         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
@@ -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();
         }
 
index 7e6698ad6bcacb79aa0161704dd3352c3e0b924f..763f2cf20fe10be3a2bbd88489ec12fd12b94d01 100644 (file)
@@ -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 (file)
index 0000000..e398532
--- /dev/null
@@ -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 (file)
index 0000000..a3de6ab
--- /dev/null
@@ -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"));
+    }
+}