You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PopupDateField.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.ui;
  17. import java.util.Date;
  18. import com.vaadin.data.Property;
  19. import com.vaadin.server.PaintException;
  20. import com.vaadin.server.PaintTarget;
  21. import com.vaadin.shared.ui.datefield.PopupDateFieldState;
  22. /**
  23. * <p>
  24. * A date entry component, which displays the actual date selector as a popup.
  25. *
  26. * </p>
  27. *
  28. * @see DateField
  29. * @see InlineDateField
  30. * @author Vaadin Ltd.
  31. * @since 5.0
  32. */
  33. public class PopupDateField extends DateField {
  34. private String inputPrompt = null;
  35. public PopupDateField() {
  36. super();
  37. }
  38. public PopupDateField(Property dataSource) throws IllegalArgumentException {
  39. super(dataSource);
  40. }
  41. public PopupDateField(String caption, Date value) {
  42. super(caption, value);
  43. }
  44. public PopupDateField(String caption, Property dataSource) {
  45. super(caption, dataSource);
  46. }
  47. public PopupDateField(String caption) {
  48. super(caption);
  49. }
  50. @Override
  51. public void paintContent(PaintTarget target) throws PaintException {
  52. super.paintContent(target);
  53. if (inputPrompt != null) {
  54. target.addAttribute("prompt", inputPrompt);
  55. }
  56. }
  57. /**
  58. * Gets the current input prompt.
  59. *
  60. * @see #setInputPrompt(String)
  61. * @return the current input prompt, or null if not enabled
  62. */
  63. public String getInputPrompt() {
  64. return inputPrompt;
  65. }
  66. /**
  67. * Sets the input prompt - a textual prompt that is displayed when the field
  68. * would otherwise be empty, to prompt the user for input.
  69. *
  70. * @param inputPrompt
  71. */
  72. public void setInputPrompt(String inputPrompt) {
  73. this.inputPrompt = inputPrompt;
  74. markAsDirty();
  75. }
  76. @Override
  77. protected PopupDateFieldState getState() {
  78. return (PopupDateFieldState) super.getState();
  79. }
  80. @Override
  81. protected PopupDateFieldState getState(boolean markAsDirty) {
  82. return (PopupDateFieldState) super.getState(markAsDirty);
  83. }
  84. /**
  85. * Checks whether the text field is enabled (default) or not.
  86. *
  87. * @see PopupDateField#setTextFieldEnabled(boolean);
  88. *
  89. * @return <b>true</b> if the text field is enabled, <b>false</b> otherwise.
  90. */
  91. public boolean isTextFieldEnabled() {
  92. return getState(false).textFieldEnabled;
  93. }
  94. /**
  95. * Enables or disables the text field. By default the text field is enabled.
  96. * Disabling it causes only the button for date selection to be active, thus
  97. * preventing the user from entering invalid dates.
  98. *
  99. * See {@link http://dev.vaadin.com/ticket/6790}.
  100. *
  101. * @param state
  102. * <b>true</b> to enable text field, <b>false</b> to disable it.
  103. */
  104. public void setTextFieldEnabled(boolean state) {
  105. getState().textFieldEnabled = state;
  106. }
  107. /**
  108. * Set a description that explains the usage of the Widget for users of
  109. * assistive devices.
  110. *
  111. * @param description
  112. * String with the description
  113. */
  114. public void setAssistiveText(String description) {
  115. getState().descriptionForAssistiveDevices = description;
  116. }
  117. /**
  118. * Get the description that explains the usage of the Widget for users of
  119. * assistive devices.
  120. *
  121. * @return String with the description
  122. */
  123. public String getAssistiveText() {
  124. return getState(false).descriptionForAssistiveDevices;
  125. }
  126. }