Browse Source

Remove editor row discard methods; rename "commit" to "save" (#13334)

Change-Id: Ic7cec3c3750db8a2e0b23a4d38f63e9642999e3e
tags/7.4.0.beta1
Johannes Dahlström 9 years ago
parent
commit
4f41def1e6

+ 3
- 17
client/src/com/vaadin/client/connectors/GridConnector.java View File

@@ -195,12 +195,6 @@ public class GridConnector extends AbstractHasComponentsConnector implements
GridConnector.this.getWidget().editRow(rowIndex);
}

@Override
public void discard(int rowIndex) {
serverInitiated = true;
GridConnector.this.getWidget().discardEditorRow();
}

@Override
public void cancel(int rowIndex) {
serverInitiated = true;
@@ -213,7 +207,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements
}

@Override
public void confirmCommit() {
public void confirmSave() {
endRequest();
}
});
@@ -228,18 +222,10 @@ public class GridConnector extends AbstractHasComponentsConnector implements
}

@Override
public void commit(EditorRowRequest<JSONObject> request) {
if (!handleServerInitiated(request)) {
startRequest(request);
rpc.commit(request.getRowIndex());
}
}

@Override
public void discard(EditorRowRequest<JSONObject> request) {
public void save(EditorRowRequest<JSONObject> request) {
if (!handleServerInitiated(request)) {
startRequest(request);
rpc.discard(request.getRowIndex());
rpc.save(request.getRowIndex());
}
}


+ 5
- 17
client/src/com/vaadin/client/ui/grid/EditorRowHandler.java View File

@@ -16,6 +16,7 @@
package com.vaadin.client.ui.grid;

import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ui.grid.Grid.EditorRow;

/**
* An interface for binding widgets and data to the editor row. Used by the
@@ -149,26 +150,13 @@ public interface EditorRowHandler<T> {
public void cancel(EditorRowRequest<T> request);

/**
* Commits changes in the currently active edit to the data source. Called
* by the editor row when changes are saved.
* Saves changes in the currently active edit to the data source. Called by
* the editor row when changes are saved.
*
* @param request
* the commit request
* the save request
*/
public void commit(EditorRowRequest<T> request);

/**
* Discards any unsaved changes and reloads editor content from the data
* source.
* <p>
* Implementation note: This method may simply call
* {@link #bind(EditorRowRequest) bind} if no other processing needs to be
* done.
*
* @param request
* the discard request
*/
public void discard(EditorRowRequest<T> request);
public void save(EditorRowRequest<T> request);

/**
* Returns a widget instance that is used to edit the values in the given

+ 15
- 49
client/src/com/vaadin/client/ui/grid/Grid.java View File

@@ -950,7 +950,7 @@ public class Grid<T> extends ResizeComposite implements
public static final int KEYCODE_HIDE = KeyCodes.KEY_ESCAPE;

protected enum State {
INACTIVE, ACTIVATING, ACTIVE, COMMITTING
INACTIVE, ACTIVATING, ACTIVE, SAVING
}

private Grid<T> grid;
@@ -1005,7 +1005,7 @@ public class Grid<T> extends ResizeComposite implements

/**
* Cancels the currently active edit and hides the editor. Any changes
* that are not {@link #commit() committed} are lost.
* that are not {@link #save() saved} are lost.
*
* @throws IllegalStateException
* if this editor row is not enabled
@@ -1028,57 +1028,36 @@ public class Grid<T> extends ResizeComposite implements
}

/**
* Commits any unsaved changes to the data source.
* Saves any unsaved changes to the data source.
*
* @throws IllegalStateException
* if this editor row is not enabled
* @throws IllegalStateException
* if this editor row is not in edit mode
*/
public void commit() {
public void save() {
if (!enabled) {
throw new IllegalStateException(
"Cannot commit: EditorRow is not enabled");
"Cannot save: EditorRow is not enabled");
}
if (state != State.ACTIVE) {
throw new IllegalStateException(
"Cannot commit: EditorRow is not in edit mode");
"Cannot save: EditorRow is not in edit mode");
}

state = State.COMMITTING;
state = State.SAVING;

handler.commit(new EditorRowRequest<T>(grid, rowIndex,
handler.save(new EditorRowRequest<T>(grid, rowIndex,
new RequestCallback<T>() {
@Override
public void onResponse(EditorRowRequest<T> request) {
if (state == State.COMMITTING) {
if (state == State.SAVING) {
state = State.ACTIVE;
}
}
}));
}

/**
* Reloads row values from the data source, discarding any unsaved
* changes.
*
* @throws IllegalStateException
* if this editor row is not enabled
* @throws IllegalStateException
* if this editor row is not in edit mode
*/
public void discard() {
if (!enabled) {
throw new IllegalStateException(
"Cannot discard: EditorRow is not enabled");
}
if (state != State.ACTIVE) {
throw new IllegalStateException(
"Cannot discard: EditorRow is not in edit mode");
}
handler.discard(new EditorRowRequest<T>(grid, rowIndex, null));
}

/**
* Returns the handler responsible for binding data and editor widgets
* to this editor row.
@@ -1244,8 +1223,8 @@ public class Grid<T> extends ResizeComposite implements
save.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// TODO should have a mechanism for handling failed commits
commit();
// TODO should have a mechanism for handling failed save
save();
cancel();
}
});
@@ -5013,33 +4992,20 @@ public class Grid<T> extends ResizeComposite implements
}

/**
* Commits any unsaved changes to the data source.
*
* @throws IllegalStateException
* if the editor row is not enabled
* @throws IllegalStateException
* if the editor row is not in edit mode
*/
public void commitEditorRow() {
editorRow.commit();
}

/**
* Reloads values from the data source for the row being edited, discarding
* any unsaved changes.
* Saves any unsaved changes to the data source.
*
* @throws IllegalStateException
* if the editor row is not enabled
* @throws IllegalStateException
* if the editor row is not in edit mode
*/
public void discardEditorRow() {
editorRow.discard();
public void saveEditorRow() {
editorRow.save();
}

/**
* Cancels the currently active edit and hides the editor. Any changes that
* are not {@link #commit() committed} are lost.
* are not {@link #saveEditorRow() saved} are lost.
*
* @throws IllegalStateException
* if the editor row is not enabled

+ 8
- 24
server/src/com/vaadin/ui/Grid.java View File

@@ -1762,19 +1762,10 @@ public class Grid extends AbstractComponent implements SelectionChangeNotifier,
}

@Override
public void commit(int rowIndex) {
public void save(int rowIndex) {
try {
commitEditorRow();
getEditorRowRpc().confirmCommit();
} catch (Exception e) {
handleError(e);
}
}

@Override
public void discard(int rowIndex) {
try {
discardEditorRow();
saveEditorRow();
getEditorRowRpc().confirmSave();
} catch (Exception e) {
handleError(e);
}
@@ -3467,14 +3458,16 @@ public class Grid extends AbstractComponent implements SelectionChangeNotifier,
}

/**
* Commits all changes done to the bound fields.
* Saves all changes done to the bound fields.
* <p>
* <em>Note:</em> This is a pass-through call to the backing field group.
*
* @throws CommitException
* If the commit was aborted
*
* @see FieldGroup#commit()
*/
public void commitEditorRow() throws CommitException {
public void saveEditorRow() throws CommitException {
editorRowFieldGroup.commit();
}

@@ -3493,15 +3486,6 @@ public class Grid extends AbstractComponent implements SelectionChangeNotifier,
editedItemId = null;
}

/**
* Discards all changes done to the bound fields.
* <p>
* <em>Note:</em> This is a pass-through call to the backing field group.
*/
public void discardEditorRow() {
editorRowFieldGroup.discard();
}

void resetEditorRow() {
if (isEditorRowActive()) {
/*
@@ -3562,7 +3546,7 @@ public class Grid extends AbstractComponent implements SelectionChangeNotifier,
/**
* Sets the error handler for this editor row. The error handler is invoked
* for exceptions thrown while processing client requests; specifically when
* {@link #commitEditorRow()} triggered by the client throws a
* {@link #saveEditorRow()} triggered by the client throws a
* CommitException. If the error handler is not set, one is looked up via
* Grid.
*

+ 3
- 11
shared/src/com/vaadin/shared/ui/grid/EditorRowClientRpc.java View File

@@ -33,14 +33,6 @@ public interface EditorRowClientRpc extends ClientRpc {
*/
void bind(int rowIndex);

/**
* Tells the client to discard unsaved changes in the editor row.
*
* @param rowIndex
* the index of the edited row
*/
void discard(int rowIndex);

/**
* Tells the client to cancel editing and hide the editor row.
*
@@ -56,8 +48,8 @@ public interface EditorRowClientRpc extends ClientRpc {
void confirmBind();

/**
* Confirms a pending {@link EditorRowServerRpc#commit(int) commit request}
* sent by the client.
* Confirms a pending {@link EditorRowServerRpc#save(int) save request} sent
* by the client.
*/
void confirmCommit();
void confirmSave();
}

+ 4
- 13
shared/src/com/vaadin/shared/ui/grid/EditorRowServerRpc.java View File

@@ -37,23 +37,14 @@ public interface EditorRowServerRpc extends ServerRpc {
void bind(int rowIndex);

/**
* Asks the server to commit unsaved changes in the editor row to the data
* source. When a commit request is sent, it must be acknowledged with a
* {@link EditorRowClientRpc#confirmCommit() confirm call}.
* Asks the server to save unsaved changes in the editor row to the data
* source. When a save request is sent, it must be acknowledged with a
* {@link EditorRowClientRpc#confirmSave() confirm call}.
*
* @param rowIndex
* the index of the edited row
*/
void commit(int rowIndex);

/**
* Asks the server to replace any unsaved changes with values from the data
* source.
*
* @param rowIndex
* the index of the edited row
*/
void discard(int rowIndex);
void save(int rowIndex);

/**
* Tells the server to cancel editing. When sending a cancel request, the

+ 2
- 8
uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java View File

@@ -816,23 +816,17 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
c.editItem(100);
}
}, null);
createClickAction("Commit", "Editor row", new Command<Grid, String>() {
createClickAction("Save", "Editor row", new Command<Grid, String>() {
@Override
public void execute(Grid c, String value, Object data) {
try {
c.commitEditorRow();
c.saveEditorRow();
} catch (CommitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}, null);
createClickAction("Discard", "Editor row", new Command<Grid, String>() {
@Override
public void execute(Grid c, String value, Object data) {
c.discardEditorRow();
}
}, null);
createClickAction("Cancel edit", "Editor row",
new Command<Grid, String>() {
@Override

+ 11
- 10
uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridEditorRowClientTest.java View File

@@ -121,13 +121,13 @@ public class GridEditorRowClientTest extends GridBasicClientFeaturesTest {
}

@Test
public void testCommit() {
public void testSave() {
selectMenuPath("Component", "Editor row", "Edit row 100");

List<WebElement> widgets = getEditorRow().findElements(
By.className("gwt-TextBox"));
WebElement textField = getEditorRow().findElements(
By.className("gwt-TextBox")).get(0);

widgets.get(0).sendKeys(" changed");
textField.sendKeys(" changed");

WebElement saveButton = getEditorRow().findElement(
By.className("v-editor-row-save"));
@@ -139,16 +139,17 @@ public class GridEditorRowClientTest extends GridBasicClientFeaturesTest {
}

@Test
public void testDiscard() {
public void testProgrammaticSave() {
selectMenuPath("Component", "Editor row", "Edit row 100");

List<WebElement> widgets = getEditorRow().findElements(
By.className("gwt-TextBox"));
WebElement textField = getEditorRow().findElements(
By.className("gwt-TextBox")).get(0);

widgets.get(0).sendKeys(" changed");
textField.sendKeys(" changed");

selectMenuPath("Component", "Editor row", "Discard");
selectMenuPath("Component", "Editor row", "Save");

assertEquals("(100, 0)", getGridElement().getCell(100, 0).getText());
assertEquals("(100, 0) changed", getGridElement().getCell(100, 0)
.getText());
}
}

+ 14
- 11
uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorRowTest.java View File

@@ -118,15 +118,15 @@ public class GridEditorRowTest extends GridBasicFeaturesTest {
}

@Test
public void testCommit() {
public void testSave() {
selectMenuPath("Component", "Editor row", "Edit item 100");

List<WebElement> widgets = getEditorRow().findElements(
By.className("v-textfield"));
WebElement textField = getEditorRow().findElements(
By.className("v-textfield")).get(0);

widgets.get(0).click();
textField.click();

widgets.get(0).sendKeys(" changed");
textField.sendKeys(" changed");

WebElement saveButton = getEditorRow().findElement(
By.className("v-editor-row-save"));
@@ -138,16 +138,19 @@ public class GridEditorRowTest extends GridBasicFeaturesTest {
}

@Test
public void testDiscard() {
public void testProgrammaticSave() {
selectMenuPath("Component", "Editor row", "Edit item 100");

List<WebElement> widgets = getEditorRow().findElements(
By.className("v-textfield"));
WebElement textField = getEditorRow().findElements(
By.className("v-textfield")).get(0);

textField.click();

widgets.get(0).sendKeys(" changed");
textField.sendKeys(" changed");

selectMenuPath("Component", "Editor row", "Discard");
selectMenuPath("Component", "Editor row", "Save");

assertEquals("(100, 0)", getGridElement().getCell(100, 0).getText());
assertEquals("(100, 0) changed", getGridElement().getCell(100, 0)
.getText());
}
}

+ 3
- 15
uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java View File

@@ -114,7 +114,7 @@ public class GridBasicClientFeaturesWidget extends
}

@Override
public void commit(EditorRowRequest<List<Data>> request) {
public void save(EditorRowRequest<List<Data>> request) {
log.setText("Row " + request.getRowIndex() + " edit committed");
List<Data> rowData = ds.getRow(request.getRowIndex());

@@ -135,11 +135,6 @@ public class GridBasicClientFeaturesWidget extends
request.invokeCallback();
}

@Override
public void discard(EditorRowRequest<List<Data>> request) {
bind(request);
}

@Override
public TextBox getWidget(GridColumn<?, List<Data>> column) {
if (grid.getColumns().indexOf(column) == 0
@@ -900,17 +895,10 @@ public class GridBasicClientFeaturesWidget extends
}
}, "Component", "Editor row");

addMenuCommand("Commit", new ScheduledCommand() {
@Override
public void execute() {
grid.commitEditorRow();
}
}, "Component", "Editor row");

addMenuCommand("Discard", new ScheduledCommand() {
addMenuCommand("Save", new ScheduledCommand() {
@Override
public void execute() {
grid.discardEditorRow();
grid.saveEditorRow();
}
}, "Component", "Editor row");


Loading…
Cancel
Save