summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/ui/Button.java
diff options
context:
space:
mode:
authorArtur Signell <artur.signell@itmill.com>2011-07-18 13:08:21 +0000
committerArtur Signell <artur.signell@itmill.com>2011-07-18 13:08:21 +0000
commit1bbad422177eac5a795e0b63cfbd788f9e99d864 (patch)
treec4078c1056d1aebcfbefccd14466e3782219b756 /src/com/vaadin/ui/Button.java
parent460a3ff128c817b256e234a8bdbc8b4aa3590b79 (diff)
downloadvaadin-framework-1bbad422177eac5a795e0b63cfbd788f9e99d864.tar.gz
vaadin-framework-1bbad422177eac5a795e0b63cfbd788f9e99d864.zip
#6444 Ability to disable button on click
svn changeset:19820/svn branch:6.7
Diffstat (limited to 'src/com/vaadin/ui/Button.java')
-rw-r--r--src/com/vaadin/ui/Button.java34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/com/vaadin/ui/Button.java b/src/com/vaadin/ui/Button.java
index 122d155e0f..16314f94c3 100644
--- a/src/com/vaadin/ui/Button.java
+++ b/src/com/vaadin/ui/Button.java
@@ -43,6 +43,8 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier,
boolean switchMode = false;
+ boolean disableOnClick = false;
+
/**
* Creates a new push button. The value of the push button is false and it
* is immediate by default.
@@ -148,6 +150,9 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier,
}
target.addVariable(this, "state", booleanValue());
+ if (isDisableOnClick()) {
+ target.addAttribute(VButton.ATTR_DISABLE_ON_CLICK, true);
+ }
if (clickShortcut != null) {
target.addAttribute("keycode", clickShortcut.getKeyCode());
}
@@ -164,6 +169,12 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier,
public void changeVariables(Object source, Map<String, Object> variables) {
super.changeVariables(source, variables);
+ if (variables.containsKey("disabledOnClick")) {
+ // Could be optimized so the button is not repainted because of this
+ // (client side has already disabled the button)
+ setEnabled(false);
+ }
+
if (!isReadOnly() && variables.containsKey("state")) {
// Gets the new and old button states
final Boolean newValue = (Boolean) variables.get("state");
@@ -651,4 +662,27 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier,
}
}
+ /**
+ * Determines if a button is automatically disabled when clicked. See
+ * {@link #setDisableOnClick(boolean)} for details.
+ *
+ * @return true if the button is disabled when clicked, false otherwise
+ */
+ public boolean isDisableOnClick() {
+ return disableOnClick;
+ }
+
+ /**
+ * Determines if a button is automatically disabled when clicked. If this is
+ * set to true the button will be automatically disabled when clicked,
+ * typically to prevent (accidental) extra clicks on a button.
+ *
+ * @param disableOnClick
+ * true to disable button when it is clicked, false otherwise
+ */
+ public void setDisableOnClick(boolean disableOnClick) {
+ this.disableOnClick = disableOnClick;
+ requestRepaint();
+ }
+
}