You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NotificationDemo.java 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.itmill.toolkit.demo;
  5. import com.itmill.toolkit.data.Item;
  6. import com.itmill.toolkit.ui.AbstractSelect;
  7. import com.itmill.toolkit.ui.Button;
  8. import com.itmill.toolkit.ui.NativeSelect;
  9. import com.itmill.toolkit.ui.RichTextArea;
  10. import com.itmill.toolkit.ui.TextField;
  11. import com.itmill.toolkit.ui.Window;
  12. import com.itmill.toolkit.ui.Button.ClickEvent;
  13. import com.itmill.toolkit.ui.Button.ClickListener;
  14. /**
  15. * Demonstrates the use of Notifications.
  16. *
  17. * @author IT Mill Ltd.
  18. * @see com.itmill.toolkit.ui.Window
  19. */
  20. public class NotificationDemo extends com.itmill.toolkit.Application {
  21. // Dropdown select for notification type, using the native dropdown
  22. NativeSelect type;
  23. // Textfield for the notification caption
  24. TextField caption;
  25. // Textfield for the notification content
  26. TextField message;
  27. /**
  28. * The initialization method that is the only requirement for inheriting the
  29. * com.itmill.toolkit.service.Application class. It will be automatically
  30. * called by the framework when a user accesses the application.
  31. */
  32. public void init() {
  33. // Create new window for the application and give the window a visible.
  34. final Window main = new Window("Notification demo");
  35. // set as main window
  36. setMainWindow(main);
  37. // Create the 'type' dropdown select.
  38. type = new NativeSelect("Notification type");
  39. // no empty selection allowed
  40. type.setNullSelectionAllowed(false);
  41. // we want a different caption than the value
  42. type.addContainerProperty("caption", String.class, null);
  43. type.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY);
  44. type.setItemCaptionPropertyId("caption");
  45. // add some content (items) using the Container API
  46. Item i = type.addItem(new Integer(
  47. Window.Notification.TYPE_HUMANIZED_MESSAGE));
  48. i.getItemProperty("caption").setValue("Humanized message");
  49. i = type.addItem(new Integer(Window.Notification.TYPE_WARNING_MESSAGE));
  50. i.getItemProperty("caption").setValue("Warning message");
  51. i = type.addItem(new Integer(Window.Notification.TYPE_ERROR_MESSAGE));
  52. i.getItemProperty("caption").setValue("Error message");
  53. i = type
  54. .addItem(new Integer(Window.Notification.TYPE_TRAY_NOTIFICATION));
  55. i.getItemProperty("caption").setValue("Tray notification");
  56. // set the initially selected item
  57. type.setValue(new Integer(Window.Notification.TYPE_HUMANIZED_MESSAGE));
  58. main.addComponent(type); // add to layout
  59. // Notification caption
  60. caption = new TextField("Caption");
  61. caption.setColumns(20);
  62. caption.setValue("Brown Fox!");
  63. main.addComponent(caption);
  64. // Notification message
  65. message = new RichTextArea();
  66. message.setCaption("Message");
  67. message.setValue("A quick one jumped over the lazy dog.");
  68. main.addComponent(message); // add to layout
  69. // Button to show the notification
  70. final Button b = new Button("Show notification", new ClickListener() {
  71. // this is an inline ClickListener
  72. public void buttonClick(ClickEvent event) {
  73. // show the notification
  74. getMainWindow().showNotification((String) caption.getValue(),
  75. (String) message.getValue(),
  76. ((Integer) type.getValue()).intValue());
  77. }
  78. });
  79. main.addComponent(b); // add button to layout
  80. }
  81. }