summaryrefslogtreecommitdiffstats
path: root/client/src
diff options
context:
space:
mode:
authorAnna Koskinen <Ansku@users.noreply.github.com>2018-03-21 15:54:26 +0200
committerIlia Motornyi <elmot@vaadin.com>2018-03-21 15:54:26 +0200
commit1187cf22f06df587b2a1ec1068be88e2b70c888d (patch)
tree9712c2700de577ec195e1b159aaf51dd27ee65bc /client/src
parent940a1ef584c82e343474863408771ff091044bdc (diff)
downloadvaadin-framework-1187cf22f06df587b2a1ec1068be88e2b70c888d.tar.gz
vaadin-framework-1187cf22f06df587b2a1ec1068be88e2b70c888d.zip
Grid editor open (#10674)
Diffstat (limited to 'client/src')
-rw-r--r--client/src/main/java/com/vaadin/client/WidgetUtil.java51
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/EditorConnector.java14
-rwxr-xr-xclient/src/main/java/com/vaadin/client/widgets/Grid.java96
3 files changed, 123 insertions, 38 deletions
diff --git a/client/src/main/java/com/vaadin/client/WidgetUtil.java b/client/src/main/java/com/vaadin/client/WidgetUtil.java
index 11a5ae363c..b995ef15c0 100644
--- a/client/src/main/java/com/vaadin/client/WidgetUtil.java
+++ b/client/src/main/java/com/vaadin/client/WidgetUtil.java
@@ -52,6 +52,37 @@ import com.vaadin.shared.util.SharedUtil;
public class WidgetUtil {
/**
+ * Simple object to store another object.
+ *
+ * @param <T>
+ * the object type to store
+ * @since
+ */
+ public static class Reference<T> {
+
+ T reference = null;
+
+ /**
+ * Gets the current object.
+ *
+ * @return the stored object
+ */
+ public T get() {
+ return reference;
+ }
+
+ /**
+ * Sets the current object.
+ *
+ * @param reference
+ * the object to store
+ */
+ public void set(T reference) {
+ this.reference = reference;
+ }
+ }
+
+ /**
* Helper method for debugging purposes.
*
* Stops execution on firefox browsers on a breakpoint.
@@ -778,7 +809,7 @@ public class WidgetUtil {
com.google.gwt.dom.client.Element el, String p)
/*-{
try {
-
+
if (el.currentStyle) {
// IE
return el.currentStyle[p];
@@ -793,7 +824,7 @@ public class WidgetUtil {
} catch (e) {
return "";
}
-
+
}-*/;
/**
@@ -807,7 +838,7 @@ public class WidgetUtil {
try {
el.focus();
} catch (e) {
-
+
}
}-*/;
@@ -1158,7 +1189,7 @@ public class WidgetUtil {
if ($wnd.document.activeElement) {
return $wnd.document.activeElement;
}
-
+
return null;
}-*/;
@@ -1229,11 +1260,11 @@ public class WidgetUtil {
/*-{
var top = elem.offsetTop;
var height = elem.offsetHeight;
-
+
if (elem.parentNode != elem.offsetParent) {
top -= elem.parentNode.offsetTop;
}
-
+
var cur = elem.parentNode;
while (cur && (cur.nodeType == 1)) {
if (top < cur.scrollTop) {
@@ -1242,12 +1273,12 @@ public class WidgetUtil {
if (top + height > cur.scrollTop + cur.clientHeight) {
cur.scrollTop = (top + height) - cur.clientHeight;
}
-
+
var offsetTop = cur.offsetTop;
if (cur.parentNode != cur.offsetParent) {
offsetTop -= cur.parentNode.offsetTop;
}
-
+
top += offsetTop - cur.scrollTop;
cur = cur.parentNode;
}
@@ -1696,7 +1727,7 @@ public class WidgetUtil {
}
var heightWithoutBorder = cloneElement.offsetHeight;
parentElement.removeChild(cloneElement);
-
+
return heightWithBorder - heightWithoutBorder;
}
}-*/;
@@ -1873,7 +1904,7 @@ public class WidgetUtil {
* ancestors has the style {@code display: none} applied.
*
* @param element
- * the element to test for visibility
+ * the element to test for visibility
* @return {@code true} if the element is displayed, {@code false} otherwise
* @since 8.3.2
*/
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/EditorConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/EditorConnector.java
index c8c60c9620..8e2d050d55 100644
--- a/client/src/main/java/com/vaadin/client/connectors/grid/EditorConnector.java
+++ b/client/src/main/java/com/vaadin/client/connectors/grid/EditorConnector.java
@@ -66,12 +66,7 @@ public class EditorConnector extends AbstractExtensionConnector {
public void bind(final int rowIndex) {
// call this deferred to avoid issues with editing on init
Scheduler.get().scheduleDeferred(() -> {
- currentEditedRow = rowIndex;
- // might need to wait for available data,
- // if data is available, ensureAvailability will immediately trigger the handler anyway,
- // so no need for alternative "immediately available" logic
- waitingForAvailableData = true;
- getParent().getDataSource().ensureAvailability(rowIndex, 1);
+ getParent().getWidget().editRow(rowIndex);
});
}
@@ -218,13 +213,6 @@ public class EditorConnector extends AbstractExtensionConnector {
protected void extend(ServerConnector target) {
Grid<JsonObject> grid = getParent().getWidget();
grid.getEditor().setHandler(new CustomEditorHandler());
- grid.addDataAvailableHandler((event) -> {
- Range range = event.getAvailableRows();
- if (waitingForAvailableData && currentEditedRow != null && range.contains(currentEditedRow)) {
- getParent().getWidget().editRow(currentEditedRow);
- waitingForAvailableData = false;
- }
- });
}
@Override
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 1d24086b3b..5a31ec1f41 100755
--- a/client/src/main/java/com/vaadin/client/widgets/Grid.java
+++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java
@@ -80,6 +80,7 @@ import com.vaadin.client.BrowserInfo;
import com.vaadin.client.DeferredWorker;
import com.vaadin.client.Focusable;
import com.vaadin.client.WidgetUtil;
+import com.vaadin.client.WidgetUtil.Reference;
import com.vaadin.client.data.DataChangeHandler;
import com.vaadin.client.data.DataSource;
import com.vaadin.client.data.DataSource.RowHandle;
@@ -1437,7 +1438,6 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
private String styleName = null;
private HandlerRegistration hScrollHandler;
- private HandlerRegistration vScrollHandler;
private final Button saveButton;
private final Button cancelButton;
@@ -1680,20 +1680,10 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
}
state = State.ACTIVATING;
- final Escalator escalator = grid.getEscalator();
- if (escalator.getVisibleRowRange().contains(rowIndex)) {
- show(rowIndex, columnIndexDOM);
- } else {
- vScrollHandler = grid.addScrollHandler(event -> {
- if (escalator.getVisibleRowRange().contains(rowIndex)) {
- show(rowIndex, columnIndexDOM);
- vScrollHandler.removeHandler();
- }
- });
- grid.scrollToRow(rowIndex,
- isBuffered() ? ScrollDestination.MIDDLE
- : ScrollDestination.ANY);
- }
+ grid.scrollToRow(rowIndex,
+ isBuffered() ? ScrollDestination.MIDDLE
+ : ScrollDestination.ANY,
+ () -> show(rowIndex, columnIndexDOM));
}
/**
@@ -7384,6 +7374,45 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
}
/**
+ * Helper method for making sure desired row is visible and it is properly
+ * rendered.
+ *
+ * @param rowIndex
+ * the row to look for
+ * @param destination
+ * the desired scroll destination
+ * @param callback
+ * the callback command to execute when row is available
+ * @since
+ */
+ public void scrollToRow(int rowIndex, ScrollDestination destination,
+ Runnable callback) {
+ waitUntilVisible(rowIndex, destination, () -> {
+ Reference<HandlerRegistration> registration = new Reference<>();
+ registration.set(addDataAvailableHandler(event -> {
+ if (event.getAvailableRows().contains(rowIndex)) {
+ registration.get().removeHandler();
+ callback.run();
+ }
+ }));
+ });
+ }
+
+ /**
+ * Helper method for making sure desired row is visible and it is properly
+ * rendered.
+ *
+ * @param rowIndex
+ * the row to look for
+ * @param whenRendered
+ * the callback command to execute when row is available
+ * @since
+ */
+ public void scrollToRow(int rowIndex, Runnable whenRendered) {
+ scrollToRow(rowIndex, ScrollDestination.ANY, whenRendered);
+ }
+
+ /**
* Scrolls to a certain row using only user-specified parameters.
* <p>
* If the details for that row are visible, those will be taken into account
@@ -7421,6 +7450,43 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
}
/**
+ * Helper method for scrolling and making sure row is visible.
+ *
+ * @param rowIndex
+ * the row index to make visible
+ * @param destination
+ * the desired scroll destination
+ * @param whenVisible
+ * the callback method to call when row is visible
+ */
+ private void waitUntilVisible(int rowIndex, ScrollDestination destination,
+ Runnable whenVisible) {
+ final Escalator escalator = getEscalator();
+ if (escalator.getVisibleRowRange().contains(rowIndex)) {
+ TableRowElement rowElement = escalator.getBody()
+ .getRowElement(rowIndex);
+ long bottomBorder = Math.round(WidgetUtil.getBorderBottomThickness(
+ rowElement.getFirstChildElement()) + 0.5d);
+ if (rowElement.getAbsoluteTop() >= escalator.getHeader()
+ .getElement().getAbsoluteBottom()
+ && rowElement.getAbsoluteBottom() <= escalator.getFooter()
+ .getElement().getAbsoluteTop() + bottomBorder) {
+ whenVisible.run();
+ return;
+ }
+ }
+
+ Reference<HandlerRegistration> registration = new Reference<>();
+ registration.set(addScrollHandler(event -> {
+ if (escalator.getVisibleRowRange().contains(rowIndex)) {
+ registration.get().removeHandler();
+ whenVisible.run();
+ }
+ }));
+ scrollToRow(rowIndex, destination);
+ }
+
+ /**
* Scrolls to the beginning of the very first row.
*/
public void scrollToStart() {