summaryrefslogtreecommitdiffstats
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
parent8e4b607730fc9ee30519c21779a99cef6440831c (diff)
downloadvaadin-framework-911972c58b14deb847e807b3401ea08039d5b7a2.tar.gz
vaadin-framework-911972c58b14deb847e807b3401ea08039d5b7a2.zip
Make Grid react to theme changes (#15418)
Change-Id: Id67e378a0363a1c84cf08552a1528d612f6d43fe
-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
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridThemeChange.java59
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridThemeChangeTest.java51
5 files changed, 177 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();
+ }
}
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridThemeChange.java b/uitest/src/com/vaadin/tests/components/grid/GridThemeChange.java
new file mode 100644
index 0000000000..76f7e22ee0
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/GridThemeChange.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid;
+
+import java.util.Arrays;
+import java.util.List;
+
+import com.vaadin.event.SelectionEvent;
+import com.vaadin.event.SelectionEvent.SelectionListener;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.Grid.SelectionMode;
+
+public class GridThemeChange extends AbstractTestUI {
+ private final List<String> themes = Arrays.asList("valo", "reindeer",
+ "runo", "chameleon", "base");
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ final Grid grid = new Grid();
+ grid.setSelectionMode(SelectionMode.SINGLE);
+
+ grid.addColumn("Theme");
+ for (String theme : themes) {
+ Object itemId = grid.addRow(theme);
+ if (theme.equals(getTheme())) {
+ grid.select(itemId);
+ }
+ }
+
+ grid.addSelectionListener(new SelectionListener() {
+ @Override
+ public void select(SelectionEvent event) {
+ Object selectedItemId = grid.getSelectedRow();
+ Object theme = grid.getContainerDataSource()
+ .getItem(selectedItemId).getItemProperty("Theme")
+ .getValue();
+ setTheme(String.valueOf(theme));
+ }
+ });
+
+ addComponent(grid);
+
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridThemeChangeTest.java b/uitest/src/com/vaadin/tests/components/grid/GridThemeChangeTest.java
new file mode 100644
index 0000000000..5a21705b55
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/GridThemeChangeTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid;
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.remote.DesiredCapabilities;
+
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class GridThemeChangeTest extends MultiBrowserTest {
+ @Override
+ public List<DesiredCapabilities> getBrowsersToTest() {
+ // Seems like stylesheet onload is not fired on PhantomJS
+ // https://github.com/ariya/phantomjs/issues/12332
+ return super.getBrowsersExcludingPhantomJS();
+ }
+
+ @Test
+ public void testThemeChange() {
+ openTestURL();
+
+ GridElement grid = $(GridElement.class).first();
+
+ int reindeerHeight = grid.getRow(0).getSize().getHeight();
+
+ grid.getCell(0, 0).click();
+
+ int valoHeight = grid.getRow(0).getSize().getHeight();
+
+ Assert.assertTrue(
+ "Row height should increase when changing from Reindeer to Valo",
+ valoHeight > reindeerHeight);
+ }
+}