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 --- .../client/connectors/grid/GridConnector.java | 30 +++++++- .../main/java/com/vaadin/client/widgets/Grid.java | 80 +++++++++++++++++++++- 2 files changed, 107 insertions(+), 3 deletions(-) (limited to 'client/src') diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java index 491aa0d9d2..b9521d06f5 100644 --- a/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java +++ b/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java @@ -59,6 +59,7 @@ import com.vaadin.client.widgets.Grid.Column; import com.vaadin.client.widgets.Grid.FooterRow; import com.vaadin.client.widgets.Grid.HeaderRow; import com.vaadin.client.widgets.Grid.SelectionColumn; +import com.vaadin.client.widgets.Grid.StaticSection.StaticCell; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.data.sort.SortDirection; import com.vaadin.shared.ui.Connect; @@ -457,6 +458,8 @@ public class GridConnector extends AbstractListingConnector "unexpected cell type: " + cellState.type); } cell.setStyleName(cellState.styleName); + cell.setDescription(cellState.description); + cell.setDescriptionContentMode(cellState.descriptionContentMode); } /** @@ -677,7 +680,10 @@ public class GridConnector extends AbstractListingConnector if (cell != null) { JsonObject row = cell.getRow(); - + TooltipInfo tooltip = getHeaderFooterTooltip(cell); + if (tooltip != null) { + return tooltip; + } if (row != null && (row.hasKey(GridState.JSONKEY_ROWDESCRIPTION) || row.hasKey(GridState.JSONKEY_CELLDESCRIPTION))) { @@ -708,6 +714,28 @@ public class GridConnector extends AbstractListingConnector return null; } + private TooltipInfo getHeaderFooterTooltip(CellReference cell) { + Section section = Section.BODY; + if (cell instanceof EventCellReference) { + // Header or footer + section = ((EventCellReference) cell).getSection(); + } + StaticCell staticCell = null; + if (section == Section.HEADER) { + staticCell = getWidget().getHeaderRow(cell.getRowIndex()) + .getCell(cell.getColumn()); + } else if (section == Section.FOOTER) { + staticCell = getWidget().getFooterRow(cell.getRowIndex()) + .getCell(cell.getColumn()); + } + if (staticCell != null && staticCell.getDescription() != null) { + return new TooltipInfo(staticCell.getDescription(), + staticCell.getDescriptionContentMode()); + } + + return null; + } + @Override protected void sendContextClickEvent(MouseEventDetails details, EventTarget eventTarget) { diff --git a/client/src/main/java/com/vaadin/client/widgets/Grid.java b/client/src/main/java/com/vaadin/client/widgets/Grid.java index e8baa981af..8a6d7abfdd 100755 --- a/client/src/main/java/com/vaadin/client/widgets/Grid.java +++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java @@ -176,6 +176,7 @@ import com.vaadin.client.widgets.Grid.StaticSection.StaticRow; import com.vaadin.shared.Range; import com.vaadin.shared.Registration; import com.vaadin.shared.data.sort.SortDirection; +import com.vaadin.shared.ui.ContentMode; import com.vaadin.shared.ui.grid.ColumnResizeMode; import com.vaadin.shared.ui.grid.GridConstants; import com.vaadin.shared.ui.grid.GridConstants.Section; @@ -258,6 +259,10 @@ public class Grid extends ResizeComposite implements HasSelectionHandlers, private String styleName = null; + private String description = null; + + private ContentMode descriptionContentMode = ContentMode.TEXT; + /** * Sets the text displayed in this cell. * @@ -426,11 +431,82 @@ public class Grid extends ResizeComposite implements HasSelectionHandlers, * @since 7.6.3 */ void detach() { - if (this.content instanceof Widget) { + if (content instanceof Widget) { // Widget in the cell, detach it - section.getGrid().detachWidget((Widget) this.content); + section.getGrid().detachWidget((Widget) content); } } + + /** + * Gets the tooltip for the cell. + *

+ * The tooltip is shown in the mode returned by + * {@link #getDescriptionContentMode()}. + * + * @since + */ + public String getDescription() { + return 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) { + this.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. + *

+ * The content mode determines how the tooltip is shown. + * + * @see ContentMode + * @return the content mode for the tooltip + * @since + */ + public ContentMode getDescriptionContentMode() { + return descriptionContentMode; + } + + /** + * Sets the content mode for the tooltip. + * + * @see ContentMode + * @param descriptionContentMode + * the content mode for the tooltip + * @since + */ + public void setDescriptionContentMode( + ContentMode descriptionContentMode) { + this.descriptionContentMode = descriptionContentMode; + } } /** -- cgit v1.2.3