private boolean open = false;
+ private boolean textFieldEnabled = true;
+
public VPopupCalendar() {
super();
}
}
+ /**
+ * 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)
*
if (!parsable) {
setText(previousValue);
}
+
+ // superclass sets the text field independently when building date
+ text.setEnabled(isEnabled() && isTextFieldEnabled());
}
/**
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;
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);
import com.vaadin.data.Property;
import com.vaadin.server.PaintException;
import com.vaadin.server.PaintTarget;
+import com.vaadin.shared.ui.datefield.PopupDateFieldState;
/**
* <p>
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;
+ }
+
}
{
primaryStyleName = "v-datefield";
}
+
+ public boolean textFieldEnabled = true;
+
}
--- /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>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>
super.createActions();
createInputPromptSelectAction(CATEGORY_FEATURES);
+ createTextEnabledAction(CATEGORY_FEATURES);
}
private void createInputPromptSelectAction(String category) {
});
}
+ 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);
+ }
+
+ });
+ }
}
--- /dev/null
+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