This patch adds a minimal editor subpart support.
Change-Id: I36a81cb432f71821715cb60338a07a289bdae18d
import com.vaadin.client.widget.grid.sort.SortHandler;
import com.vaadin.client.widget.grid.sort.SortOrder;
import com.vaadin.client.widgets.Escalator.AbstractRowContainer;
+import com.vaadin.client.widgets.Grid.Editor.State;
import com.vaadin.shared.data.sort.SortDirection;
import com.vaadin.shared.ui.grid.GridConstants;
import com.vaadin.shared.ui.grid.GridStaticCellType;
container = escalator.getBody();
} else if (type.equalsIgnoreCase("footer")) {
container = escalator.getFooter();
+ } else if (type.equalsIgnoreCase("editor")) {
+ if (editor.getState() != State.ACTIVE) {
+ // Editor is not there.
+ return null;
+ }
+
+ if (indices.length == 0) {
+ return DOM.asOld(editor.editorOverlay);
+ } else if (indices.length == 1 && indices[0] < columns.size()) {
+ escalator.scrollToColumn(indices[0], ScrollDestination.ANY, 0);
+ return editor.getWidget(columns.get(indices[0])).getElement();
+ } else {
+ return null;
+ }
}
if (null != container) {
+ (containerRow ? "]" : "][" + cell.getColumn() + "]");
}
}
+
+ // Check if subelement is part of editor.
+ if (editor.getState() == State.ACTIVE) {
+ if (editor.editorOverlay.isOrHasChild(subElement)) {
+ int i = 0;
+ for (Column<?, T> column : columns) {
+ if (editor.getWidget(column).getElement()
+ .isOrHasChild(subElement)) {
+ return "editor[" + i + "]";
+ }
+ ++i;
+ }
+ return "editor";
+ }
+ }
+
return null;
}
try {
Object id = getContainerDataSource().getIdByIndex(rowIndex);
doEditItem(id);
- getEditorRpc().confirmBind();
} catch (Exception e) {
handleError(e);
}
+ getEditorRpc().confirmBind();
}
@Override
public void save(int rowIndex) {
try {
saveEditor();
- getEditorRpc().confirmSave();
} catch (Exception e) {
handleError(e);
}
+ getEditorRpc().confirmSave();
}
private void handleError(Exception e) {
}
}
+ public static class GridEditorElement extends AbstractElement {
+
+ private GridElement grid;
+
+ private GridEditorElement setGrid(GridElement grid) {
+ this.grid = grid;
+ return this;
+ }
+
+ /**
+ * Gets the editor field for column in given index.
+ *
+ * @param colIndex
+ * column index
+ * @return the editor field for given location
+ */
+ public TestBenchElement getField(int colIndex) {
+ return grid.getSubPart("#editor[" + colIndex + "]");
+ }
+
+ /**
+ * Saves the fields of this editor.
+ * <p>
+ * <em>Note:</em> that this closes the editor making this element
+ * useless.
+ */
+ public void save() {
+ getField(0);
+ List<WebElement> buttons = findElements(By.xpath("./button"));
+ buttons.get(0).click();
+ }
+
+ /**
+ * Cancels this editor.
+ * <p>
+ * <em>Note:</em> that this closes the editor making this element
+ * useless.
+ */
+ public void cancel() {
+ getField(0);
+ List<WebElement> buttons = findElements(By.xpath("./button"));
+ buttons.get(1).click();
+ }
+ }
+
/**
* Scrolls Grid element so that wanted row is displayed
*
return rootElements.get(2);
}
+ public GridEditorElement getEditor() {
+ return getSubPart("#editor").wrap(GridEditorElement.class)
+ .setGrid(this);
+ }
+
/**
* Helper function to get Grid subparts wrapped correctly
*
private TestBenchElement getSubPart(String subPartSelector) {
return (TestBenchElement) findElement(By.vaadin(subPartSelector));
}
-
}
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.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
+import com.vaadin.testbench.elements.GridElement.GridEditorElement;
+import com.vaadin.testbench.elements.NotificationElement;
import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures;
import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
@Before
public void setUp() {
+ setDebug(true);
openTestURL();
selectMenuPath("Component", "Editor", "Enabled");
}
return getEditor().findElements(By.className("v-textfield"));
}
+
+ @Test
+ public void testInvalidEdition() {
+ selectMenuPath("Component", "Editor", "Edit item 5");
+ assertFalse(logContainsText("Exception occured, java.lang.IllegalStateException"));
+ GridEditorElement editor = getGridElement().getEditor();
+ WebElement intField = editor.getField(7);
+ intField.clear();
+ intField.sendKeys("banana phone");
+ editor.save();
+ assertTrue(
+ "No exception on invalid value.",
+ logContainsText("Exception occured, com.vaadin.data.fieldgroup.FieldGroup$CommitExceptionCommit failed"));
+ selectMenuPath("Component", "Editor", "Edit item 100");
+ assertFalse("Exception should not exist",
+ isElementPresent(NotificationElement.class));
+ }
}