public static final String CLASSNAME = "v-button";
private static final String CLASSNAME_PRESSED = "v-pressed";
+ public static final String ATTR_DISABLE_ON_CLICK = "dc";
+
// mouse movement is checked before synthesizing click event on mouseout
protected static int MOVE_THRESHOLD = 3;
protected int mousedownX = 0;
private int tabIndex = 0;
+ private boolean disableOnClick = false;
+
/*
* BELOW PRIVATE MEMBERS COPY-PASTED FROM GWT CustomButton
*/
// Set text
setText(uidl.getStringAttribute("caption"));
+ disableOnClick = uidl.hasAttribute(ATTR_DISABLE_ON_CLICK);
+
// handle error
if (uidl.hasAttribute("error")) {
if (errorIndicatorElement == null) {
if (BrowserInfo.get().isSafari()) {
VButton.this.setFocus(true);
}
+ if (disableOnClick) {
+ setEnabled(false);
+ client.updateVariable(id, "disabledOnClick", true, false);
+ }
+
client.updateVariable(id, "state", true, false);
// Add mouse details
private HandlerRegistration focusHandlerRegistration;
private HandlerRegistration blurHandlerRegistration;
+ private boolean disableOnClick = false;
+
public VNativeButton() {
setStyleName(CLASSNAME);
return;
}
+ disableOnClick = uidl.hasAttribute(VButton.ATTR_DISABLE_ON_CLICK);
+
focusHandlerRegistration = EventHelper.updateFocusHandler(this, client,
focusHandlerRegistration);
blurHandlerRegistration = EventHelper.updateBlurHandler(this, client,
if (BrowserInfo.get().isSafari()) {
VNativeButton.this.setFocus(true);
}
+ if (disableOnClick) {
+ setEnabled(false);
+ client.updateVariable(id, "disabledOnClick", true, false);
+ }
// Add mouse details
MouseEventDetails details = new MouseEventDetails(
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.
}
target.addVariable(this, "state", booleanValue());
+ if (isDisableOnClick()) {
+ target.addAttribute(VButton.ATTR_DISABLE_ON_CLICK, true);
+ }
if (clickShortcut != null) {
target.addAttribute("keycode", clickShortcut.getKeyCode());
}
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");
}
}
+ /**
+ * 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();
+ }
+
}
super.setSwitchMode(true);
}
+ @Override
+ public void setDisableOnClick(boolean disableOnClick) {
+ throw new UnsupportedOperationException(
+ "CheckBox does not support disable on click");
+ }
+
}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="http://localhost:8888/" />
+<title>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.components.button.Buttons2?restartApplication</td>
+ <td></td>
+</tr>
+<!--value change listener-->
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::PID_Smenu#item0</td>
+ <td>37,10</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::Root/VOverlay[0]/VMenuBar[0]#item3</td>
+ <td>28,7</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::Root/VOverlay[1]/VMenuBar[0]#item4</td>
+ <td>35,8</td>
+</tr>
+<!--disable on click-->
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::PID_Smenu#item0</td>
+ <td>39,10</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::Root/VOverlay[0]/VMenuBar[0]#item4</td>
+ <td>33,7</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::Root/VOverlay[1]/VMenuBar[0]#item1</td>
+ <td>22,4</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::PID_SLog_row_0</td>
+ <td>1. Command: /Disable on click(true)</td>
+</tr>
+<!--click button-->
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::PID_StestComponent/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertCSSClass</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::PID_StestComponent</td>
+ <td>v-disabled</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::PID_SLog_row_0</td>
+ <td>2. ClickEvent</td>
+</tr>
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::PID_StestComponent/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::PID_SLog_row_0</td>
+ <td>2. ClickEvent</td>
+</tr>
+<!--re-enable-->
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::PID_Smenu#item0</td>
+ <td>35,13</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::Root/VOverlay[0]/VMenuBar[0]#item0</td>
+ <td>34,12</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::Root/VOverlay[1]/VMenuBar[0]#item1</td>
+ <td>15,13</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::PID_Smenu#item0</td>
+ <td>43,4</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::Root/VOverlay[0]/VMenuBar[0]#item0</td>
+ <td>37,8</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::Root/VOverlay[1]/VMenuBar[0]#item1</td>
+ <td>33,6</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::PID_SLog_row_0</td>
+ <td>4. Command: /Enabled(true)</td>
+</tr>
+<tr>
+ <td>assertNotCSSClass</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::PID_StestComponent</td>
+ <td>v-disabled</td>
+</tr>
+<!--no longer disable on click-->
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::PID_Smenu#item0</td>
+ <td>25,9</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::Root/VOverlay[0]/VMenuBar[0]#item4</td>
+ <td>39,13</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::Root/VOverlay[1]/VMenuBar[0]#item1</td>
+ <td>36,3</td>
+</tr>
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::PID_StestComponent/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::PID_SLog_row_0</td>
+ <td>6. ClickEvent</td>
+</tr>
+<tr>
+ <td>assertNotCSSClass</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtons2::PID_StestComponent</td>
+ <td>v-disabled</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
}\r
};\r
\r
+ private Command<T, Boolean> disableOnClickCommand = new Command<T, Boolean>() {\r
+\r
+ public void execute(T c, Boolean value, Object data) {\r
+ c.setDisableOnClick(value);\r
+ }\r
+ };\r
+\r
private Command<T, Boolean> clickListenerCommand = new Command<T, Boolean>() {\r
\r
public void execute(T c, Boolean value, Object data) {\r
\r
createBooleanAction("Switch mode", CATEGORY_FEATURES, false,\r
switchModeCommand);\r
+ createBooleanAction("Disable on click", CATEGORY_FEATURES, false,\r
+ disableOnClickCommand);\r
addClickListener(CATEGORY_LISTENERS);\r
}\r
\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="http://localhost:8888/" />
+<title>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.components.nativebutton.NativeButtonTest?restartApplication</td>
+ <td></td>
+</tr>
+<!--value change listener-->
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::PID_Smenu#item0</td>
+ <td>37,10</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::Root/VOverlay[0]/VMenuBar[0]#item3</td>
+ <td>28,7</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::Root/VOverlay[1]/VMenuBar[0]#item4</td>
+ <td>35,8</td>
+</tr>
+<!--disable on click-->
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::PID_Smenu#item0</td>
+ <td>39,10</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::Root/VOverlay[0]/VMenuBar[0]#item4</td>
+ <td>33,7</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::Root/VOverlay[1]/VMenuBar[0]#item1</td>
+ <td>22,4</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::PID_SLog_row_0</td>
+ <td>1. Command: /Disable on click(true)</td>
+</tr>
+<!--click button-->
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::PID_StestComponent</td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertCSSClass</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::PID_StestComponent</td>
+ <td>v-disabled</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::PID_SLog_row_0</td>
+ <td>2. ClickEvent</td>
+</tr>
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::PID_StestComponent</td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::PID_SLog_row_0</td>
+ <td>2. ClickEvent</td>
+</tr>
+<!--re-enable-->
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::PID_Smenu#item0</td>
+ <td>35,13</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::Root/VOverlay[0]/VMenuBar[0]#item0</td>
+ <td>34,12</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::Root/VOverlay[1]/VMenuBar[0]#item1</td>
+ <td>15,13</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::PID_Smenu#item0</td>
+ <td>43,4</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::Root/VOverlay[0]/VMenuBar[0]#item0</td>
+ <td>37,8</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::Root/VOverlay[1]/VMenuBar[0]#item1</td>
+ <td>33,6</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::PID_SLog_row_0</td>
+ <td>4. Command: /Enabled(true)</td>
+</tr>
+<tr>
+ <td>assertNotCSSClass</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::PID_StestComponent</td>
+ <td>v-disabled</td>
+</tr>
+<!--no longer disable on click-->
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::PID_Smenu#item0</td>
+ <td>25,9</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::Root/VOverlay[0]/VMenuBar[0]#item4</td>
+ <td>39,13</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::Root/VOverlay[1]/VMenuBar[0]#item1</td>
+ <td>36,3</td>
+</tr>
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::PID_StestComponent</td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::PID_SLog_row_0</td>
+ <td>6. ClickEvent</td>
+</tr>
+<tr>
+ <td>assertNotCSSClass</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonTest::PID_StestComponent</td>
+ <td>v-disabled</td>
+</tr>
+</tbody></table>
+</body>
+</html>