summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2017-08-11 15:27:27 +0300
committerHenri Sara <henri.sara@gmail.com>2017-08-11 15:27:27 +0300
commitbda7e54cb6eadddf07fb19d88479c642c4831a66 (patch)
tree4b88c87dd70733cf1c309630c8c2e0e8ca2ad15b /client
parent9a491b040d5c9d11e227acfdecfa867e5d7cf7d2 (diff)
downloadvaadin-framework-bda7e54cb6eadddf07fb19d88479c642c4831a66.tar.gz
vaadin-framework-bda7e54cb6eadddf07fb19d88479c642c4831a66.zip
Provide API for setting row heights in Grid for different sections (#9810)
Fixes #9425
Diffstat (limited to 'client')
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java60
1 files changed, 48 insertions, 12 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 61c0957d03..41602fbcef 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
@@ -44,6 +44,7 @@ import com.vaadin.client.connectors.AbstractListingConnector;
import com.vaadin.client.connectors.grid.ColumnConnector.CustomColumn;
import com.vaadin.client.data.DataSource;
import com.vaadin.client.ui.SimpleManagedLayout;
+import com.vaadin.client.widget.escalator.RowContainer;
import com.vaadin.client.widget.grid.CellReference;
import com.vaadin.client.widget.grid.EventCellReference;
import com.vaadin.client.widget.grid.events.BodyClickHandler;
@@ -117,6 +118,7 @@ public class GridConnector extends AbstractListingConnector
/* Child component list for HasComponentsConnector */
private List<ComponentConnector> childComponents;
private ItemClickHandler itemClickHandler = new ItemClickHandler();
+ private boolean rowHeightScheduled = false;
/**
* Gets the string identifier of the given column in this grid.
@@ -347,19 +349,53 @@ public class GridConnector extends AbstractListingConnector
grid.setHeaderVisible(state.visible);
}
- @OnStateChange("rowHeight")
+ @OnStateChange({ "bodyRowHeight", "headerRowHeight", "footerRowHeight" })
void updateRowHeight() {
- double rowHeight = getState().rowHeight;
- if (rowHeight >= 0) {
- getWidget().getEscalator().getHeader()
- .setDefaultRowHeight(rowHeight);
- getWidget().getEscalator().getBody().setDefaultRowHeight(rowHeight);
- getWidget().getEscalator().getFooter()
- .setDefaultRowHeight(rowHeight);
- } else if (getWidget().isAttached()) {
- // finally to make sure column sizes have been set before this
- Scheduler.get()
- .scheduleFinally(() -> getWidget().resetSizesFromDom());
+ if (rowHeightScheduled) {
+ return;
+ }
+
+ Scheduler.get().scheduleFinally(() -> {
+ GridState state = getState();
+ if (getWidget().isAttached() && rowHeightNeedsReset()) {
+ getWidget().resetSizesFromDom();
+ }
+ updateContainerRowHeigth(getWidget().getEscalator().getBody(),
+ state.bodyRowHeight);
+ updateContainerRowHeigth(getWidget().getEscalator().getHeader(),
+ state.headerRowHeight);
+ updateContainerRowHeigth(getWidget().getEscalator().getFooter(),
+ state.footerRowHeight);
+ rowHeightScheduled = false;
+ });
+
+ rowHeightScheduled = true;
+ }
+
+ private boolean rowHeightNeedsReset() {
+ GridState state = getState();
+ // Body
+ boolean bodyAutoCalc = state.bodyRowHeight < 0;
+
+ // Header
+ boolean headerAutoCalc = state.headerRowHeight < 0;
+ boolean headerReset = headerAutoCalc && hasVisibleContent(state.header);
+
+ // Footer
+ boolean footerAutoCalc = state.footerRowHeight < 0;
+ boolean footerReset = footerAutoCalc && hasVisibleContent(state.footer);
+
+ return bodyAutoCalc || headerReset || footerReset;
+ }
+
+ private boolean hasVisibleContent(SectionState state) {
+ return state.visible && !state.rows.isEmpty();
+ }
+
+ private void updateContainerRowHeigth(RowContainer container,
+ double height) {
+ if (height >= 0) {
+ container.setDefaultRowHeight(height);
}
}