summaryrefslogtreecommitdiffstats
path: root/server/src
diff options
context:
space:
mode:
authorPiotr Wilkin <piotr.wilkin@syndatis.com>2017-10-10 12:02:47 +0200
committerHenri Sara <henri.sara@gmail.com>2017-10-10 13:02:47 +0300
commit802bb98b851ab9b15617b283ccdba3dbc517ada6 (patch)
tree1edbb81782e941e2a6332fe9b610f9d1fe357c87 /server/src
parenta8f23e84a0fbb5da515cacffb8f5a85fd4c21694 (diff)
downloadvaadin-framework-802bb98b851ab9b15617b283ccdba3dbc517ada6.tar.gz
vaadin-framework-802bb98b851ab9b15617b283ccdba3dbc517ada6.zip
Edit grid row by index - server side (#10040)
Opening grid editor from server side. Fixes #8477. Addressing #8820 will be the user's responsibility as fetching index of item might be slow.
Diffstat (limited to 'server/src')
-rw-r--r--server/src/main/java/com/vaadin/data/provider/DataCommunicator.java2
-rw-r--r--server/src/main/java/com/vaadin/data/provider/HierarchicalDataCommunicator.java2
-rw-r--r--server/src/main/java/com/vaadin/ui/components/grid/Editor.java10
-rw-r--r--server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java37
4 files changed, 49 insertions, 2 deletions
diff --git a/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java b/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java
index 9996d8d1aa..66bf758efe 100644
--- a/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java
+++ b/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java
@@ -370,7 +370,7 @@ public class DataCommunicator<T> extends AbstractExtension {
* @since 8.1
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
- protected List<T> fetchItemsWithRange(int offset, int limit) {
+ public List<T> fetchItemsWithRange(int offset, int limit) {
return (List<T>) getDataProvider().fetch(new Query(offset, limit,
backEndSorting, inMemorySorting, filter))
.collect(Collectors.toList());
diff --git a/server/src/main/java/com/vaadin/data/provider/HierarchicalDataCommunicator.java b/server/src/main/java/com/vaadin/data/provider/HierarchicalDataCommunicator.java
index 627cc28651..b0397ffcc7 100644
--- a/server/src/main/java/com/vaadin/data/provider/HierarchicalDataCommunicator.java
+++ b/server/src/main/java/com/vaadin/data/provider/HierarchicalDataCommunicator.java
@@ -66,7 +66,7 @@ public class HierarchicalDataCommunicator<T> extends DataCommunicator<T> {
}
@Override
- protected List<T> fetchItemsWithRange(int offset, int limit) {
+ public List<T> fetchItemsWithRange(int offset, int limit) {
// Instead of adding logic to this class, delegate request to the
// separate object handling hierarchies.
return mapper.fetchItems(Range.withLength(offset, limit))
diff --git a/server/src/main/java/com/vaadin/ui/components/grid/Editor.java b/server/src/main/java/com/vaadin/ui/components/grid/Editor.java
index 26ef8101ab..8c34fbdf64 100644
--- a/server/src/main/java/com/vaadin/ui/components/grid/Editor.java
+++ b/server/src/main/java/com/vaadin/ui/components/grid/Editor.java
@@ -104,6 +104,16 @@ public interface Editor<T> extends Serializable {
public void cancel();
/**
+ * Edits the selected row
+ *
+ * @param rowNumber
+ * the row to edit
+ *
+ * @since 8.2
+ */
+ public void editRow(int rowNumber);
+
+ /**
* Sets the caption of the save button in buffered mode.
*
* @param saveCaption
diff --git a/server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java b/server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java
index 4d5e91b671..7329677ca3 100644
--- a/server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java
+++ b/server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java
@@ -267,6 +267,43 @@ public class EditorImpl<T> extends AbstractGridExtension<T>
rpc.cancel();
}
+ /**
+ * Opens the editor interface for the provided row. Scrolls the Grid to
+ * bring the row to view if it is not already visible.
+ *
+ * Note that any cell content rendered by a WidgetRenderer will not be
+ * visible in the editor row.
+ *
+ * @param rowNumber
+ * the row number of the edited item
+ * @throws IllegalStateException
+ * if the editor is not enabled or already editing a different item
+ * in buffered mode
+ * @throws IllegalArgumentException
+ * if the {@code rowNumber} is not in the backing data provider
+ * @see #setEnabled(boolean)
+ */
+ public void editRow(int rowNumber)
+ throws IllegalStateException, IllegalArgumentException {
+ if (!isEnabled()) {
+ throw new IllegalStateException("Item editor is not enabled");
+ }
+ T beanToEdit = getParent().getDataCommunicator().
+ fetchItemsWithRange(rowNumber, 1).
+ stream().findFirst().orElseThrow(() -> new IllegalArgumentException(
+ "Row number " + rowNumber+ "did not yield any item from data provider"));
+ if (!beanToEdit.equals(edited)) {
+ if (isBuffered() && edited != null) {
+ throw new IllegalStateException("Editing item " + beanToEdit
+ + " failed. Item editor is already editing item "
+ + edited);
+ } else {
+ rpc.bind(rowNumber);
+ }
+ }
+
+ }
+
private void doCancel(boolean afterBeingSaved) {
T editedBean = edited;
doClose();