diff options
author | Teppo Kurki <teppo.kurki@vaadin.com> | 2015-06-02 15:08:03 +0300 |
---|---|---|
committer | Teppo Kurki <teppo.kurki@vaadin.com> | 2015-06-04 16:17:13 +0300 |
commit | 1b67d65d9718745edc69a51c082e917a2bbee2e0 (patch) | |
tree | 7f7176ce00d52b36f9351e0ef76aa27afc019e7f | |
parent | a4b2dc6caf82487903e583edfa30eec837bbb5b1 (diff) | |
download | vaadin-framework-1b67d65d9718745edc69a51c082e917a2bbee2e0.tar.gz vaadin-framework-1b67d65d9718745edc69a51c082e917a2bbee2e0.zip |
Allow programmatically opening editor in unbuffered mode
..when the editor is already open on another row
Change-Id: Ibec04dc7b1559149cf33e36fada8d676d943fc72
4 files changed, 48 insertions, 15 deletions
diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index db3cea58dc..834280d89d 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -1209,7 +1209,6 @@ public class Grid<T> extends ResizeComposite implements assert rowIndex == request.getRowIndex() : "Request row index " + request.getRowIndex() + " did not match the saved row index " + rowIndex; - showOverlay(); } } @@ -1316,7 +1315,8 @@ public class Grid<T> extends ResizeComposite implements * @throws IllegalStateException * if this editor is not enabled * @throws IllegalStateException - * if this editor is already in edit mode + * if this editor is already in edit mode and in buffered + * mode * * @since 7.5 */ @@ -1326,8 +1326,10 @@ public class Grid<T> extends ResizeComposite implements "Cannot edit row: editor is not enabled"); } if (state != State.INACTIVE) { - throw new IllegalStateException( - "Cannot edit row: editor already in edit mode"); + if (isBuffered()) { + throw new IllegalStateException( + "Cannot edit row: editor already in edit mode"); + } } this.rowIndex = rowIndex; @@ -1474,13 +1476,6 @@ public class Grid<T> extends ResizeComposite implements } } - protected void hide() { - hideOverlay(); - grid.getEscalator().setScrollLocked(Direction.VERTICAL, false); - state = State.INACTIVE; - updateSelectionCheckboxesAsNeeded(true); - } - protected void setGrid(final Grid<T> grid) { assert grid != null : "Grid cannot be null"; assert this.grid == null : "Can only attach editor to Grid once"; @@ -1539,6 +1534,8 @@ public class Grid<T> extends ResizeComposite implements * @since 7.5 */ protected void showOverlay() { + // Ensure overlay is hidden initially + hideOverlay(); DivElement gridElement = DivElement.as(grid.getElement()); @@ -1646,6 +1643,10 @@ public class Grid<T> extends ResizeComposite implements } protected void hideOverlay() { + if (editorOverlay.getParentElement() == null) { + return; + } + for (Widget w : columnToWidget.values()) { setParent(w, null); } @@ -6492,7 +6493,6 @@ public class Grid<T> extends ResizeComposite implements return true; } else if (editorIsActive && moveEvent) { - editor.hide(); cellFocusHandler.setCellFocus(eventCell); editor.editRow(eventCell.getRowIndex(), diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java index 74f58ecf74..68676e5435 100644 --- a/server/src/com/vaadin/ui/Grid.java +++ b/server/src/com/vaadin/ui/Grid.java @@ -3383,7 +3383,8 @@ public class Grid extends AbstractFocusable implements SelectionNotifier, private final String nullRepresentation; - protected AbstractRenderer(Class<T> presentationType, String nullRepresentation) { + protected AbstractRenderer(Class<T> presentationType, + String nullRepresentation) { this.presentationType = presentationType; this.nullRepresentation = nullRepresentation; } @@ -3428,6 +3429,7 @@ public class Grid extends AbstractFocusable implements SelectionNotifier, /** * Null representation for the renderer + * * @return a textual representation of {@code null} */ protected String getNullRepresentation() { @@ -5819,7 +5821,8 @@ public class Grid extends AbstractFocusable implements SelectionNotifier, * @param itemId * the id of the item to edit * @throws IllegalStateException - * if the editor is not enabled or already editing an item + * if the editor is not enabled or already editing an item in + * buffered mode * @throws IllegalArgumentException * if the {@code itemId} is not in the backing container * @see #setEditorEnabled(boolean) @@ -5828,7 +5831,7 @@ public class Grid extends AbstractFocusable implements SelectionNotifier, IllegalArgumentException { if (!isEditorEnabled()) { throw new IllegalStateException("Item editor is not enabled"); - } else if (editedItemId != null) { + } else if (isEditorBuffered() && editedItemId != null) { throw new IllegalStateException("Editing item + " + itemId + " failed. Item editor is already editing item " + editedItemId); diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorBufferedTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorBufferedTest.java index 606fe783d4..728c32af5d 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorBufferedTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorBufferedTest.java @@ -214,4 +214,20 @@ public class GridEditorBufferedTest extends GridEditorTest { getGridElement().getCell(4, 0).doubleClick(); assertEditorClosed(); } + + @Test + public void testProgrammaticOpeningWhenOpen() { + selectMenuPath(EDIT_ITEM_5); + assertEditorOpen(); + assertEquals("Editor should edit row 5", "(5, 0)", getEditorWidgets() + .get(0).getAttribute("value")); + + selectMenuPath(EDIT_ITEM_100); + boolean thrown = logContainsText("Exception occured, java.lang.IllegalStateException"); + assertTrue("IllegalStateException thrown", thrown); + + assertEditorOpen(); + assertEquals("Editor should still edit row 5", "(5, 0)", + getEditorWidgets().get(0).getAttribute("value")); + } } diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorUnbufferedTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorUnbufferedTest.java index 90a4c8b0b1..4725d24903 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorUnbufferedTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorUnbufferedTest.java @@ -15,6 +15,7 @@ */ package com.vaadin.tests.components.grid.basicfeatures.server; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -162,4 +163,17 @@ public class GridEditorUnbufferedTest extends GridEditorTest { getGridElement().getCell(4, 0).doubleClick(); assertEditorClosed(); } + + @Test + public void testProgrammaticOpeningWhenOpen() { + selectMenuPath(EDIT_ITEM_5); + assertEditorOpen(); + assertEquals("Editor should edit row 5", "(5, 0)", getEditorWidgets() + .get(0).getAttribute("value")); + + selectMenuPath(EDIT_ITEM_100); + assertEditorOpen(); + assertEquals("Editor should edit row 100", "(100, 0)", + getEditorWidgets().get(0).getAttribute("value")); + } }
\ No newline at end of file |