aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/itmill/toolkit/demo/featurebrowser/NotificationExample.java
diff options
context:
space:
mode:
authorMarc Englund <marc.englund@itmill.com>2007-11-29 09:02:35 +0000
committerMarc Englund <marc.englund@itmill.com>2007-11-29 09:02:35 +0000
commit350b6b063eb86122787ee6582d9a0bc92fde80d6 (patch)
tree917e87a85ee8d64c3cfdccadad9bcf8d4a5c40d8 /src/com/itmill/toolkit/demo/featurebrowser/NotificationExample.java
parent1c63d43f7cab7f0307e132fb14f3f15415aec9b5 (diff)
downloadvaadin-framework-350b6b063eb86122787ee6582d9a0bc92fde80d6.tar.gz
vaadin-framework-350b6b063eb86122787ee6582d9a0bc92fde80d6.zip
Pre-refactor commit.
svn changeset:3033/svn branch:trunk
Diffstat (limited to 'src/com/itmill/toolkit/demo/featurebrowser/NotificationExample.java')
-rw-r--r--src/com/itmill/toolkit/demo/featurebrowser/NotificationExample.java90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/com/itmill/toolkit/demo/featurebrowser/NotificationExample.java b/src/com/itmill/toolkit/demo/featurebrowser/NotificationExample.java
new file mode 100644
index 0000000000..c007df8e74
--- /dev/null
+++ b/src/com/itmill/toolkit/demo/featurebrowser/NotificationExample.java
@@ -0,0 +1,90 @@
+package com.itmill.toolkit.demo.featurebrowser;
+
+import java.util.Date;
+
+import com.itmill.toolkit.data.Item;
+import com.itmill.toolkit.ui.AbstractSelect;
+import com.itmill.toolkit.ui.Button;
+import com.itmill.toolkit.ui.CustomComponent;
+import com.itmill.toolkit.ui.NativeSelect;
+import com.itmill.toolkit.ui.OrderedLayout;
+import com.itmill.toolkit.ui.RichTextArea;
+import com.itmill.toolkit.ui.TextField;
+import com.itmill.toolkit.ui.Window;
+import com.itmill.toolkit.ui.Button.ClickEvent;
+import com.itmill.toolkit.ui.Button.ClickListener;
+
+/**
+ * Demonstrates the use of Notifications.
+ *
+ * @author IT Mill Ltd.
+ * @see com.itmill.toolkit.ui.Window
+ */
+public class NotificationExample extends CustomComponent {
+
+ // Dropdown select for notification type, using the native dropdown
+ NativeSelect type;
+ // Textfield for the notification caption
+ TextField caption;
+ // Textfield for the notification content
+ TextField message;
+
+ /**
+ * Default constructor; We're subclassing CustomComponent, so we need to
+ * choose a root component and set it as composition root.
+ */
+ public NotificationExample() {
+ // Main layout
+ OrderedLayout main = new OrderedLayout();
+ main.setMargin(true); // use theme-specific margin
+ setCompositionRoot(main);
+
+ // Create the 'type' dropdown select.
+ type = new NativeSelect("Notification type");
+ main.addComponent(type);
+ // no empty selection allowed
+ type.setNullSelectionAllowed(false);
+ // we want a different caption than the value
+ type.addContainerProperty("caption", String.class, null);
+ type.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY);
+ type.setItemCaptionPropertyId("caption");
+ // add some content (items) using the Container API
+ Item i = type.addItem(new Integer(
+ Window.Notification.TYPE_HUMANIZED_MESSAGE));
+ i.getItemProperty("caption").setValue("Humanized message");
+ i = type.addItem(new Integer(Window.Notification.TYPE_WARNING_MESSAGE));
+ i.getItemProperty("caption").setValue("Warning message");
+ i = type.addItem(new Integer(Window.Notification.TYPE_ERROR_MESSAGE));
+ i.getItemProperty("caption").setValue("Error message");
+ i = type
+ .addItem(new Integer(Window.Notification.TYPE_TRAY_NOTIFICATION));
+ i.getItemProperty("caption").setValue("Tray notification");
+ // set the initially selected item
+ type.setValue(new Integer(Window.Notification.TYPE_HUMANIZED_MESSAGE));
+
+ // Notification caption
+ caption = new TextField("Caption");
+ main.addComponent(caption);
+ caption.setColumns(20);
+ caption.setValue("Brown Fox!");
+
+ // Notification message
+ message = new RichTextArea();
+ main.addComponent(message);
+ message.setCaption("Message");
+ message.setValue("A quick one jumped over the lazy dog.");
+
+ // Button to show the notification
+ Button b = new Button("Show notification", new ClickListener() {
+ // this is an inline ClickListener
+ public void buttonClick(ClickEvent event) {
+ // show the notification
+ getWindow().showNotification((String) caption.getValue(),
+ (String) message.getValue(),
+ ((Integer) type.getValue()).intValue());
+ getWindow().setCaption(new Date().toString());
+ }
+ });
+ main.addComponent(b);
+ }
+}