aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatti Tahvonen <matti.tahvonen@itmill.com>2010-09-09 10:15:00 +0000
committerMatti Tahvonen <matti.tahvonen@itmill.com>2010-09-09 10:15:00 +0000
commitb864d221076b0babccddea3f1f98514d71b52fd5 (patch)
tree52805520c186f6a9053229a2a0a772d0e5e691f7
parentc694ce35ed14f282c32c53fe52eb30680a1ad57f (diff)
downloadvaadin-framework-b864d221076b0babccddea3f1f98514d71b52fd5.tar.gz
vaadin-framework-b864d221076b0babccddea3f1f98514d71b52fd5.zip
fixes #5567
svn changeset:14799/svn branch:6.4
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VCalendarPanel.java2
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VDateFieldCalendar.java24
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java12
-rw-r--r--tests/src/com/vaadin/tests/components/datefield/LowResolution.java78
4 files changed, 109 insertions, 7 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCalendarPanel.java b/src/com/vaadin/terminal/gwt/client/ui/VCalendarPanel.java
index fdcd6d65dd..16d27bb053 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VCalendarPanel.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VCalendarPanel.java
@@ -584,7 +584,7 @@ public class VCalendarPanel extends FocusableFlexTable implements
if (getResolution() <= VDateField.RESOLUTION_MONTH
&& valueChangeListener != null) {
- valueChangeListener.changed(focusedDate);
+ valueChangeListener.changed(new Date(focusedDate.getTime()));
}
Date start = new Date();
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VDateFieldCalendar.java b/src/com/vaadin/terminal/gwt/client/ui/VDateFieldCalendar.java
index 385257ccf6..d276ce23f9 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VDateFieldCalendar.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VDateFieldCalendar.java
@@ -13,6 +13,7 @@ import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.FocusOutListener;
import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.SubmitListener;
import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.TimeChangeListener;
+import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.ValueChangeListener;
public class VDateFieldCalendar extends VDateField {
@@ -69,10 +70,33 @@ public class VDateFieldCalendar extends VDateField {
});
}
+ if (currentResolution <= RESOLUTION_MONTH) {
+ caleandarPanel.setValueChangeListener(new ValueChangeListener() {
+ public void changed(Date date) {
+ Date date2 = new Date(caleandarPanel.getDate().getTime());
+ /*
+ * Update the value of calendarPanel
+ */
+ date2.setYear(date.getYear());
+ date2.setMonth(date.getMonth());
+ caleandarPanel.setDate(date2);
+ /*
+ * Then update the value from panel to server
+ */
+ updateValueFromPanel();
+ }
+ });
+ } else {
+ caleandarPanel.setValueChangeListener(null);
+ }
+
// Update possible changes
caleandarPanel.renderCalendar();
}
+ /**
+ * TODO refactor: almost same method as in VPopupCalendar.updateValue
+ */
private void updateValueFromPanel() {
Date date2 = caleandarPanel.getDate();
Date currentDate = getCurrentDate();
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java b/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java
index ba91df0888..ae7bea406e 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java
@@ -166,10 +166,15 @@ public class VPopupCalendar extends VTextualDate implements Paintable, Field,
if (currentResolution <= RESOLUTION_MONTH) {
calendar.setValueChangeListener(new ValueChangeListener() {
public void changed(Date date) {
- setCurrentDate(date);
+ updateValue(date);
buildDate();
+ Date date2 = calendar.getDate();
+ date2.setYear(date.getYear());
+ date2.setMonth(date.getMonth());
}
});
+ } else {
+ calendar.setValueChangeListener(null);
}
if (currentResolution > RESOLUTION_DAY) {
@@ -324,11 +329,6 @@ public class VPopupCalendar extends VTextualDate implements Paintable, Field,
*/
public void onClose(CloseEvent<PopupPanel> event) {
if (event.getSource() == popup) {
- if (getCurrentResolution() <= VDateField.RESOLUTION_MONTH) {
- // due to UI limitations always fetch date from popup if
- // resolution is month or year
- setDate(calendar.getDate());
- }
buildDate();
focus();
diff --git a/tests/src/com/vaadin/tests/components/datefield/LowResolution.java b/tests/src/com/vaadin/tests/components/datefield/LowResolution.java
new file mode 100644
index 0000000000..1c1994cbe5
--- /dev/null
+++ b/tests/src/com/vaadin/tests/components/datefield/LowResolution.java
@@ -0,0 +1,78 @@
+package com.vaadin.tests.components.datefield;
+
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.CheckBox;
+import com.vaadin.ui.InlineDateField;
+import com.vaadin.ui.PopupDateField;
+
+@SuppressWarnings("serial")
+public class LowResolution extends TestBase {
+
+ @Override
+ protected void setup() {
+ final PopupDateField dateField = new PopupDateField();
+ dateField.setValue(new java.util.Date());
+ dateField.setResolution(PopupDateField.RESOLUTION_MONTH);
+ dateField.addListener(new PopupDateField.ValueChangeListener() {
+ public void valueChange(ValueChangeEvent event) {
+ getMainWindow().showNotification(
+ "Date now" + event.getProperty());
+ }
+ });
+ dateField.setImmediate(true);
+ getLayout().addComponent(dateField);
+
+ final PopupDateField dateField3 = new PopupDateField();
+ // dateField.setValue(new java.util.Date());
+ dateField3.setResolution(PopupDateField.RESOLUTION_YEAR);
+ dateField3.addListener(new PopupDateField.ValueChangeListener() {
+ public void valueChange(ValueChangeEvent event) {
+ getMainWindow().showNotification(
+ "Date now" + event.getProperty());
+ }
+ });
+ dateField3.setImmediate(true);
+ getLayout().addComponent(dateField3);
+
+ final InlineDateField dateField2 = new InlineDateField();
+ dateField2.setValue(new java.util.Date());
+ dateField2.setResolution(PopupDateField.RESOLUTION_MONTH);
+ dateField2.addListener(new PopupDateField.ValueChangeListener() {
+ public void valueChange(ValueChangeEvent event) {
+ getMainWindow().showNotification(
+ "Date now" + event.getProperty());
+ }
+ });
+ dateField2.setImmediate(true);
+ getLayout().addComponent(dateField2);
+
+ CheckBox immediate = new CheckBox(
+ "Immediate (use sync button to change fields) ");
+ immediate.setValue(true);
+ immediate.addListener(new CheckBox.ValueChangeListener() {
+ public void valueChange(ValueChangeEvent event) {
+ boolean immediate = !dateField.isImmediate();
+ dateField.setImmediate(immediate);
+ dateField2.setImmediate(immediate);
+ dateField3.setImmediate(immediate);
+ }
+ });
+
+ getLayout().addComponent(immediate);
+ getLayout().addComponent(new Button("sync"));
+
+ }
+
+ @Override
+ protected String getDescription() {
+ return "Date field should work and update its value to the server.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 5567;
+ }
+
+}