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.

NotificationsWaiAria.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package com.vaadin.tests.components.notification;
  2. import com.vaadin.data.Item;
  3. import com.vaadin.server.Page;
  4. import com.vaadin.shared.ui.ui.NotificationRole;
  5. import com.vaadin.tests.components.TestBase;
  6. import com.vaadin.ui.Button;
  7. import com.vaadin.ui.Button.ClickEvent;
  8. import com.vaadin.ui.Button.ClickListener;
  9. import com.vaadin.ui.ComboBox;
  10. import com.vaadin.ui.NativeSelect;
  11. import com.vaadin.ui.Notification;
  12. import com.vaadin.ui.Notification.Type;
  13. import com.vaadin.ui.NotificationConfiguration;
  14. import com.vaadin.ui.TextArea;
  15. import com.vaadin.ui.TextField;
  16. import com.vaadin.ui.UI;
  17. public class NotificationsWaiAria extends TestBase {
  18. private static final String CAPTION = "CAPTION";
  19. private static final String ROLE = "ROLE";
  20. private TextField prefix;
  21. private TextField postfix;
  22. private NativeSelect role;
  23. private TextArea tf;
  24. private ComboBox type;
  25. @SuppressWarnings("deprecation")
  26. @Override
  27. protected void setup() {
  28. prefix = new TextField("Prefix", "Info");
  29. addComponent(prefix);
  30. postfix = new TextField("Postfix",
  31. " - closes automatically after 10 seconds");
  32. addComponent(postfix);
  33. role = new NativeSelect("NotificationRole");
  34. role.addItem(NotificationRole.ALERT);
  35. role.addItem(NotificationRole.STATUS);
  36. role.setValue(role.getItemIds().iterator().next());
  37. addComponent(role);
  38. tf = new TextArea("Text", "Hello world");
  39. tf.setRows(10);
  40. addComponent(tf);
  41. type = new ComboBox();
  42. type.setNullSelectionAllowed(false);
  43. type.addContainerProperty(CAPTION, String.class, "");
  44. type.setItemCaptionPropertyId(CAPTION);
  45. Item item = type.addItem(Notification.TYPE_HUMANIZED_MESSAGE);
  46. item.getItemProperty(CAPTION).setValue("Humanized");
  47. item = type.addItem(Notification.TYPE_ERROR_MESSAGE);
  48. item.getItemProperty(CAPTION).setValue("Error");
  49. item = type.addItem(Notification.TYPE_WARNING_MESSAGE);
  50. item.getItemProperty(CAPTION).setValue("Warning");
  51. item = type.addItem(Notification.TYPE_TRAY_NOTIFICATION);
  52. item.getItemProperty(CAPTION).setValue("Tray");
  53. item = type.addItem(Notification.Type.ASSISTIVE_NOTIFICATION);
  54. item.getItemProperty(CAPTION).setValue("Assistive");
  55. type.setValue(type.getItemIds().iterator().next());
  56. addComponent(type);
  57. Button showNotification = new Button("Show notification",
  58. new SettingHandler());
  59. addComponent(showNotification);
  60. Button showDefaultNotification = new Button("Default notification",
  61. new DefaultHandler());
  62. addComponent(showDefaultNotification);
  63. }
  64. @Override
  65. protected String getDescription() {
  66. return "Generic test case for notifications";
  67. }
  68. @Override
  69. protected Integer getTicketNumber() {
  70. // TODO Auto-generated method stub
  71. return null;
  72. }
  73. private class SettingHandler implements ClickListener {
  74. @Override
  75. public void buttonClick(ClickEvent event) {
  76. Type typeValue = (Type) type.getValue();
  77. Notification n = new Notification(tf.getValue(), typeValue);
  78. n.setHtmlContentAllowed(true);
  79. NotificationConfiguration notificationConf = UI.getCurrent()
  80. .getNotificationConfiguration();
  81. notificationConf.setAssistivePrefix(typeValue, prefix.getValue());
  82. notificationConf.setAssistivePostfix(typeValue, postfix.getValue());
  83. notificationConf.setAssistiveRole(typeValue,
  84. (NotificationRole) role.getValue());
  85. n.show(Page.getCurrent());
  86. }
  87. }
  88. private class DefaultHandler implements ClickListener {
  89. @Override
  90. public void buttonClick(ClickEvent event) {
  91. Notification n = new Notification(tf.getValue(),
  92. (Type) type.getValue());
  93. n.setHtmlContentAllowed(true);
  94. n.show(Page.getCurrent());
  95. }
  96. }
  97. }