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 | |
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')
14 files changed, 414 insertions, 0 deletions
diff --git a/src/com/itmill/toolkit/demo/sampler/ExampleUtil.java b/src/com/itmill/toolkit/demo/sampler/ExampleUtil.java index 36bbb09a12..e612e91a2e 100644 --- a/src/com/itmill/toolkit/demo/sampler/ExampleUtil.java +++ b/src/com/itmill/toolkit/demo/sampler/ExampleUtil.java @@ -1,5 +1,7 @@ package com.itmill.toolkit.demo.sampler; +import java.util.Locale; + import com.itmill.toolkit.data.Container; import com.itmill.toolkit.data.Item; import com.itmill.toolkit.data.util.HierarchicalContainer; @@ -117,6 +119,26 @@ public final class ExampleUtil { } } + public static final Object locale_PROPERTY_LOCALE = "locale"; + public static final Object locale_PROPERTY_NAME = "name"; + private static final String[][] locales = { { "fi", "FI", "Finnish" }, + { "de", "DE", "German" }, { "en", "US", "US - English" }, + { "sv", "SE", "Swedish" } }; + private static final IndexedContainer localeContainer = new IndexedContainer(); + static { + localeContainer.addContainerProperty(locale_PROPERTY_LOCALE, + Locale.class, null); + localeContainer.addContainerProperty(locale_PROPERTY_NAME, + String.class, null); + for (int i = 0; i < locales.length; i++) { + String id = locales[i][2]; + Item item = localeContainer.addItem(id); + item.getItemProperty(locale_PROPERTY_LOCALE).setValue( + new Locale(locales[i][0], locales[i][1])); + item.getItemProperty(locale_PROPERTY_NAME).setValue(locales[i][2]); + } + } + private static final String[][] hardware = { // { "Desktops", "Dell OptiPlex GX240", "Dell OptiPlex GX260", "Dell OptiPlex GX280" }, @@ -124,6 +146,10 @@ public final class ExampleUtil { { "Laptops", "IBM ThinkPad T40", "IBM ThinkPad T43", "IBM ThinkPad T60" } }; + public static IndexedContainer getLocaleContainer() { + return localeContainer; + } + public static IndexedContainer getISO3166Container() { return iso3166Container; } diff --git a/src/com/itmill/toolkit/demo/sampler/FeatureSet.java b/src/com/itmill/toolkit/demo/sampler/FeatureSet.java index 7746eccb77..619940cff4 100644 --- a/src/com/itmill/toolkit/demo/sampler/FeatureSet.java +++ b/src/com/itmill/toolkit/demo/sampler/FeatureSet.java @@ -16,6 +16,10 @@ import com.itmill.toolkit.demo.sampler.features.commons.Errors; import com.itmill.toolkit.demo.sampler.features.commons.Icons; import com.itmill.toolkit.demo.sampler.features.commons.Tooltips; import com.itmill.toolkit.demo.sampler.features.commons.Validation; +import com.itmill.toolkit.demo.sampler.features.dates.DateInline; +import com.itmill.toolkit.demo.sampler.features.dates.DateLocale; +import com.itmill.toolkit.demo.sampler.features.dates.DatePopup; +import com.itmill.toolkit.demo.sampler.features.dates.DateResolution; import com.itmill.toolkit.demo.sampler.features.form.FormBasic; import com.itmill.toolkit.demo.sampler.features.layouts.HorizontalLayoutBasic; import com.itmill.toolkit.demo.sampler.features.layouts.LayoutAlignment; @@ -119,6 +123,7 @@ public class FeatureSet extends Feature { new Tables(),// new Texts(), // new Trees(), // + new Dates(), // }); } } @@ -302,6 +307,18 @@ public class FeatureSet extends Feature { } } + public static class Dates extends FeatureSet { + public Dates() { + super("Dates", new Feature[] { + // + new DatePopup(), // + new DateInline(), // + new DateLocale(), // + new DateResolution(), // + }); + } + } + // ---------------------------------------------------------- /* * FeatureSet implementation follows. diff --git a/src/com/itmill/toolkit/demo/sampler/features/dates/DateInline.java b/src/com/itmill/toolkit/demo/sampler/features/dates/DateInline.java new file mode 100644 index 0000000000..6b2b41216c --- /dev/null +++ b/src/com/itmill/toolkit/demo/sampler/features/dates/DateInline.java @@ -0,0 +1,43 @@ +package com.itmill.toolkit.demo.sampler.features.dates;
+
+import com.itmill.toolkit.demo.sampler.APIResource;
+import com.itmill.toolkit.demo.sampler.Feature;
+import com.itmill.toolkit.demo.sampler.NamedExternalResource;
+import com.itmill.toolkit.ui.DateField;
+import com.itmill.toolkit.ui.InlineDateField;
+
+public class DateInline extends Feature {
+ @Override
+ public String getName() {
+ return "Date selection inline";
+ }
+
+ @Override
+ public String getDescription() {
+ return "The DateField component can be used to produce various"
+ + " date and time input fields with different resolutions."
+ + " The date and time format used with this component is"
+ + " reported to the Toolkit by the browser."
+ + "<br>In this example, the resolution is set to be one day"
+ + " and the DateField component is shown as an inline calendar"
+ + " component.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(DateField.class),
+ new APIResource(InlineDateField.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { DatePopup.class, DateLocale.class,
+ DateResolution.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
diff --git a/src/com/itmill/toolkit/demo/sampler/features/dates/DateInline.png b/src/com/itmill/toolkit/demo/sampler/features/dates/DateInline.png Binary files differnew file mode 100644 index 0000000000..852a12df04 --- /dev/null +++ b/src/com/itmill/toolkit/demo/sampler/features/dates/DateInline.png diff --git a/src/com/itmill/toolkit/demo/sampler/features/dates/DateInlineExample.java b/src/com/itmill/toolkit/demo/sampler/features/dates/DateInlineExample.java new file mode 100644 index 0000000000..7b12738142 --- /dev/null +++ b/src/com/itmill/toolkit/demo/sampler/features/dates/DateInlineExample.java @@ -0,0 +1,40 @@ +package com.itmill.toolkit.demo.sampler.features.dates;
+
+import java.text.DateFormat;
+
+import com.itmill.toolkit.data.Property;
+import com.itmill.toolkit.data.Property.ValueChangeEvent;
+import com.itmill.toolkit.ui.InlineDateField;
+import com.itmill.toolkit.ui.VerticalLayout;
+
+public class DateInlineExample extends VerticalLayout implements
+ Property.ValueChangeListener {
+
+ private InlineDateField datetime;
+
+ public DateInlineExample() {
+ 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);
+
+ // Add valuechangelistener
+ datetime.addListener(this);
+ datetime.setImmediate(true);
+
+ addComponent(datetime);
+ }
+
+ public void valueChange(ValueChangeEvent event) {
+ // Get the new value and format it to the current locale
+ DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.SHORT);
+ String dateOut = dateFormatter.format(event.getProperty().getValue());
+ // Show notification
+ getWindow().showNotification("Starting date: " + dateOut);
+ }
+}
diff --git a/src/com/itmill/toolkit/demo/sampler/features/dates/DateLocale.java b/src/com/itmill/toolkit/demo/sampler/features/dates/DateLocale.java new file mode 100644 index 0000000000..1f50d78611 --- /dev/null +++ b/src/com/itmill/toolkit/demo/sampler/features/dates/DateLocale.java @@ -0,0 +1,46 @@ +package com.itmill.toolkit.demo.sampler.features.dates;
+
+import java.util.Locale;
+
+import com.itmill.toolkit.demo.sampler.APIResource;
+import com.itmill.toolkit.demo.sampler.Feature;
+import com.itmill.toolkit.demo.sampler.NamedExternalResource;
+import com.itmill.toolkit.ui.DateField;
+import com.itmill.toolkit.ui.InlineDateField;
+
+public class DateLocale extends Feature {
+ @Override
+ public String getName() {
+ return "Date selection - Locale";
+ }
+
+ @Override
+ public String getDescription() {
+ return "The DateField component can be used to produce various"
+ + " date and time input fields with different resolutions."
+ + " The date and time format used with this component is"
+ + " reported to the Toolkit by the browser."
+ + "<br>In this example, you can select a different locale"
+ + " from the combo box and see how the calendar component"
+ + " will be localized.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(DateField.class),
+ new APIResource(InlineDateField.class),
+ new APIResource(Locale.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { DateInline.class, DatePopup.class,
+ DateResolution.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
diff --git a/src/com/itmill/toolkit/demo/sampler/features/dates/DateLocale.png b/src/com/itmill/toolkit/demo/sampler/features/dates/DateLocale.png Binary files differnew file mode 100644 index 0000000000..dad35b72a0 --- /dev/null +++ b/src/com/itmill/toolkit/demo/sampler/features/dates/DateLocale.png diff --git a/src/com/itmill/toolkit/demo/sampler/features/dates/DateLocaleExample.java b/src/com/itmill/toolkit/demo/sampler/features/dates/DateLocaleExample.java new file mode 100644 index 0000000000..bc368acd15 --- /dev/null +++ b/src/com/itmill/toolkit/demo/sampler/features/dates/DateLocaleExample.java @@ -0,0 +1,48 @@ +package com.itmill.toolkit.demo.sampler.features.dates;
+
+import java.util.Locale;
+
+import com.itmill.toolkit.data.Item;
+import com.itmill.toolkit.data.Property;
+import com.itmill.toolkit.data.Property.ValueChangeEvent;
+import com.itmill.toolkit.demo.sampler.ExampleUtil;
+import com.itmill.toolkit.ui.ComboBox;
+import com.itmill.toolkit.ui.InlineDateField;
+import com.itmill.toolkit.ui.VerticalLayout;
+
+public class DateLocaleExample extends VerticalLayout implements
+ Property.ValueChangeListener {
+
+ private InlineDateField datetime;
+ private ComboBox localeSelection;
+
+ public DateLocaleExample() {
+ 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_MIN);
+ datetime.setImmediate(true);
+
+ // Create selection and fill it with locales
+ localeSelection = new ComboBox("Select date format:");
+ localeSelection.addListener(this);
+ localeSelection.setImmediate(true);
+ localeSelection
+ .setContainerDataSource(ExampleUtil.getLocaleContainer());
+
+ addComponent(datetime);
+ addComponent(localeSelection);
+ }
+
+ public void valueChange(ValueChangeEvent event) {
+ Item selected = localeSelection.getItem(event.getProperty().getValue());
+ datetime.setLocale((Locale) selected.getItemProperty(
+ ExampleUtil.locale_PROPERTY_LOCALE).getValue());
+ datetime.requestRepaint();
+ }
+}
diff --git a/src/com/itmill/toolkit/demo/sampler/features/dates/DatePopup.java b/src/com/itmill/toolkit/demo/sampler/features/dates/DatePopup.java new file mode 100644 index 0000000000..373f2bfc34 --- /dev/null +++ b/src/com/itmill/toolkit/demo/sampler/features/dates/DatePopup.java @@ -0,0 +1,42 @@ +package com.itmill.toolkit.demo.sampler.features.dates;
+
+import com.itmill.toolkit.demo.sampler.APIResource;
+import com.itmill.toolkit.demo.sampler.Feature;
+import com.itmill.toolkit.demo.sampler.NamedExternalResource;
+import com.itmill.toolkit.ui.DateField;
+import com.itmill.toolkit.ui.PopupDateField;
+
+public class DatePopup extends Feature {
+ @Override
+ public String getName() {
+ return "Date selection pop-up";
+ }
+
+ @Override
+ public String getDescription() {
+ return "The DateField component can be used to produce various"
+ + " date and time input fields with different resolutions."
+ + " The date and time format used with this component is"
+ + " reported to the Toolkit by the browser."
+ + "<br>In this example, the resolution is set to be one day"
+ + " and the DateField component is shown as a calendar pop-up.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(DateField.class),
+ new APIResource(PopupDateField.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { DateInline.class, DateLocale.class,
+ DateResolution.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
diff --git a/src/com/itmill/toolkit/demo/sampler/features/dates/DatePopup.png b/src/com/itmill/toolkit/demo/sampler/features/dates/DatePopup.png Binary files differnew file mode 100644 index 0000000000..14af990fe7 --- /dev/null +++ b/src/com/itmill/toolkit/demo/sampler/features/dates/DatePopup.png diff --git a/src/com/itmill/toolkit/demo/sampler/features/dates/DatePopupExample.java b/src/com/itmill/toolkit/demo/sampler/features/dates/DatePopupExample.java new file mode 100644 index 0000000000..46c0163068 --- /dev/null +++ b/src/com/itmill/toolkit/demo/sampler/features/dates/DatePopupExample.java @@ -0,0 +1,40 @@ +package com.itmill.toolkit.demo.sampler.features.dates;
+
+import java.text.DateFormat;
+
+import com.itmill.toolkit.data.Property;
+import com.itmill.toolkit.data.Property.ValueChangeEvent;
+import com.itmill.toolkit.ui.PopupDateField;
+import com.itmill.toolkit.ui.VerticalLayout;
+
+public class DatePopupExample extends VerticalLayout implements
+ Property.ValueChangeListener {
+
+ private PopupDateField datetime;
+
+ public DatePopupExample() {
+ setSpacing(true);
+
+ datetime = new PopupDateField("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(PopupDateField.RESOLUTION_DAY);
+
+ // Add valuechangelistener
+ datetime.addListener(this);
+ datetime.setImmediate(true);
+
+ addComponent(datetime);
+ }
+
+ public void valueChange(ValueChangeEvent event) {
+ // Get the new value and format it to the current locale
+ DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.SHORT);
+ String dateOut = dateFormatter.format(event.getProperty().getValue());
+ // Show notification
+ getWindow().showNotification("Starting date: " + dateOut);
+ }
+}
diff --git a/src/com/itmill/toolkit/demo/sampler/features/dates/DateResolution.java b/src/com/itmill/toolkit/demo/sampler/features/dates/DateResolution.java new file mode 100644 index 0000000000..174d1b2326 --- /dev/null +++ b/src/com/itmill/toolkit/demo/sampler/features/dates/DateResolution.java @@ -0,0 +1,43 @@ +package com.itmill.toolkit.demo.sampler.features.dates;
+
+import com.itmill.toolkit.demo.sampler.APIResource;
+import com.itmill.toolkit.demo.sampler.Feature;
+import com.itmill.toolkit.demo.sampler.NamedExternalResource;
+import com.itmill.toolkit.ui.DateField;
+import com.itmill.toolkit.ui.InlineDateField;
+
+public class DateResolution extends Feature {
+ @Override
+ public String getName() {
+ return "Date selection - Resolution";
+ }
+
+ @Override
+ public String getDescription() {
+ return "The DateField component can be used to produce various"
+ + " date and time input fields with different resolutions."
+ + " The date and time format used with this component is"
+ + " reported to the Toolkit by the browser."
+ + "<br>In this example, you can select a different resolution"
+ + " from the combo box and see how the calendar component"
+ + " will change.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ return new APIResource[] { new APIResource(DateField.class),
+ new APIResource(InlineDateField.class) };
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ return new Class[] { DateInline.class, DatePopup.class,
+ DateLocale.class };
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
diff --git a/src/com/itmill/toolkit/demo/sampler/features/dates/DateResolution.png b/src/com/itmill/toolkit/demo/sampler/features/dates/DateResolution.png Binary files differnew file mode 100644 index 0000000000..682a211cbd --- /dev/null +++ b/src/com/itmill/toolkit/demo/sampler/features/dates/DateResolution.png 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;
+ }
+}
|