summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2015-01-15 22:05:58 +0200
committerLeif Åstrand <leif@vaadin.com>2015-01-16 12:25:16 +0200
commit911972c58b14deb847e807b3401ea08039d5b7a2 (patch)
tree2cc0bfed49784b9596592513e1b2ce7621841605 /client
parent8e4b607730fc9ee30519c21779a99cef6440831c (diff)
downloadvaadin-framework-911972c58b14deb847e807b3401ea08039d5b7a2.tar.gz
vaadin-framework-911972c58b14deb847e807b3401ea08039d5b7a2.zip
Make Grid react to theme changes (#15418)
Change-Id: Id67e378a0363a1c84cf08552a1528d612f6d43fe
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/connectors/GridConnector.java10
-rw-r--r--client/src/com/vaadin/client/widgets/Escalator.java74
-rw-r--r--client/src/com/vaadin/client/widgets/Grid.java9
3 files changed, 67 insertions, 26 deletions
diff --git a/client/src/com/vaadin/client/connectors/GridConnector.java b/client/src/com/vaadin/client/connectors/GridConnector.java
index 0414e82680..93e2b0568d 100644
--- a/client/src/com/vaadin/client/connectors/GridConnector.java
+++ b/client/src/com/vaadin/client/connectors/GridConnector.java
@@ -389,6 +389,8 @@ public class GridConnector extends AbstractHasComponentsConnector implements
private ItemClickHandler itemClickHandler = new ItemClickHandler();
+ private String lastKnownTheme = null;
+
@Override
@SuppressWarnings("unchecked")
public Grid<JsonObject> getWidget() {
@@ -533,6 +535,14 @@ public class GridConnector extends AbstractHasComponentsConnector implements
if (stateChangeEvent.hasPropertyChanged("frozenColumnCount")) {
getWidget().setFrozenColumnCount(getState().frozenColumnCount);
}
+
+ String activeTheme = getConnection().getUIConnector().getActiveTheme();
+ if (lastKnownTheme == null) {
+ lastKnownTheme = activeTheme;
+ } else if (!lastKnownTheme.equals(activeTheme)) {
+ getWidget().resetSizesFromDom();
+ lastKnownTheme = activeTheme;
+ }
}
private void updateColumnOrderFromState(List<String> stateColumnOrder) {
diff --git a/client/src/com/vaadin/client/widgets/Escalator.java b/client/src/com/vaadin/client/widgets/Escalator.java
index f1c59f17ea..641a8d9adb 100644
--- a/client/src/com/vaadin/client/widgets/Escalator.java
+++ b/client/src/com/vaadin/client/widgets/Escalator.java
@@ -1903,39 +1903,45 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker
rowTopPositionMap.remove(tr);
}
- public void autodetectRowHeight() {
+ public void autodetectRowHeightLater() {
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
-
@Override
public void execute() {
if (defaultRowHeightShouldBeAutodetected && isAttached()) {
- final Element detectionTr = DOM.createTR();
- detectionTr
- .setClassName(getStylePrimaryName() + "-row");
-
- final Element cellElem = DOM
- .createElement(getCellElementTagName());
- cellElem.setClassName(getStylePrimaryName() + "-cell");
- cellElem.setInnerText("Ij");
-
- detectionTr.appendChild(cellElem);
- root.appendChild(detectionTr);
- double boundingHeight = WidgetUtil
- .getRequiredHeightBoundingClientRectDouble(cellElem);
- defaultRowHeight = Math.max(1.0d, boundingHeight);
- root.removeChild(detectionTr);
-
- if (root.hasChildNodes()) {
- reapplyDefaultRowHeights();
- applyHeightByRows();
- }
-
+ autodetectRowHeightNow();
defaultRowHeightShouldBeAutodetected = false;
}
}
});
}
+ public void autodetectRowHeightNow() {
+ if (!isAttached()) {
+ // Run again when attached
+ defaultRowHeightShouldBeAutodetected = true;
+ return;
+ }
+
+ final Element detectionTr = DOM.createTR();
+ detectionTr.setClassName(getStylePrimaryName() + "-row");
+
+ final Element cellElem = DOM.createElement(getCellElementTagName());
+ cellElem.setClassName(getStylePrimaryName() + "-cell");
+ cellElem.setInnerText("Ij");
+
+ detectionTr.appendChild(cellElem);
+ root.appendChild(detectionTr);
+ double boundingHeight = WidgetUtil
+ .getRequiredHeightBoundingClientRectDouble(cellElem);
+ defaultRowHeight = Math.max(1.0d, boundingHeight);
+ root.removeChild(detectionTr);
+
+ if (root.hasChildNodes()) {
+ reapplyDefaultRowHeights();
+ applyHeightByRows();
+ }
+ }
+
@Override
public Cell getCell(final Element element) {
if (element == null) {
@@ -4367,9 +4373,9 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker
protected void onLoad() {
super.onLoad();
- header.autodetectRowHeight();
- body.autodetectRowHeight();
- footer.autodetectRowHeight();
+ header.autodetectRowHeightLater();
+ body.autodetectRowHeightLater();
+ footer.autodetectRowHeightLater();
header.paintInsertRows(0, header.getRowCount());
footer.paintInsertRows(0, footer.getRowCount());
@@ -5090,4 +5096,20 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker
return WidgetUtil
.getRequiredWidthBoundingClientRectDouble(tableWrapper);
}
+
+ /**
+ * Resets all cached pixel sizes and reads new values from the DOM. This
+ * methods should be used e.g. when styles affecting the dimensions of
+ * elements in this escalator have been changed.
+ */
+ public void resetSizesFromDom() {
+ header.autodetectRowHeightNow();
+ body.autodetectRowHeightNow();
+ footer.autodetectRowHeightNow();
+
+ for (int i = 0; i < columnConfiguration.getColumnCount(); i++) {
+ columnConfiguration.setColumnWidth(i,
+ columnConfiguration.getColumnWidth(i));
+ }
+ }
}
diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java
index a215b9df6d..7668d43fe0 100644
--- a/client/src/com/vaadin/client/widgets/Grid.java
+++ b/client/src/com/vaadin/client/widgets/Grid.java
@@ -5832,4 +5832,13 @@ public class Grid<T> extends ResizeComposite implements
/*-{
widget.@com.google.gwt.user.client.ui.Widget::setParent(Lcom/google/gwt/user/client/ui/Widget;)(parent);
}-*/;
+
+ /**
+ * Resets all cached pixel sizes and reads new values from the DOM. This
+ * methods should be used e.g. when styles affecting the dimensions of
+ * elements in this grid have been changed.
+ */
+ public void resetSizesFromDom() {
+ getEscalator().resetSizesFromDom();
+ }
}