From e813c97e0bdc00c5542c9bf0f55eef65f34ac093 Mon Sep 17 00:00:00 2001 From: Artur Date: Tue, 13 Mar 2018 14:03:29 +0200 Subject: Setting of tooltips for grid header/footer cells (#10489) Fixes #7527 --- .../com/vaadin/ui/components/grid/FooterCell.java | 57 ++++++++++++++++++ .../com/vaadin/ui/components/grid/HeaderCell.java | 57 ++++++++++++++++++ .../vaadin/ui/components/grid/StaticSection.java | 70 ++++++++++++++++++++++ 3 files changed, 184 insertions(+) (limited to 'server') diff --git a/server/src/main/java/com/vaadin/ui/components/grid/FooterCell.java b/server/src/main/java/com/vaadin/ui/components/grid/FooterCell.java index d9777cbb77..9c4a38bc77 100644 --- a/server/src/main/java/com/vaadin/ui/components/grid/FooterCell.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/FooterCell.java @@ -17,6 +17,7 @@ package com.vaadin.ui.components.grid; import java.io.Serializable; +import com.vaadin.shared.ui.ContentMode; import com.vaadin.shared.ui.grid.GridStaticCellType; import com.vaadin.ui.Component; @@ -102,4 +103,60 @@ public interface FooterCell extends Serializable { * the style name to set or null to not use any style name */ public void setStyleName(String styleName); + + /** + * Gets the tooltip for the cell. + *

+ * The tooltip is shown in the mode returned by + * {@link #getDescriptionContentMode()}. + * + * @since + */ + public String getDescription(); + + /** + * Sets the tooltip for the cell. + *

+ * By default, tooltips are shown as plain text. For HTML tooltips, see + * {@link #setDescription(String, ContentMode)} or + * {@link #setDescriptionContentMode(ContentMode)}. + * + * @param description + * the tooltip to show when hovering the cell + * @since + */ + public void setDescription(String description); + + /** + * Sets the tooltip for the cell to be shown with the given content mode. + * + * @see ContentMode + * @param description + * the tooltip to show when hovering the cell + * @param descriptionContentMode + * the content mode to use for the tooltip (HTML or plain text) + * @since + */ + public void setDescription(String description, + ContentMode descriptionContentMode); + + /** + * Gets the content mode for the tooltip. + + * @see ContentMode + * @return the content mode for the tooltip + * @since + */ + public ContentMode getDescriptionContentMode(); + + /** + * Sets the content mode for the tooltip. + * + * @see ContentMode + * @param descriptionContentMode + * the content mode for the tooltip + * @since + */ + public void setDescriptionContentMode(ContentMode descriptionContentMode); + } diff --git a/server/src/main/java/com/vaadin/ui/components/grid/HeaderCell.java b/server/src/main/java/com/vaadin/ui/components/grid/HeaderCell.java index 6801622740..79f25b6dea 100644 --- a/server/src/main/java/com/vaadin/ui/components/grid/HeaderCell.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/HeaderCell.java @@ -17,6 +17,7 @@ package com.vaadin.ui.components.grid; import java.io.Serializable; +import com.vaadin.shared.ui.ContentMode; import com.vaadin.shared.ui.grid.GridStaticCellType; import com.vaadin.ui.Component; @@ -102,4 +103,60 @@ public interface HeaderCell extends Serializable { * the style name to set or null to not use any style name */ public void setStyleName(String styleName); + + /** + * Gets the tooltip for the cell. + *

+ * The tooltip is shown in the mode returned by + * {@link #getDescriptionContentMode()}. + * + * @since + */ + public String getDescription(); + + /** + * Sets the tooltip for the cell. + *

+ * By default, tooltips are shown as plain text. For HTML tooltips, see + * {@link #setDescription(String, ContentMode)} or + * {@link #setDescriptionContentMode(ContentMode)}. + * + * @param description + * the tooltip to show when hovering the cell + * @since + */ + public void setDescription(String description); + + /** + * Sets the tooltip for the cell to be shown with the given content mode. + * + * @see ContentMode + * @param description + * the tooltip to show when hovering the cell + * @param descriptionContentMode + * the content mode to use for the tooltip (HTML or plain text) + * @since + */ + public void setDescription(String description, + ContentMode descriptionContentMode); + + /** + * Gets the content mode for the tooltip. + *

+ * + * @see ContentMode + * @return the content mode for the tooltip + * @since + */ + public ContentMode getDescriptionContentMode(); + + /** + * Sets the content mode for the tooltip. + * + * @see ContentMode + * @param descriptionContentMode + * the content mode for the tooltip + * @since + */ + public void setDescriptionContentMode(ContentMode descriptionContentMode); } diff --git a/server/src/main/java/com/vaadin/ui/components/grid/StaticSection.java b/server/src/main/java/com/vaadin/ui/components/grid/StaticSection.java index ec25339931..40ade7e97e 100644 --- a/server/src/main/java/com/vaadin/ui/components/grid/StaticSection.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/StaticSection.java @@ -35,6 +35,7 @@ import java.util.stream.Stream; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; +import com.vaadin.shared.ui.ContentMode; import com.vaadin.shared.ui.grid.GridStaticCellType; import com.vaadin.shared.ui.grid.SectionState; import com.vaadin.shared.ui.grid.SectionState.CellState; @@ -615,6 +616,75 @@ public abstract class StaticSection> void detach() { removeComponentIfPresent(); } + + /** + * Gets the tooltip for the cell. + *

+ * The tooltip is shown in the mode returned by + * {@link #getDescriptionContentMode()}. + * + * @since + */ + public String getDescription() { + return cellState.description; + } + + /** + * Sets the tooltip for the cell. + *

+ * By default, tooltips are shown as plain text. For HTML tooltips, see + * {@link #setDescription(String, ContentMode)} or + * {@link #setDescriptionContentMode(ContentMode)}. + * + * @param description + * the tooltip to show when hovering the cell + * @since + */ + public void setDescription(String description) { + cellState.description = description; + } + + /** + * Sets the tooltip for the cell to be shown with the given content + * mode. + * + * @see ContentMode + * @param description + * the tooltip to show when hovering the cell + * @param descriptionContentMode + * the content mode to use for the tooltip (HTML or plain + * text) + * @since + */ + public void setDescription(String description, + ContentMode descriptionContentMode) { + setDescription(description); + setDescriptionContentMode(descriptionContentMode); + } + + /** + * Gets the content mode for the tooltip. + * + * @see ContentMode + * @return the content mode for the tooltip + * @since + */ + public ContentMode getDescriptionContentMode() { + return cellState.descriptionContentMode; + } + + /** + * Sets the content mode for the tooltip. + * + * @see ContentMode + * @param descriptionContentMode + * the content mode for the tooltip + * @since + */ + public void setDescriptionContentMode( + ContentMode descriptionContentMode) { + cellState.descriptionContentMode = descriptionContentMode; + } } private final List rows = new ArrayList<>(); -- cgit v1.2.3