From: Mikael Grankvist Date: Thu, 15 Nov 2012 09:21:14 +0000 (+0200) Subject: Added possibility to disable text input for PopupDateField (#6790) X-Git-Tag: 7.0.0.beta10~85^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fchanges%2F72%2F272%2F2;p=vaadin-framework.git Added possibility to disable text input for PopupDateField (#6790) Change-Id: I3275fce74c26b1409aa00505c06f459d1ae2e6ce --- 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; @@ -131,6 +132,12 @@ public class PopupDateFieldConnector extends TextualDateConnector { return (PopupDateFieldState) super.getState(); } + @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; /** *

@@ -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 true if the text field is enabled, false 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 + * true to enable text field, false 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 @@ + + + + + + +PopupDateFieldTest + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PopupDateFieldTest
open/run/com.vaadin.tests.components.datefield.PopupDateFieldTest?restartApplication
assertEditablevaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::/VVerticalLayout[0]/VVerticalLayout[0]/VPopupCalendar[0]#field
mouseClickvaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::/VVerticalLayout[0]/VVerticalLayout[0]/VMenuBar[0]#item029,9
mouseClickvaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::Root/VOverlay[0]/VMenuBar[0]#item426,9
mouseClickvaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::Root/VOverlay[1]/VMenuBar[0]#item684,9
assertNotEditablevaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::/VVerticalLayout[0]/VVerticalLayout[0]/VPopupCalendar[0]#field
mouseClickvaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::/VVerticalLayout[0]/VVerticalLayout[0]/VMenuBar[0]#item031,6
mouseClickvaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::Root/VOverlay[0]/VMenuBar[0]#item029,7
mouseClickvaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::Root/VOverlay[1]/VMenuBar[0]#item142,7
mouseClickvaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::/VVerticalLayout[0]/VVerticalLayout[0]/VMenuBar[0]#item045,7
mouseClickvaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::Root/VOverlay[0]/VMenuBar[0]#item043,7
mouseClickvaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::Root/VOverlay[1]/VMenuBar[0]#item139,6
assertNotEditablevaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::/VVerticalLayout[0]/VVerticalLayout[0]/VPopupCalendar[0]#field
mouseClickvaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::/VVerticalLayout[0]/VVerticalLayout[0]/VMenuBar[0]#item036,7
mouseClickvaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::Root/VOverlay[0]/VMenuBar[0]#item434,6
mouseClickvaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::Root/VOverlay[1]/VMenuBar[0]#item671,7
assertEditablevaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldTest::/VVerticalLayout[0]/VVerticalLayout[0]/VPopupCalendar[0]#field
+ + 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 { super.createActions(); createInputPromptSelectAction(CATEGORY_FEATURES); + createTextEnabledAction(CATEGORY_FEATURES); } private void createInputPromptSelectAction(String category) { @@ -36,4 +37,16 @@ public class PopupDateFieldTest extends DateFieldTest { }); } + private void createTextEnabledAction(String category) { + this.createBooleanAction("Text field enabled", category, true, + new Command() { + + @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