diff options
author | Henrik Paul <henrik@vaadin.com> | 2015-02-02 16:51:49 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-02-05 06:50:44 +0000 |
commit | 323e8bb4588fcb4eefa6e988cceb8444f963d733 (patch) | |
tree | 38d6251431c43fabe3ba4e4c3afdf3edbe939ac3 /client | |
parent | 2a67b961a466b512532b1f554b0fc2903d185f50 (diff) | |
download | vaadin-framework-323e8bb4588fcb4eefa6e988cceb8444f963d733.tar.gz vaadin-framework-323e8bb4588fcb4eefa6e988cceb8444f963d733.zip |
Makes it possible to change save/cancel captions in Grid editor (#16551)
Change-Id: I4e303613f66a13b3ad6a9b2284537e5548391a4a
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/widgets/Grid.java | 130 |
1 files changed, 107 insertions, 23 deletions
diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index e112d868b4..aee1c1fcc8 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -971,8 +971,8 @@ public class Grid<T> extends ResizeComposite implements 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() { @@ -1053,6 +1053,28 @@ public class Grid<T> extends ResizeComposite implements } }; + 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; } @@ -1295,28 +1317,7 @@ public class Grid<T> extends ResizeComposite implements } } - 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); /* @@ -1362,6 +1363,9 @@ public class Grid<T> extends ResizeComposite implements } columnToWidget.clear(); + detachWidget(saveButton); + detachWidget(cancelButton); + editorOverlay.removeAllChildren(); editorOverlay.removeFromParent(); @@ -1371,9 +1375,14 @@ public class Grid<T> extends ResizeComposite implements 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"); } /** @@ -1401,6 +1410,11 @@ public class Grid<T> extends ResizeComposite implements 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(); @@ -1431,6 +1445,32 @@ public class Grid<T> extends ResizeComposite implements 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> @@ -5825,6 +5865,50 @@ public class Grid<T> extends ResizeComposite implements 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(); |