diff options
author | Artur <artur@vaadin.com> | 2018-03-13 14:03:29 +0200 |
---|---|---|
committer | Ilia Motornyi <elmot@vaadin.com> | 2018-03-13 15:03:29 +0300 |
commit | e813c97e0bdc00c5542c9bf0f55eef65f34ac093 (patch) | |
tree | df2557a4a63a9de77234358e0c55bfc8ca1185ff /client/src | |
parent | 0af3b7d717b44b0de1af82143b3c3d3aece587ab (diff) | |
download | vaadin-framework-e813c97e0bdc00c5542c9bf0f55eef65f34ac093.tar.gz vaadin-framework-e813c97e0bdc00c5542c9bf0f55eef65f34ac093.zip |
Setting of tooltips for grid header/footer cells (#10489)
Fixes #7527
Diffstat (limited to 'client/src')
-rw-r--r-- | client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java | 30 | ||||
-rwxr-xr-x | client/src/main/java/com/vaadin/client/widgets/Grid.java | 80 |
2 files changed, 107 insertions, 3 deletions
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<T> extends ResizeComposite implements HasSelectionHandlers<T>, 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<T> extends ResizeComposite implements HasSelectionHandlers<T>, * @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. + * <p> + * The tooltip is shown in the mode returned by + * {@link #getDescriptionContentMode()}. + * + * @since + */ + public String getDescription() { + return description; + } + + /** + * Sets the tooltip for the cell. + * <p> + * 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. + * <p> + * 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; + } } /** |