diff options
author | Artur Signell <artur@vaadin.com> | 2012-11-20 13:12:43 +0000 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2012-11-20 13:12:43 +0000 |
commit | 40e7287b82df23e9105f51b7ca086e93fb8903c5 (patch) | |
tree | 6e1bdb4b0382844d4ec170fe65b96da8a04e7ba2 | |
parent | 9c04958fdda8f490fc91aef19819ef9965c36e2e (diff) | |
parent | fb771475c1b94d0dca3e1cb69f87cb8d80630aad (diff) | |
download | vaadin-framework-40e7287b82df23e9105f51b7ca086e93fb8903c5.tar.gz vaadin-framework-40e7287b82df23e9105f51b7ca086e93fb8903c5.zip |
Merge "Added possibility to disable text input for PopupDateField (#6790)"
7 files changed, 232 insertions, 0 deletions
diff --git a/client/src/com/vaadin/client/ui/VPopupCalendar.java b/client/src/com/vaadin/client/ui/VPopupCalendar.java index 941978d129..c5680e3662 100644 --- a/client/src/com/vaadin/client/ui/VPopupCalendar.java +++ b/client/src/com/vaadin/client/ui/VPopupCalendar.java @@ -66,6 +66,8 @@ public class VPopupCalendar extends VTextualDate implements Field, private boolean open = false; + private boolean textFieldEnabled = true; + public VPopupCalendar() { super(); @@ -156,6 +158,34 @@ public class VPopupCalendar extends VTextualDate implements Field, } } + /** + * Checks whether the text field is enabled. + * + * @see VPopupCalendar#setTextFieldEnabled(boolean) + * @return The current state of the text field. + */ + public boolean isTextFieldEnabled() { + return textFieldEnabled; + } + + /** + * Sets the state of the text field of this component. By default the text + * field is enabled. Disabling it causes only the button for date selection + * to be active, thus preventing the user from entering invalid dates. See + * {@link http://dev.vaadin.com/ticket/6790}. + * + * @param state + */ + public void setTextFieldEnabled(boolean textFieldEnabled) { + this.textFieldEnabled = textFieldEnabled; + text.setEnabled(textFieldEnabled); + if (textFieldEnabled) { + calendarToggle.setTabIndex(-1); + } else { + calendarToggle.setTabIndex(0); + } + } + /* * (non-Javadoc) * @@ -335,6 +365,9 @@ public class VPopupCalendar extends VTextualDate implements Field, if (!parsable) { setText(previousValue); } + + // superclass sets the text field independently when building date + text.setEnabled(isEnabled() && isTextFieldEnabled()); } /** diff --git a/client/src/com/vaadin/client/ui/datefield/PopupDateFieldConnector.java b/client/src/com/vaadin/client/ui/datefield/PopupDateFieldConnector.java index 3859a22046..1ff1e58e72 100644 --- a/client/src/com/vaadin/client/ui/datefield/PopupDateFieldConnector.java +++ b/client/src/com/vaadin/client/ui/datefield/PopupDateFieldConnector.java @@ -21,6 +21,7 @@ import java.util.Date; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.DateTimeService; import com.vaadin.client.UIDL; +import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.ui.VCalendarPanel.FocusChangeListener; import com.vaadin.client.ui.VCalendarPanel.TimeChangeListener; import com.vaadin.client.ui.VPopupCalendar; @@ -132,6 +133,12 @@ public class PopupDateFieldConnector extends TextualDateConnector { } @Override + public void onStateChanged(StateChangeEvent stateChangeEvent) { + super.onStateChanged(stateChangeEvent); + getWidget().setTextFieldEnabled(getState().textFieldEnabled); + } + + @Override protected void setWidgetStyleName(String styleName, boolean add) { super.setWidgetStyleName(styleName, add); diff --git a/server/src/com/vaadin/ui/PopupDateField.java b/server/src/com/vaadin/ui/PopupDateField.java index 39e0578301..8d26fa8e25 100644 --- a/server/src/com/vaadin/ui/PopupDateField.java +++ b/server/src/com/vaadin/ui/PopupDateField.java @@ -21,6 +21,7 @@ import java.util.Date; import com.vaadin.data.Property; import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; +import com.vaadin.shared.ui.datefield.PopupDateFieldState; /** * <p> @@ -87,4 +88,34 @@ public class PopupDateField extends DateField { markAsDirty(); } + @Override + protected PopupDateFieldState getState() { + return (PopupDateFieldState) super.getState(); + } + + /** + * Checks whether the text field is enabled (default) or not. + * + * @see PopupDateField#setTextFieldEnabled(boolean); + * + * @return <b>true</b> if the text field is enabled, <b>false</b> otherwise. + */ + public boolean isTextFieldEnabled() { + return getState().textFieldEnabled; + } + + /** + * Enables or disables the text field. By default the text field is enabled. + * Disabling it causes only the button for date selection to be active, thus + * preventing the user from entering invalid dates. + * + * See {@link http://dev.vaadin.com/ticket/6790}. + * + * @param state + * <b>true</b> to enable text field, <b>false</b> to disable it. + */ + public void setTextFieldEnabled(boolean state) { + getState().textFieldEnabled = state; + } + } diff --git a/shared/src/com/vaadin/shared/ui/datefield/PopupDateFieldState.java b/shared/src/com/vaadin/shared/ui/datefield/PopupDateFieldState.java index c0d3b20c28..deed182d8e 100644 --- a/shared/src/com/vaadin/shared/ui/datefield/PopupDateFieldState.java +++ b/shared/src/com/vaadin/shared/ui/datefield/PopupDateFieldState.java @@ -4,4 +4,7 @@ public class PopupDateFieldState extends TextualDateFieldState { { primaryStyleName = "v-datefield"; } + + public boolean textFieldEnabled = true; + } diff --git a/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldTest.html b/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldTest.html new file mode 100644 index 0000000000..eb9859bf9d --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldTest.html @@ -0,0 +1,102 @@ +<?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>PopupDateFieldTest</title> +</head> +<body> +<table cellpadding="1" cellspacing="1" border="1"> +<thead> +<tr><td rowspan="1" colspan="3">PopupDateFieldTest</td></tr> +</thead><tbody> +<tr> + <td>open</td> + <td>/run/com.vaadin.tests.components.datefield.PopupDateFieldTest?restartApplication</td> + <td></td> +</tr> +<tr> + <td>assertEditable</td> + <td>vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::/VVerticalLayout[0]/VVerticalLayout[0]/VPopupCalendar[0]#field</td> + <td></td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::/VVerticalLayout[0]/VVerticalLayout[0]/VMenuBar[0]#item0</td> + <td>29,9</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::Root/VOverlay[0]/VMenuBar[0]#item4</td> + <td>26,9</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::Root/VOverlay[1]/VMenuBar[0]#item6</td> + <td>84,9</td> +</tr> +<tr> + <td>assertNotEditable</td> + <td>vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::/VVerticalLayout[0]/VVerticalLayout[0]/VPopupCalendar[0]#field</td> + <td></td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::/VVerticalLayout[0]/VVerticalLayout[0]/VMenuBar[0]#item0</td> + <td>31,6</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::Root/VOverlay[0]/VMenuBar[0]#item0</td> + <td>29,7</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::Root/VOverlay[1]/VMenuBar[0]#item1</td> + <td>42,7</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::/VVerticalLayout[0]/VVerticalLayout[0]/VMenuBar[0]#item0</td> + <td>45,7</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::Root/VOverlay[0]/VMenuBar[0]#item0</td> + <td>43,7</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::Root/VOverlay[1]/VMenuBar[0]#item1</td> + <td>39,6</td> +</tr> +<tr> + <td>assertNotEditable</td> + <td>vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::/VVerticalLayout[0]/VVerticalLayout[0]/VPopupCalendar[0]#field</td> + <td></td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::/VVerticalLayout[0]/VVerticalLayout[0]/VMenuBar[0]#item0</td> + <td>36,7</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::Root/VOverlay[0]/VMenuBar[0]#item4</td> + <td>34,6</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::Root/VOverlay[1]/VMenuBar[0]#item6</td> + <td>71,7</td> +</tr> +<tr> + <td>assertEditable</td> + <td>vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::/VVerticalLayout[0]/VVerticalLayout[0]/VPopupCalendar[0]#field</td> + <td></td> +</tr> + +</tbody></table> +</body> +</html> diff --git a/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldTest.java b/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldTest.java index 3e8b0678a7..6e3250a825 100644 --- a/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldTest.java +++ b/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldTest.java @@ -16,6 +16,7 @@ public class PopupDateFieldTest extends DateFieldTest<PopupDateField> { super.createActions(); createInputPromptSelectAction(CATEGORY_FEATURES); + createTextEnabledAction(CATEGORY_FEATURES); } private void createInputPromptSelectAction(String category) { @@ -36,4 +37,16 @@ public class PopupDateFieldTest extends DateFieldTest<PopupDateField> { }); } + private void createTextEnabledAction(String category) { + this.createBooleanAction("Text field enabled", category, true, + new Command<PopupDateField, Boolean>() { + + @Override + public void execute(PopupDateField c, Boolean value, + Object data) { + c.setTextFieldEnabled(value); + } + + }); + } } diff --git a/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldTextEnabled.java b/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldTextEnabled.java new file mode 100644 index 0000000000..731869f668 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldTextEnabled.java @@ -0,0 +1,43 @@ +package com.vaadin.tests.components.datefield; + +import com.vaadin.data.Property; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.PopupDateField; + +public class PopupDateFieldTextEnabled extends TestBase { + + private static final String ENABLED = "DateField text box enabled"; + private static final String DISABLED = "DateField text box disabled"; + @Override + public void setup() { + final PopupDateField field = new PopupDateField(); + final CheckBox box = new CheckBox(ENABLED, true); + box.addListener(new Property.ValueChangeListener() { + + @Override + public void valueChange(Property.ValueChangeEvent event) { + field.setTextFieldEnabled((Boolean) event.getProperty() + .getValue()); + if(field.isTextFieldEnabled()){ + box.setCaption(ENABLED); + }else{ + box.setCaption(DISABLED); + } + } + }); + addComponent(box); + addComponent(field); + } + + @Override + protected String getDescription() { + return "tests whether or not enabling text field in the component works"; + } + + @Override + protected Integer getTicketNumber() { + return 6790; + } + +}
\ No newline at end of file |