Skip to content

Commit

Permalink
Disable and restore editor and scroll locking on setEnabled (#16502)
Browse files Browse the repository at this point in the history
Change-Id: I26b612f5a412c4e056d02799ab8f83429ab46cac
  • Loading branch information
Teemu Suo-Anttila committed Jan 27, 2015
1 parent c1149e0 commit a6cb362
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
22 changes: 18 additions & 4 deletions client/src/com/vaadin/client/widgets/Grid.java
Expand Up @@ -1000,7 +1000,7 @@ public void onError(EditorRequest<T> request) {

private void cleanup() {
state = State.ACTIVE;
enableButtons(true);
setButtonsEnabled(true);
saveTimeout.cancel();
}
};
Expand Down Expand Up @@ -1126,7 +1126,7 @@ public void save() {
}

state = State.SAVING;
enableButtons(false);
setButtonsEnabled(false);
saveTimeout.schedule(SAVE_TIMEOUT_MS);
EditorRequest<T> request = new EditorRequest<T>(grid, rowIndex,
saveRequestCallback);
Expand Down Expand Up @@ -1372,7 +1372,13 @@ private void updateHorizontalScrollPosition() {
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);
}
Expand Down Expand Up @@ -3542,7 +3548,15 @@ public void setEnabled(boolean enabled) {

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);
}

Expand Down
Expand Up @@ -232,4 +232,28 @@ public void testNoScrollAfterEditByKeyboard() {
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());
}
}

0 comments on commit a6cb362

Please sign in to comment.