summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/com')
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java38
-rw-r--r--src/com/vaadin/ui/PopupDateField.java34
2 files changed, 71 insertions, 1 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java b/src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java
index 209c5cabde..92e3aad39b 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java
@@ -44,6 +44,11 @@ public class VTextualDate extends VDateField implements Paintable, Field,
private boolean lenient;
+ private static final String CLASSNAME_PROMPT = "prompt";
+ private static final String ATTR_INPUTPROMPT = "prompt";
+ private String inputPrompt = "";
+ private boolean prompting = false;
+
public VTextualDate() {
super();
@@ -57,6 +62,10 @@ public class VTextualDate extends VDateField implements Paintable, Field,
public void onFocus(FocusEvent event) {
text.addStyleName(VTextField.CLASSNAME + "-"
+ VTextField.CLASSNAME_FOCUS);
+ if (prompting) {
+ text.setText("");
+ setPrompting(false);
+ }
if (client != null
&& client.hasEventListeners(VTextualDate.this,
EventId.FOCUS)) {
@@ -68,6 +77,12 @@ public class VTextualDate extends VDateField implements Paintable, Field,
public void onBlur(BlurEvent event) {
text.removeStyleName(VTextField.CLASSNAME + "-"
+ VTextField.CLASSNAME_FOCUS);
+ String value = getText();
+ setPrompting(inputPrompt != null
+ && (value == null || "".equals(value)));
+ if (prompting) {
+ text.setText(readonly ? "" : inputPrompt);
+ }
if (client != null
&& client.hasEventListeners(VTextualDate.this,
EventId.BLUR)) {
@@ -91,6 +106,8 @@ public class VTextualDate extends VDateField implements Paintable, Field,
formatStr = uidl.getStringAttribute("format");
}
+ inputPrompt = uidl.getStringAttribute(ATTR_INPUTPROMPT);
+
lenient = !uidl.getBooleanAttribute("strict");
buildDate();
@@ -163,7 +180,7 @@ public class VTextualDate extends VDateField implements Paintable, Field,
dateText = "";
}
- text.setText(dateText);
+ setText(dateText);
text.setEnabled(enabled);
text.setReadOnly(readonly);
@@ -175,6 +192,15 @@ public class VTextualDate extends VDateField implements Paintable, Field,
}
+ protected void setPrompting(boolean prompting) {
+ this.prompting = prompting;
+ if (prompting) {
+ addStyleDependentName(CLASSNAME_PROMPT);
+ } else {
+ removeStyleDependentName(CLASSNAME_PROMPT);
+ }
+ }
+
public void onChange(ChangeEvent event) {
if (!text.getText().equals("")) {
try {
@@ -357,10 +383,20 @@ public class VTextualDate extends VDateField implements Paintable, Field,
}
protected String getText() {
+ if (prompting) {
+ return "";
+ }
return text.getText();
}
protected void setText(String text) {
+ if (inputPrompt != null && (text == null || "".equals(text))) {
+ text = readonly ? "" : inputPrompt;
+ setPrompting(true);
+ } else {
+ setPrompting(false);
+ }
+
this.text.setText(text);
}
diff --git a/src/com/vaadin/ui/PopupDateField.java b/src/com/vaadin/ui/PopupDateField.java
index 5164601f0d..e975cb23d2 100644
--- a/src/com/vaadin/ui/PopupDateField.java
+++ b/src/com/vaadin/ui/PopupDateField.java
@@ -7,6 +7,8 @@ package com.vaadin.ui;
import java.util.Date;
import com.vaadin.data.Property;
+import com.vaadin.terminal.PaintException;
+import com.vaadin.terminal.PaintTarget;
/**
* <p>
@@ -24,6 +26,8 @@ import com.vaadin.data.Property;
@SuppressWarnings("serial")
public class PopupDateField extends DateField {
+ private String inputPrompt = null;
+
public PopupDateField() {
super();
type = TYPE_POPUP;
@@ -49,4 +53,34 @@ public class PopupDateField extends DateField {
type = TYPE_POPUP;
}
+ @Override
+ public void paintContent(PaintTarget target) throws PaintException {
+ super.paintContent(target);
+
+ if (inputPrompt != null) {
+ target.addAttribute("prompt", inputPrompt);
+ }
+ }
+
+ /**
+ * Gets the current input prompt.
+ *
+ * @see #setInputPrompt(String)
+ * @return the current input prompt, or null if not enabled
+ */
+ public String getInputPrompt() {
+ return inputPrompt;
+ }
+
+ /**
+ * Sets the input prompt - a textual prompt that is displayed when the field
+ * would otherwise be empty, to prompt the user for input.
+ *
+ * @param inputPrompt
+ */
+ public void setInputPrompt(String inputPrompt) {
+ this.inputPrompt = inputPrompt;
+ requestRepaint();
+ }
+
}