diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-06-20 12:59:14 +0300 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-06-20 12:59:14 +0300 |
commit | f700c01e12ea5be80d88587a2720a03187922f2c (patch) | |
tree | e6e1cdd58cfe034769e29cdc85abc70dd1746331 /client | |
parent | 086170faf858062d2d85fca7fade901a6070c2c2 (diff) | |
download | vaadin-framework-f700c01e12ea5be80d88587a2720a03187922f2c.tar.gz vaadin-framework-f700c01e12ea5be80d88587a2720a03187922f2c.zip |
Enable row height and content mode settings for Tree (#9540)
* Enable row height setting for Tree
* Add content mode for captions
* Align expander element by default to top
The content mode allows use of preformatted and
HTML captions that bring value to row height
Fixes #9411
Diffstat (limited to 'client')
-rw-r--r-- | client/src/main/java/com/vaadin/client/connectors/grid/TreeRendererConnector.java | 29 | ||||
-rwxr-xr-x | client/src/main/java/com/vaadin/client/widgets/Grid.java | 4 |
2 files changed, 28 insertions, 5 deletions
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/TreeRendererConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/TreeRendererConnector.java index df0da24e99..fe27b76bdc 100644 --- a/client/src/main/java/com/vaadin/client/connectors/grid/TreeRendererConnector.java +++ b/client/src/main/java/com/vaadin/client/connectors/grid/TreeRendererConnector.java @@ -17,6 +17,7 @@ package com.vaadin.client.connectors.grid; import com.google.gwt.safehtml.shared.SafeHtmlUtils; import com.google.gwt.user.client.Element; +import com.vaadin.client.annotations.OnStateChange; import com.vaadin.client.renderers.HtmlRenderer; import com.vaadin.client.renderers.Renderer; import com.vaadin.client.widget.grid.RendererCellReference; @@ -27,7 +28,7 @@ import com.vaadin.ui.Tree.TreeRenderer; import elemental.json.JsonObject; /** - * Connector for TreeRenderer + * Connector for TreeRenderer. * * @author Vaadin Ltd * @since 8.1 @@ -42,9 +43,8 @@ public class TreeRendererConnector @Override public void render(RendererCellReference cell, String htmlString) { - String content = "<span class=\"v-captiontext\">" + - SafeHtmlUtils.htmlEscape(htmlString) - + "</span>"; + String content = "<span class=\"v-captiontext\">" + + getContentString(htmlString) + "</span>"; JsonObject row = getParent().getParent().getDataSource() .getRow(cell.getRowIndex()); @@ -56,9 +56,30 @@ public class TreeRendererConnector } super.render(cell, content); } + + private String getContentString(String htmlString) { + switch (getState().mode) { + case HTML: + return htmlString; + case PREFORMATTED: + return "<pre>" + SafeHtmlUtils.htmlEscape(htmlString) + + "</pre>"; + default: + return SafeHtmlUtils.htmlEscape(htmlString); + } + } }; } + @OnStateChange("mode") + void updateContentMode() { + // Redraw content + getParent().getParent().getWidget().requestRefreshBody(); + + // Some pre-formatted content might change size of content. + getParent().getParent().getWidget().recalculateColumnWidths(); + } + @Override public ColumnConnector getParent() { return (ColumnConnector) super.getParent(); 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 aa0261d6d9..45937e0c07 100755 --- a/client/src/main/java/com/vaadin/client/widgets/Grid.java +++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java @@ -6381,8 +6381,10 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, /** * Request delayed refresh of all body rows. + * + * @since 8.1 */ - private void requestRefreshBody() { + public void requestRefreshBody() { if (!refreshBodyRequested) { refreshBodyRequested = true; Scheduler.get().scheduleFinally(() -> { |