您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

NotificationExample.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.itmill.toolkit.demo.featurebrowser;
  5. import java.util.Date;
  6. import com.itmill.toolkit.data.Item;
  7. import com.itmill.toolkit.ui.AbstractSelect;
  8. import com.itmill.toolkit.ui.Button;
  9. import com.itmill.toolkit.ui.CustomComponent;
  10. import com.itmill.toolkit.ui.NativeSelect;
  11. import com.itmill.toolkit.ui.OrderedLayout;
  12. import com.itmill.toolkit.ui.RichTextArea;
  13. import com.itmill.toolkit.ui.TextField;
  14. import com.itmill.toolkit.ui.Window;
  15. import com.itmill.toolkit.ui.Button.ClickEvent;
  16. import com.itmill.toolkit.ui.Button.ClickListener;
  17. /**
  18. * Demonstrates the use of Notifications.
  19. *
  20. * @author IT Mill Ltd.
  21. * @see com.itmill.toolkit.ui.Window
  22. */
  23. public class NotificationExample extends CustomComponent {
  24. // Dropdown select for notification type, using the native dropdown
  25. NativeSelect type;
  26. // Textfield for the notification caption
  27. TextField caption;
  28. // Textfield for the notification content
  29. TextField message;
  30. /**
  31. * Default constructor; We're subclassing CustomComponent, so we need to
  32. * choose a root component and set it as composition root.
  33. */
  34. public NotificationExample() {
  35. // Main layout
  36. final OrderedLayout main = new OrderedLayout();
  37. main.setMargin(true); // use theme-specific margin
  38. setCompositionRoot(main);
  39. // Create the 'type' dropdown select.
  40. type = new NativeSelect("Notification type");
  41. main.addComponent(type);
  42. // no empty selection allowed
  43. type.setNullSelectionAllowed(false);
  44. // we want a different caption than the value
  45. type.addContainerProperty("caption", String.class, null);
  46. type.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY);
  47. type.setItemCaptionPropertyId("caption");
  48. // add some content (items) using the Container API
  49. Item i = type.addItem(new Integer(
  50. Window.Notification.TYPE_HUMANIZED_MESSAGE));
  51. i.getItemProperty("caption").setValue("Humanized message");
  52. i = type.addItem(new Integer(Window.Notification.TYPE_WARNING_MESSAGE));
  53. i.getItemProperty("caption").setValue("Warning message");
  54. i = type.addItem(new Integer(Window.Notification.TYPE_ERROR_MESSAGE));
  55. i.getItemProperty("caption").setValue("Error message");
  56. i = type
  57. .addItem(new Integer(Window.Notification.TYPE_TRAY_NOTIFICATION));
  58. i.getItemProperty("caption").setValue("Tray notification");
  59. // set the initially selected item
  60. type.setValue(new Integer(Window.Notification.TYPE_HUMANIZED_MESSAGE));
  61. // Notification caption
  62. caption = new TextField("Caption");
  63. main.addComponent(caption);
  64. caption.setColumns(20);
  65. caption.setValue("Brown Fox!");
  66. // Notification message
  67. message = new RichTextArea();
  68. main.addComponent(message);
  69. message.setCaption("Message");
  70. message.setValue("A quick one jumped over the lazy dog.");
  71. // Button to show the notification
  72. final Button b = new Button("Show notification", new ClickListener() {
  73. // this is an inline ClickListener
  74. public void buttonClick(ClickEvent event) {
  75. // show the notification
  76. getWindow().showNotification((String) caption.getValue(),
  77. (String) message.getValue(),
  78. ((Integer) type.getValue()).intValue());
  79. getWindow().setCaption(new Date().toString());
  80. }
  81. });
  82. main.addComponent(b);
  83. main.setComponentAlignment(b, OrderedLayout.ALIGNMENT_RIGHT,
  84. OrderedLayout.ALIGNMENT_VERTICAL_CENTER);
  85. }
  86. }