summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authoradam <adam@vaadin.com>2016-08-08 15:25:10 +0300
committerVaadin Code Review <review@vaadin.com>2016-08-11 08:44:50 +0000
commit5e75657b387a99993ec17b03ab97bc32884fef80 (patch)
treeb7e9559ff85969ea683d98b539aab881801e47c8 /client
parent020557163c5dd3b1a532e75656922ab988076bef (diff)
downloadvaadin-framework-5e75657b387a99993ec17b03ab97bc32884fef80.tar.gz
vaadin-framework-5e75657b387a99993ec17b03ab97bc32884fef80.zip
Fix Grid height calculation when HeightMode.ROW (#20104, #20074)
When Grid is inside of a Tab (Tabsheet or Accordion) and height mode is set to HeightMode.ROW, layout happens before row height is known. To fix that, an event is fired and a handler starts a layout after everything is calculated. Change-Id: I516b09b5a7febc7ab3931fe582752eb5c888e4a8
Diffstat (limited to 'client')
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/GridConnector.java12
-rw-r--r--client/src/main/java/com/vaadin/client/widget/escalator/events/RowHeightChangedEvent.java48
-rw-r--r--client/src/main/java/com/vaadin/client/widget/escalator/events/RowHeightChangedHandler.java35
-rw-r--r--client/src/main/java/com/vaadin/client/widgets/Escalator.java27
-rw-r--r--client/src/main/java/com/vaadin/client/widgets/Grid.java7
5 files changed, 128 insertions, 1 deletions
diff --git a/client/src/main/java/com/vaadin/client/connectors/GridConnector.java b/client/src/main/java/com/vaadin/client/connectors/GridConnector.java
index f53d9c9d04..550cf1517c 100644
--- a/client/src/main/java/com/vaadin/client/connectors/GridConnector.java
+++ b/client/src/main/java/com/vaadin/client/connectors/GridConnector.java
@@ -52,6 +52,8 @@ import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.client.ui.AbstractHasComponentsConnector;
import com.vaadin.client.ui.ConnectorFocusAndBlurHandler;
import com.vaadin.client.ui.SimpleManagedLayout;
+import com.vaadin.client.widget.escalator.events.RowHeightChangedEvent;
+import com.vaadin.client.widget.escalator.events.RowHeightChangedHandler;
import com.vaadin.client.widget.grid.CellReference;
import com.vaadin.client.widget.grid.CellStyleGenerator;
import com.vaadin.client.widget.grid.EditorHandler;
@@ -797,6 +799,16 @@ public class GridConnector extends AbstractHasComponentsConnector implements
getWidget().setDetailsGenerator(customDetailsGenerator);
getLayoutManager().registerDependency(this, getWidget().getElement());
+ // Handling row height changes
+ getWidget().addRowHeightChangedHandler(new RowHeightChangedHandler() {
+ @Override
+ public void onRowHeightChanged(RowHeightChangedEvent event) {
+ getLayoutManager()
+ .setNeedsMeasureRecursively(GridConnector.this);
+ getLayoutManager().layoutNow();
+ }
+ });
+
layout();
}
diff --git a/client/src/main/java/com/vaadin/client/widget/escalator/events/RowHeightChangedEvent.java b/client/src/main/java/com/vaadin/client/widget/escalator/events/RowHeightChangedEvent.java
new file mode 100644
index 0000000000..1c4a875d3c
--- /dev/null
+++ b/client/src/main/java/com/vaadin/client/widget/escalator/events/RowHeightChangedEvent.java
@@ -0,0 +1,48 @@
+/*
+ * 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.client.widget.escalator.events;
+
+import com.google.gwt.event.shared.GwtEvent;
+
+/**
+ * Event fired when the row height changed in the Escalator's header, body or
+ * footer.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class RowHeightChangedEvent extends GwtEvent<RowHeightChangedHandler> {
+
+ /**
+ * Handler type.
+ */
+ public final static Type<RowHeightChangedHandler> TYPE = new Type<RowHeightChangedHandler>();
+
+ public static final Type<RowHeightChangedHandler> getType() {
+ return TYPE;
+ }
+
+ @Override
+ public Type<RowHeightChangedHandler> getAssociatedType() {
+ return TYPE;
+ }
+
+ @Override
+ protected void dispatch(RowHeightChangedHandler handler) {
+ handler.onRowHeightChanged(this);
+ }
+
+}
diff --git a/client/src/main/java/com/vaadin/client/widget/escalator/events/RowHeightChangedHandler.java b/client/src/main/java/com/vaadin/client/widget/escalator/events/RowHeightChangedHandler.java
new file mode 100644
index 0000000000..8ad243a73d
--- /dev/null
+++ b/client/src/main/java/com/vaadin/client/widget/escalator/events/RowHeightChangedHandler.java
@@ -0,0 +1,35 @@
+/*
+ * 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.client.widget.escalator.events;
+
+import com.google.gwt.event.shared.EventHandler;
+
+/**
+ * Event handler for a row height changed event.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public interface RowHeightChangedHandler extends EventHandler {
+
+ /**
+ * A row height changed event, fired by Escalator when the header, body or
+ * footer row height has changed.
+ *
+ * @param event Row height changed event
+ */
+ public void onRowHeightChanged(RowHeightChangedEvent event);
+}
diff --git a/client/src/main/java/com/vaadin/client/widgets/Escalator.java b/client/src/main/java/com/vaadin/client/widgets/Escalator.java
index 2005881b40..52f981fe63 100644
--- a/client/src/main/java/com/vaadin/client/widgets/Escalator.java
+++ b/client/src/main/java/com/vaadin/client/widgets/Escalator.java
@@ -85,6 +85,7 @@ import com.vaadin.client.widget.escalator.ScrollbarBundle.HorizontalScrollbarBun
import com.vaadin.client.widget.escalator.ScrollbarBundle.VerticalScrollbarBundle;
import com.vaadin.client.widget.escalator.Spacer;
import com.vaadin.client.widget.escalator.SpacerUpdater;
+import com.vaadin.client.widget.escalator.events.RowHeightChangedEvent;
import com.vaadin.client.widget.grid.events.ScrollEvent;
import com.vaadin.client.widget.grid.events.ScrollHandler;
import com.vaadin.client.widgets.Escalator.JsniUtil.TouchHandlerBundle;
@@ -1895,6 +1896,19 @@ public class Escalator extends Widget implements RequiresResize,
});
}
+ private void fireRowHeightChangedEventFinally() {
+ if (!rowHeightChangedEventFired) {
+ rowHeightChangedEventFired = true;
+ Scheduler.get().scheduleFinally(new ScheduledCommand() {
+ @Override
+ public void execute() {
+ fireEvent(new RowHeightChangedEvent());
+ rowHeightChangedEventFired = false;
+ }
+ });
+ }
+ }
+
public void autodetectRowHeightNow() {
if (!isAttached()) {
// Run again when attached
@@ -1902,6 +1916,8 @@ public class Escalator extends Widget implements RequiresResize,
return;
}
+ final double oldRowHeight = defaultRowHeight;
+
final Element detectionTr = DOM.createTR();
detectionTr.setClassName(getStylePrimaryName() + "-row");
@@ -1920,6 +1936,10 @@ public class Escalator extends Widget implements RequiresResize,
reapplyDefaultRowHeights();
applyHeightByRows();
}
+
+ if (oldRowHeight != defaultRowHeight) {
+ fireRowHeightChangedEventFinally();
+ }
}
@Override
@@ -5432,6 +5452,11 @@ public class Escalator extends Widget implements RequiresResize,
private final BodyRowContainerImpl body = new BodyRowContainerImpl(bodyElem);
private final FooterRowContainer footer = new FooterRowContainer(footElem);
+ /**
+ * Flag for keeping track of {@link RowHeightChangedEvent}s
+ */
+ private boolean rowHeightChangedEventFired = false;
+
private final Scroller scroller = new Scroller();
private final ColumnConfigurationImpl columnConfiguration = new ColumnConfigurationImpl();
@@ -6731,4 +6756,4 @@ public class Escalator extends Widget implements RequiresResize,
double getMinCellWidth(int colIndex) {
return columnConfiguration.getMinCellWidth(colIndex);
}
-}
+} \ No newline at end of file
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 de0706a8d2..7e5838be40 100644
--- a/client/src/main/java/com/vaadin/client/widgets/Grid.java
+++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java
@@ -104,6 +104,8 @@ import com.vaadin.client.widget.escalator.RowVisibilityChangeHandler;
import com.vaadin.client.widget.escalator.ScrollbarBundle.Direction;
import com.vaadin.client.widget.escalator.Spacer;
import com.vaadin.client.widget.escalator.SpacerUpdater;
+import com.vaadin.client.widget.escalator.events.RowHeightChangedEvent;
+import com.vaadin.client.widget.escalator.events.RowHeightChangedHandler;
import com.vaadin.client.widget.grid.AutoScroller;
import com.vaadin.client.widget.grid.AutoScroller.AutoScrollerCallback;
import com.vaadin.client.widget.grid.AutoScroller.ScrollAxis;
@@ -8146,6 +8148,11 @@ public class Grid<T> extends ResizeComposite implements
return addHandler(handler, GridEnabledEvent.TYPE);
}
+ public HandlerRegistration addRowHeightChangedHandler(
+ RowHeightChangedHandler handler) {
+ return escalator.addHandler(handler, RowHeightChangedEvent.TYPE);
+ }
+
/**
* Apply sorting to data source.
*/