diff options
author | Teppo Kurki <teppo.kurki@itmill.com> | 2009-01-15 11:33:59 +0000 |
---|---|---|
committer | Teppo Kurki <teppo.kurki@itmill.com> | 2009-01-15 11:33:59 +0000 |
commit | cf1765165bbb707bf1729046e96835e4360c3f5f (patch) | |
tree | e3c407d6ba91a5adb93ea77034d974bc594531bc /src/com/itmill/toolkit/demo/sampler/features/dates/DateResolutionExample.java | |
parent | a5ab8961e2d304f791f7d8a65e4ac5f698d78f6f (diff) | |
download | vaadin-framework-cf1765165bbb707bf1729046e96835e4360c3f5f.tar.gz vaadin-framework-cf1765165bbb707bf1729046e96835e4360c3f5f.zip |
Adding DateField examples for Sampler.
svn changeset:6549/svn branch:trunk
Diffstat (limited to 'src/com/itmill/toolkit/demo/sampler/features/dates/DateResolutionExample.java')
-rw-r--r-- | src/com/itmill/toolkit/demo/sampler/features/dates/DateResolutionExample.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/com/itmill/toolkit/demo/sampler/features/dates/DateResolutionExample.java b/src/com/itmill/toolkit/demo/sampler/features/dates/DateResolutionExample.java new file mode 100644 index 0000000000..54e53b2ac1 --- /dev/null +++ b/src/com/itmill/toolkit/demo/sampler/features/dates/DateResolutionExample.java @@ -0,0 +1,69 @@ +package com.itmill.toolkit.demo.sampler.features.dates;
+
+import com.itmill.toolkit.data.Item;
+import com.itmill.toolkit.data.Property;
+import com.itmill.toolkit.data.Property.ValueChangeEvent;
+import com.itmill.toolkit.data.util.IndexedContainer;
+import com.itmill.toolkit.ui.ComboBox;
+import com.itmill.toolkit.ui.InlineDateField;
+import com.itmill.toolkit.ui.VerticalLayout;
+
+public class DateResolutionExample extends VerticalLayout implements
+ Property.ValueChangeListener {
+
+ public static final Object resolution_PROPERTY_NAME = "name";
+ // Resolution fields from DateField
+ private static final int[] resolutions = { InlineDateField.RESOLUTION_YEAR,
+ InlineDateField.RESOLUTION_MONTH, InlineDateField.RESOLUTION_DAY,
+ InlineDateField.RESOLUTION_HOUR, InlineDateField.RESOLUTION_MIN,
+ InlineDateField.RESOLUTION_SEC, InlineDateField.RESOLUTION_MSEC };
+ private static final String[] resolutionNames = { "Year", "Month", "Day",
+ "Hour", "Minute", "Second", "Millisecond" };
+
+ private InlineDateField datetime;
+ private ComboBox localeSelection;
+
+ public DateResolutionExample() {
+ setSpacing(true);
+
+ datetime = new InlineDateField("Please select the starting time:");
+
+ // Set the value of the PopupDateField to current date
+ datetime.setValue(new java.util.Date());
+
+ // Set the correct resolution
+ datetime.setResolution(InlineDateField.RESOLUTION_DAY);
+ datetime.setImmediate(true);
+
+ // Create selection
+ localeSelection = new ComboBox("Select resolution:");
+ localeSelection.setNullSelectionAllowed(false);
+ localeSelection.addListener(this);
+ localeSelection.setImmediate(true);
+
+ // Fill the selection with choices, set captions correctly
+ localeSelection.setContainerDataSource(getResolutionContainer());
+ localeSelection.setItemCaptionPropertyId(resolution_PROPERTY_NAME);
+ localeSelection.setItemCaptionMode(ComboBox.ITEM_CAPTION_MODE_PROPERTY);
+
+ addComponent(datetime);
+ addComponent(localeSelection);
+ }
+
+ public void valueChange(ValueChangeEvent event) {
+ datetime.setResolution((Integer) event.getProperty().getValue());
+ datetime.requestRepaint();
+ }
+
+ private IndexedContainer getResolutionContainer() {
+ IndexedContainer resolutionContainer = new IndexedContainer();
+ resolutionContainer.addContainerProperty(resolution_PROPERTY_NAME,
+ String.class, null);
+ for (int i = 0; i < resolutions.length; i++) {
+ Item added = resolutionContainer.addItem(resolutions[i]);
+ added.getItemProperty(resolution_PROPERTY_NAME).setValue(
+ resolutionNames[i]);
+ }
+ return resolutionContainer;
+ }
+}
|