private HandlerRegistration scrollHandler;
- private Button saveButton;
- private Button cancelButton;
+ private final Button saveButton;
+ private final Button cancelButton;
private static final int SAVE_TIMEOUT_MS = 5000;
private final Timer saveTimeout = new Timer() {
}
};
+ public Editor() {
+ saveButton = new Button();
+ saveButton.setText(GridConstants.DEFAULT_SAVE_CAPTION);
+ saveButton.setStylePrimaryName("v-nativebutton");
+ saveButton.addClickHandler(new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ save();
+ }
+ });
+
+ cancelButton = new Button();
+ cancelButton.setText(GridConstants.DEFAULT_CANCEL_CAPTION);
+ cancelButton.setStylePrimaryName("v-nativebutton");
+ cancelButton.addClickHandler(new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ cancel();
+ }
+ });
+ }
+
public int getRow() {
return rowIndex;
}
}
}
- saveButton = new Button();
- saveButton.setText("Save");
- saveButton.setStylePrimaryName("v-nativebutton");
- saveButton.addStyleName(styleName + "-save");
- saveButton.addClickHandler(new ClickHandler() {
- @Override
- public void onClick(ClickEvent event) {
- save();
- }
- });
attachWidget(saveButton, editorOverlay);
-
- cancelButton = new Button();
- cancelButton.setText("Cancel");
- cancelButton.setStylePrimaryName("v-nativebutton");
- cancelButton.addStyleName(styleName + "-cancel");
- cancelButton.addClickHandler(new ClickHandler() {
- @Override
- public void onClick(ClickEvent event) {
- cancel();
- }
- });
attachWidget(cancelButton, editorOverlay);
/*
}
columnToWidget.clear();
+ detachWidget(saveButton);
+ detachWidget(cancelButton);
+
editorOverlay.removeAllChildren();
editorOverlay.removeFromParent();
protected void setStylePrimaryName(String primaryName) {
if (styleName != null) {
editorOverlay.removeClassName(styleName);
+ saveButton.removeStyleName(styleName + "-save");
+ cancelButton.removeStyleName(styleName + "-cancel");
}
styleName = primaryName + "-editor";
editorOverlay.addClassName(styleName);
+
+ saveButton.addStyleName(styleName + "-save");
+ cancelButton.addStyleName(styleName + "-cancel");
}
/**
setParent(w, grid);
}
+ private void detachWidget(Widget w) {
+ setParent(w, null);
+ w.getElement().removeFromParent();
+ }
+
private static void setBounds(Element e, double left, double top,
double width, double height) {
Style style = e.getStyle();
saveButton.setEnabled(enabled);
cancelButton.setEnabled(enabled);
}
+
+ public void setSaveCaption(String saveCaption)
+ throws IllegalArgumentException {
+ if (saveCaption == null) {
+ throw new IllegalArgumentException(
+ "Save caption cannot be null");
+ }
+ saveButton.setText(saveCaption);
+ }
+
+ public String getSaveCaption() {
+ return saveButton.getText();
+ }
+
+ public void setCancelCaption(String cancelCaption)
+ throws IllegalArgumentException {
+ if (cancelCaption == null) {
+ throw new IllegalArgumentException(
+ "Cancel caption cannot be null");
+ }
+ cancelButton.setText(cancelCaption);
+ }
+
+ public String getCancelCaption() {
+ return cancelButton.getText();
+ }
}
public static abstract class AbstractGridKeyEvent<HANDLER extends AbstractGridKeyEventHandler>
return editor.getWidget(column);
}
+ /**
+ * Sets the caption on the save button in the Grid editor.
+ *
+ * @param saveCaption
+ * the caption to set
+ * @throws IllegalArgumentException
+ * if {@code saveCaption} is {@code null}
+ */
+ public void setEditorSaveCaption(String saveCaption)
+ throws IllegalArgumentException {
+ editor.setSaveCaption(saveCaption);
+ }
+
+ /**
+ * Gets the current caption on the save button in the Grid editor.
+ *
+ * @return the current caption on the save button
+ */
+ public String getEditorSaveCaption() {
+ return editor.getSaveCaption();
+ }
+
+ /**
+ * Sets the caption on the cancel button in the Grid editor.
+ *
+ * @param cancelCaption
+ * the caption to set
+ * @throws IllegalArgumentException
+ * if {@code cancelCaption} is {@code null}
+ */
+ public void setEditorCancelCaption(String cancelCaption)
+ throws IllegalArgumentException {
+ editor.setCancelCaption(cancelCaption);
+ }
+
+ /**
+ * Gets the caption on the cancel button in the Grid editor.
+ *
+ * @return the current caption on the cancel button
+ */
+ public String getEditorCancelCaption() {
+ return editor.getCancelCaption();
+ }
+
@Override
protected void onAttach() {
super.onAttach();
return editorFieldGroup.getFieldFactory();
}
+ /**
+ * Sets the caption on the save button in the Grid editor.
+ *
+ * @param saveCaption
+ * the caption to set
+ * @throws IllegalArgumentException
+ * if {@code saveCaption} is {@code null}
+ */
+ public void setEditorSaveCaption(String saveCaption)
+ throws IllegalArgumentException {
+ if (saveCaption == null) {
+ throw new IllegalArgumentException("Save caption cannot be null");
+ }
+ getState().editorSaveCaption = saveCaption;
+ }
+
+ /**
+ * Gets the current caption of the save button in the Grid editor.
+ *
+ * @return the current caption of the save button
+ */
+ public String getEditorSaveCaption() {
+ return getState(false).editorSaveCaption;
+ }
+
+ /**
+ * Sets the caption on the cancel button in the Grid editor.
+ *
+ * @param cancelCaption
+ * the caption to set
+ * @throws IllegalArgumentException
+ * if {@code cancelCaption} is {@code null}
+ */
+ public void setEditorCancelCaption(String cancelCaption)
+ throws IllegalArgumentException {
+ if (cancelCaption == null) {
+ throw new IllegalArgumentException("Cancel caption cannot be null");
+ }
+ getState().editorCancelCaption = cancelCaption;
+ }
+
+ /**
+ * Gets the current caption of the cancel button in the Grid editor.
+ *
+ * @return the current caption of the cancel button
+ */
+ public String getCancelCaption() {
+ return getState(false).editorCancelCaption;
+ }
+
@Override
public void addItemClickListener(ItemClickListener listener) {
addListener(GridConstants.ITEM_CLICK_EVENT_ID, ItemClickEvent.class,
* Event ID for item click events
*/
public static final String ITEM_CLICK_EVENT_ID = "itemClick";
+
+ /** The default save button caption in the editor */
+ public static final String DEFAULT_SAVE_CAPTION = "Save";
+
+ /** The default cancel button caption in the editor */
+ public static final String DEFAULT_CANCEL_CAPTION = "Cancel";
}
/** Whether row data might contain generated cell styles */
public boolean hasCellStyleGenerator;
+ /** The caption for the save button in the editor */
+ @DelegateToWidget
+ public String editorSaveCaption = GridConstants.DEFAULT_SAVE_CAPTION;
+
+ /** The caption for the cancel button in the editor */
+ @DelegateToWidget
+ public String editorCancelCaption = GridConstants.DEFAULT_CANCEL_CAPTION;
}
c.cancelEditor();
}
}, null);
+
+ createClickAction("Change save caption", "Editor",
+ new Command<Grid, String>() {
+ @Override
+ public void execute(Grid c, String value, Object data) {
+ c.setEditorSaveCaption("ǝʌɐS");
+ }
+ }, null);
+
+ createClickAction("Change cancel caption", "Editor",
+ new Command<Grid, String>() {
+ @Override
+ public void execute(Grid c, String value, Object data) {
+ c.setEditorCancelCaption("ʃǝɔuɐↃ");
+ }
+ }, null);
}
@SuppressWarnings("boxing")
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
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.shared.ui.grid.GridConstants;
import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest;
import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures;
public class GridEditorClientTest extends GridBasicClientFeaturesTest {
+ private static final String[] EDIT_ROW_100 = new String[] { "Component",
+ "Editor", "Edit row 100" };
+ private static final String[] EDIT_ROW_5 = new String[] { "Component",
+ "Editor", "Edit row 5" };
+
@Before
public void setUp() {
openTestURL();
@Test
public void testProgrammaticOpeningClosing() {
- selectMenuPath("Component", "Editor", "Edit row 5");
+ selectMenuPath(EDIT_ROW_5);
assertNotNull(getEditor());
selectMenuPath("Component", "Editor", "Cancel edit");
@Test
public void testProgrammaticOpeningWithScroll() {
- selectMenuPath("Component", "Editor", "Edit row 100");
+ selectMenuPath(EDIT_ROW_100);
assertNotNull(getEditor());
}
@Test(expected = NoSuchElementException.class)
public void testVerticalScrollLocking() {
- selectMenuPath("Component", "Editor", "Edit row 5");
+ selectMenuPath(EDIT_ROW_5);
getGridElement().getCell(200, 0);
}
@Test
public void testWidgetBinding() throws Exception {
- selectMenuPath("Component", "Editor", "Edit row 100");
+ selectMenuPath(EDIT_ROW_100);
WebElement editor = getEditor();
List<WebElement> widgets = editor.findElements(By
@Test
public void testWithSelectionColumn() throws Exception {
selectMenuPath("Component", "State", "Selection mode", "multi");
- selectMenuPath("Component", "State", "Editor", "Edit row 5");
+ selectMenuPath(EDIT_ROW_5);
WebElement editor = getEditor();
List<WebElement> selectorDivs = editor.findElements(By
@Test
public void testSave() {
- selectMenuPath("Component", "Editor", "Edit row 100");
+ selectMenuPath(EDIT_ROW_100);
WebElement textField = getEditor().findElements(
By.className("gwt-TextBox")).get(0);
@Test
public void testProgrammaticSave() {
- selectMenuPath("Component", "Editor", "Edit row 100");
+ selectMenuPath(EDIT_ROW_100);
WebElement textField = getEditor().findElements(
By.className("gwt-TextBox")).get(0);
assertEquals("Changed", getGridElement().getCell(100, 0).getText());
}
+
+ @Test
+ public void testCaptionChange() {
+ selectMenuPath(EDIT_ROW_5);
+ assertEquals("Save button caption should've been \""
+ + GridConstants.DEFAULT_SAVE_CAPTION + "\" to begin with",
+ GridConstants.DEFAULT_SAVE_CAPTION, getSaveButton().getText());
+ assertEquals("Cancel button caption should've been \""
+ + GridConstants.DEFAULT_CANCEL_CAPTION + "\" to begin with",
+ GridConstants.DEFAULT_CANCEL_CAPTION, getCancelButton()
+ .getText());
+
+ selectMenuPath("Component", "Editor", "Change Save Caption");
+ assertNotEquals(
+ "Save button caption should've changed while editor is open",
+ GridConstants.DEFAULT_SAVE_CAPTION, getSaveButton().getText());
+
+ getCancelButton().click();
+
+ selectMenuPath("Component", "Editor", "Change Cancel Caption");
+ selectMenuPath(EDIT_ROW_5);
+ assertNotEquals(
+ "Cancel button caption should've changed while editor is closed",
+ GridConstants.DEFAULT_CANCEL_CAPTION, getCancelButton()
+ .getText());
+ }
+
+ protected WebElement getSaveButton() {
+ return getEditor().findElement(By.className("v-grid-editor-save"));
+ }
+
+ protected WebElement getCancelButton() {
+ return getEditor().findElement(By.className("v-grid-editor-cancel"));
+ }
+
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
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.shared.ui.grid.GridConstants;
import com.vaadin.testbench.elements.GridElement.GridCellElement;
import com.vaadin.testbench.elements.GridElement.GridEditorElement;
import com.vaadin.testbench.elements.NotificationElement;
.getText());
}
+ @Test
+ public void testCaptionChange() {
+ selectMenuPath(EDIT_ITEM_5);
+ assertEquals("Save button caption should've been \""
+ + GridConstants.DEFAULT_SAVE_CAPTION + "\" to begin with",
+ GridConstants.DEFAULT_SAVE_CAPTION, getSaveButton().getText());
+ assertEquals("Cancel button caption should've been \""
+ + GridConstants.DEFAULT_CANCEL_CAPTION + "\" to begin with",
+ GridConstants.DEFAULT_CANCEL_CAPTION, getCancelButton()
+ .getText());
+
+ selectMenuPath("Component", "Editor", "Change save caption");
+ assertNotEquals(
+ "Save button caption should've changed while editor is open",
+ GridConstants.DEFAULT_SAVE_CAPTION, getSaveButton().getText());
+
+ getCancelButton().click();
+
+ selectMenuPath("Component", "Editor", "Change cancel caption");
+ selectMenuPath(EDIT_ITEM_5);
+ assertNotEquals(
+ "Cancel button caption should've changed while editor is closed",
+ GridConstants.DEFAULT_CANCEL_CAPTION, getCancelButton()
+ .getText());
+ }
+
private void assertEditorOpen() {
assertNotNull("Editor is supposed to be open", getEditor());
assertEquals("Unexpected number of widgets", GridBasicFeatures.COLUMNS,
assertEquals("Grid shouldn't scroll vertically while editing",
originalScrollPos, getGridVerticalScrollPos());
}
+
+ private WebElement getSaveButton() {
+ return getDriver().findElement(By.className("v-grid-editor-save"));
+ }
+
+ private WebElement getCancelButton() {
+ return getDriver().findElement(By.className("v-grid-editor-cancel"));
+ }
}
}
}, "Component", "Editor");
+ addMenuCommand("Change Save Caption", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.setEditorSaveCaption("ǝʌɐS");
+ }
+ }, "Component", "Editor");
+
+ addMenuCommand("Change Cancel Caption", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.setEditorCancelCaption("ʃǝɔuɐↃ");
+ }
+ }, "Component", "Editor");
+
}
private void configureFooterRow(final FooterRow row) {