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.

NotificationExample.java 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.automatedtests.featurebrowser;
  5. import com.vaadin.data.Item;
  6. import com.vaadin.ui.AbstractSelect;
  7. import com.vaadin.ui.Alignment;
  8. import com.vaadin.ui.Button;
  9. import com.vaadin.ui.CustomComponent;
  10. import com.vaadin.ui.NativeSelect;
  11. import com.vaadin.ui.RichTextArea;
  12. import com.vaadin.ui.TextField;
  13. import com.vaadin.ui.VerticalLayout;
  14. import com.vaadin.ui.Window;
  15. import com.vaadin.ui.Button.ClickEvent;
  16. import com.vaadin.ui.Button.ClickListener;
  17. /**
  18. * Demonstrates the use of Notifications.
  19. *
  20. * @author IT Mill Ltd.
  21. * @see com.vaadin.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 VerticalLayout main = new VerticalLayout();
  37. main.setSizeUndefined();
  38. main.setSpacing(true);
  39. main.setMargin(true); // use theme-specific margin
  40. setCompositionRoot(main);
  41. // Create the 'type' dropdown select.
  42. type = new NativeSelect("Notification type");
  43. main.addComponent(type);
  44. // no empty selection allowed
  45. type.setNullSelectionAllowed(false);
  46. // we want a different caption than the value
  47. type.addContainerProperty("caption", String.class, null);
  48. type.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY);
  49. type.setItemCaptionPropertyId("caption");
  50. // add some content (items) using the Container API
  51. Item i = type.addItem(new Integer(
  52. Window.Notification.TYPE_HUMANIZED_MESSAGE));
  53. i.getItemProperty("caption").setValue("Humanized message");
  54. i = type.addItem(new Integer(Window.Notification.TYPE_WARNING_MESSAGE));
  55. i.getItemProperty("caption").setValue("Warning message");
  56. i = type.addItem(new Integer(Window.Notification.TYPE_ERROR_MESSAGE));
  57. i.getItemProperty("caption").setValue("Error message");
  58. i = type
  59. .addItem(new Integer(Window.Notification.TYPE_TRAY_NOTIFICATION));
  60. i.getItemProperty("caption").setValue("Tray notification");
  61. // set the initially selected item
  62. type.setValue(new Integer(Window.Notification.TYPE_HUMANIZED_MESSAGE));
  63. // Notification caption
  64. caption = new TextField("Caption");
  65. main.addComponent(caption);
  66. caption.setColumns(20);
  67. caption.setValue("Brown Fox!");
  68. // Notification message
  69. message = new RichTextArea();
  70. main.addComponent(message);
  71. message.setCaption("Message");
  72. message.setValue("A quick one jumped over the lazy dog.");
  73. // Button to show the notification
  74. final Button b = new Button("Show notification", new ClickListener() {
  75. // this is an inline ClickListener
  76. public void buttonClick(ClickEvent event) {
  77. // show the notification
  78. getWindow().showNotification((String) caption.getValue(),
  79. (String) message.getValue(),
  80. ((Integer) type.getValue()).intValue());
  81. }
  82. });
  83. main.addComponent(b);
  84. main.setComponentAlignment(b, Alignment.MIDDLE_RIGHT);
  85. }
  86. }