diff options
author | Teemu Suo-Anttila <teemusa@vaadin.com> | 2015-01-27 12:54:04 +0200 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2015-01-27 13:09:58 +0200 |
commit | a6cb362fa4564d32020d78cc1444bd8a1ec44ff6 (patch) | |
tree | be5336ea08b51e551a67e8fe0112cc2d09742120 | |
parent | c1149e055871365fcf280bfcd4f1adc4439deb84 (diff) | |
download | vaadin-framework-a6cb362fa4564d32020d78cc1444bd8a1ec44ff6.tar.gz vaadin-framework-a6cb362fa4564d32020d78cc1444bd8a1ec44ff6.zip |
Disable and restore editor and scroll locking on setEnabled (#16502)
Change-Id: I26b612f5a412c4e056d02799ab8f83429ab46cac
-rw-r--r-- | client/src/com/vaadin/client/widgets/Grid.java | 22 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java | 24 |
2 files changed, 42 insertions, 4 deletions
diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index 93e94b8447..78d1fd4197 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -1000,7 +1000,7 @@ public class Grid<T> extends ResizeComposite implements private void cleanup() { state = State.ACTIVE; - enableButtons(true); + setButtonsEnabled(true); saveTimeout.cancel(); } }; @@ -1126,7 +1126,7 @@ public class Grid<T> extends ResizeComposite implements } state = State.SAVING; - enableButtons(false); + setButtonsEnabled(false); saveTimeout.schedule(SAVE_TIMEOUT_MS); EditorRequest<T> request = new EditorRequest<T>(grid, rowIndex, saveRequestCallback); @@ -1372,7 +1372,13 @@ public class Grid<T> extends ResizeComposite implements editorOverlay.getStyle().setLeft(-grid.getScrollLeft(), Unit.PX); } - private void enableButtons(boolean enabled) { + protected void setGridEnabled(boolean enabled) { + // TODO: This should be informed to handler as well so possible + // fields can be disabled. + setButtonsEnabled(enabled); + } + + private void setButtonsEnabled(boolean enabled) { saveButton.setEnabled(enabled); cancelButton.setEnabled(enabled); } @@ -3542,7 +3548,15 @@ public class Grid<T> extends ResizeComposite implements this.enabled = enabled; getElement().setTabIndex(enabled ? 0 : -1); - getEscalator().setScrollLocked(Direction.VERTICAL, !enabled); + + // Editor save and cancel buttons need to be disabled. + boolean editorOpen = editor.getState() != State.INACTIVE; + if (editorOpen) { + editor.setGridEnabled(enabled); + } + + getEscalator().setScrollLocked(Direction.VERTICAL, + !enabled || editorOpen); getEscalator().setScrollLocked(Direction.HORIZONTAL, !enabled); } diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java index 97a59291ed..0218fffe61 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java @@ -232,4 +232,28 @@ public class GridEditorTest extends GridBasicFeaturesTest { assertEquals("Grid shouldn't scroll vertically while editing", originalScrollPos, getGridVerticalScrollPos()); } + + @Test + public void testEditorInDisabledGrid() { + int originalScrollPos = getGridVerticalScrollPos(); + + selectMenuPath(EDIT_ITEM_5); + assertEditorOpen(); + + selectMenuPath("Component", "State", "Enabled"); + assertEditorOpen(); + + GridEditorElement editor = getGridElement().getEditor(); + editor.save(); + assertEditorOpen(); + + editor.cancel(); + assertEditorOpen(); + + selectMenuPath("Component", "State", "Enabled"); + + scrollGridVerticallyTo(100); + assertEquals("Grid shouldn't scroll vertically while editing", + originalScrollPos, getGridVerticalScrollPos()); + } } |