summaryrefslogtreecommitdiffstats
path: root/compatibility-client/src
diff options
context:
space:
mode:
authorAnsku <Ansku@users.noreply.github.com>2017-08-22 14:59:49 +0300
committerAleksi Hietanen <aleksi@vaadin.com>2017-08-22 14:59:49 +0300
commit3b2bea5236718fb13c9885141c0a4dddb323a868 (patch)
treec701551cf723e5ca4424574f96db627fb3457b14 /compatibility-client/src
parent5ef925daa91b1253f170f244e2a992f4f92979e1 (diff)
downloadvaadin-framework-3b2bea5236718fb13c9885141c0a4dddb323a868.tar.gz
vaadin-framework-3b2bea5236718fb13c9885141c0a4dddb323a868.zip
Resize should work within Grid details row (#9808)
Fixes #7341
Diffstat (limited to 'compatibility-client/src')
-rw-r--r--compatibility-client/src/main/java/com/vaadin/v7/client/connectors/GridConnector.java73
-rw-r--r--compatibility-client/src/main/java/com/vaadin/v7/client/widgets/Grid.java13
2 files changed, 82 insertions, 4 deletions
diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/connectors/GridConnector.java b/compatibility-client/src/main/java/com/vaadin/v7/client/connectors/GridConnector.java
index 87a4c90360..771f06881a 100644
--- a/compatibility-client/src/main/java/com/vaadin/v7/client/connectors/GridConnector.java
+++ b/compatibility-client/src/main/java/com/vaadin/v7/client/connectors/GridConnector.java
@@ -50,6 +50,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.ui.layout.ElementResizeEvent;
+import com.vaadin.client.ui.layout.ElementResizeListener;
import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.data.sort.SortDirection;
import com.vaadin.shared.ui.Connect;
@@ -496,17 +498,67 @@ public class GridConnector extends AbstractHasComponentsConnector
private final Map<String, ComponentConnector> idToDetailsMap = new HashMap<String, ComponentConnector>();
private final Map<String, Integer> idToRowIndex = new HashMap<String, Integer>();
+ private final Map<Element, ScheduledCommand> elementToResizeCommand = new HashMap<Element, Scheduler.ScheduledCommand>();
+ private final ElementResizeListener detailsRowResizeListener = new ElementResizeListener() {
+
+ @Override
+ public void onElementResize(ElementResizeEvent e) {
+ if (elementToResizeCommand.containsKey(e.getElement())) {
+ Scheduler.get().scheduleFinally(
+ elementToResizeCommand.get(e.getElement()));
+ }
+ }
+ };
+
+ /* calculated when the first details row is opened */
+ private Double spacerCellBorderHeights = null;
@Override
public Widget getDetails(int rowIndex) {
String id = getId(rowIndex);
- if (id == null) {
+ if (id == null || !hasDetailsOpen(rowIndex)) {
return null;
}
ComponentConnector componentConnector = idToDetailsMap.get(id);
idToRowIndex.put(id, rowIndex);
- return componentConnector.getWidget();
+ Widget widget = componentConnector.getWidget();
+ getLayoutManager().addElementResizeListener(widget.getElement(),
+ detailsRowResizeListener);
+ elementToResizeCommand.put(widget.getElement(),
+ createResizeCommand(rowIndex, widget.getElement()));
+
+ return widget;
+ }
+
+ private ScheduledCommand createResizeCommand(final int rowIndex,
+ final Element element) {
+ return new ScheduledCommand() {
+
+ @Override
+ public void execute() {
+ // It should not be possible to get here without calculating
+ // the spacerCellBorderHeights or without having the details
+ // row open, nor for this command to be triggered while
+ // layout is running, but it's safer to check anyway.
+ if (spacerCellBorderHeights != null
+ && !getLayoutManager().isLayoutRunning()
+ && hasDetailsOpen(rowIndex)) {
+ double height = getLayoutManager().getOuterHeightDouble(
+ element) + spacerCellBorderHeights;
+ getWidget().setDetailsHeight(rowIndex, height);
+ }
+ }
+ };
+ }
+
+ private boolean hasDetailsOpen(int rowIndex) {
+ JsonObject row = getWidget().getDataSource().getRow(rowIndex);
+ if (row.hasKey(GridState.JSONKEY_DETAILS_VISIBLE)) {
+ String id = row.getString(GridState.JSONKEY_DETAILS_VISIBLE);
+ return id != null && !id.isEmpty();
+ }
+ return false;
}
@Override
@@ -519,8 +571,16 @@ public class GridConnector extends AbstractHasComponentsConnector
getLayoutManager().setNeedsMeasureRecursively(componentConnector);
getLayoutManager().layoutNow();
- return getLayoutManager().getOuterHeightDouble(
- componentConnector.getWidget().getElement());
+ Element element = componentConnector.getWidget().getElement();
+ if (spacerCellBorderHeights == null) {
+ // If theme is changed, new details generator is created from
+ // scratch, so this value doesn't need to be updated elsewhere.
+ spacerCellBorderHeights = WidgetUtil
+ .getBorderTopAndBottomThickness(
+ element.getParentElement());
+ }
+
+ return getLayoutManager().getOuterHeightDouble(element);
}
/**
@@ -568,6 +628,11 @@ public class GridConnector extends AbstractHasComponentsConnector
}
for (String id : removedDetails) {
+ Element element = idToDetailsMap.get(id).getWidget()
+ .getElement();
+ elementToResizeCommand.remove(element);
+ getLayoutManager().removeElementResizeListener(element,
+ detailsRowResizeListener);
idToDetailsMap.remove(id);
idToRowIndex.remove(id);
}
diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/widgets/Grid.java b/compatibility-client/src/main/java/com/vaadin/v7/client/widgets/Grid.java
index 3efb253e3a..a5e77a0b15 100644
--- a/compatibility-client/src/main/java/com/vaadin/v7/client/widgets/Grid.java
+++ b/compatibility-client/src/main/java/com/vaadin/v7/client/widgets/Grid.java
@@ -9110,6 +9110,19 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
}
/**
+ * Update details row height.
+ *
+ * @since
+ * @param rowIndex
+ * the index of the row for which to update details height
+ * @param height
+ * new height of the details row
+ */
+ public void setDetailsHeight(int rowIndex, double height) {
+ escalator.getBody().setSpacer(rowIndex, height);
+ }
+
+ /**
* Requests that the column widths should be recalculated.
* <p>
* The actual recalculation is not necessarily done immediately so you