Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

NotificationConfiguration.java 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * Copyright 2000-2018 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.ui;
  17. import java.io.Serializable;
  18. import com.vaadin.shared.ui.ui.NotificationRole;
  19. import com.vaadin.shared.ui.ui.UIState.NotificationTypeConfiguration;
  20. import com.vaadin.ui.Notification.Type;
  21. /**
  22. * Provides methods for configuring the notification.
  23. *
  24. * @author Vaadin Ltd
  25. * @since 7.2
  26. */
  27. public interface NotificationConfiguration extends Serializable {
  28. /**
  29. * Sets the accessibility prefix for a notification type.
  30. * <p>
  31. * This prefix is read to assistive device users before the content of the
  32. * notification, but not visible on the page.
  33. *
  34. * @param type
  35. * type of the notification
  36. * @param prefix
  37. * string that is placed before the notification content
  38. */
  39. public void setAssistivePrefix(Type type, String prefix);
  40. /**
  41. * Gets the accessibility prefix for a notification type.
  42. * <p>
  43. * This prefix is read to assistive device users before the content of the
  44. * notification, but not visible on the page.
  45. *
  46. * @param type
  47. * type of the notification
  48. * @return The accessibility prefix for the provided notification type
  49. */
  50. public String getAssistivePrefix(Type type);
  51. /**
  52. * Sets the accessibility postfix for a notification type.
  53. * <p>
  54. * This postfix is read to assistive device users after the content of the
  55. * notification, but not visible on the page.
  56. *
  57. * @param type
  58. * type of the notification
  59. * @param postfix
  60. * string that is placed after the notification content
  61. */
  62. public void setAssistivePostfix(Type type, String postfix);
  63. /**
  64. * Gets the accessibility postfix for a notification type.
  65. * <p>
  66. * This postfix is read to assistive device users after the content of the
  67. * notification, but not visible on the page.
  68. *
  69. * @param type
  70. * type of the notification
  71. * @return The accessibility postfix for the provided notification type
  72. */
  73. public String getAssistivePostfix(Type type);
  74. /**
  75. * Sets the WAI-ARIA role for a notification type.
  76. * <p>
  77. * This role defines how an assistive device handles a notification.
  78. * Available roles are alert and status (@see
  79. * <a href="http://www.w3.org/TR/2011/CR-wai-aria-20110118/roles">Roles
  80. * Model</a>).
  81. *
  82. * The default role is alert.
  83. *
  84. * @param type
  85. * type of the notification
  86. * @param role
  87. * role to set for the notification type
  88. */
  89. public void setAssistiveRole(Type type, NotificationRole role);
  90. /**
  91. * Gets the WAI-ARIA role for a notification type.
  92. * <p>
  93. * This role defines how an assistive device handles a notification.
  94. * Available roles are alert and status (@see
  95. * <a href="http://www.w3.org/TR/2011/CR-wai-aria-20110118/roles">Roles
  96. * Model</a>)
  97. * <p>
  98. * The default role is alert.
  99. *
  100. * @param type
  101. * type of the notification
  102. * @return role to set for the notification type
  103. */
  104. public NotificationRole getAssistiveRole(Type type);
  105. }
  106. class NotificationConfigurationImpl implements NotificationConfiguration {
  107. private final UI ui;
  108. public NotificationConfigurationImpl(UI ui) {
  109. this.ui = ui;
  110. }
  111. @Override
  112. public void setAssistivePrefix(Type type, String prefix) {
  113. getConfigurationBean(type).prefix = prefix;
  114. }
  115. @Override
  116. public String getAssistivePrefix(Type type) {
  117. NotificationTypeConfiguration styleSetup = getTypeConf(type);
  118. if (styleSetup != null) {
  119. return styleSetup.prefix;
  120. }
  121. return null;
  122. }
  123. @Override
  124. public void setAssistivePostfix(Type type, String postfix) {
  125. getConfigurationBean(type).postfix = postfix;
  126. }
  127. @Override
  128. public String getAssistivePostfix(Type type) {
  129. NotificationTypeConfiguration styleSetup = getTypeConf(type);
  130. if (styleSetup != null) {
  131. return styleSetup.postfix;
  132. }
  133. return null;
  134. }
  135. @Override
  136. public void setAssistiveRole(Type type, NotificationRole role) {
  137. getConfigurationBean(type).notificationRole = role;
  138. }
  139. @Override
  140. public NotificationRole getAssistiveRole(Type type) {
  141. NotificationTypeConfiguration styleSetup = getTypeConf(type);
  142. if (styleSetup != null) {
  143. return styleSetup.notificationRole;
  144. }
  145. return null;
  146. }
  147. private NotificationTypeConfiguration getConfigurationBean(Type type) {
  148. NotificationTypeConfiguration styleSetup = getTypeConf(type);
  149. if (styleSetup == null) {
  150. styleSetup = new NotificationTypeConfiguration();
  151. ui.getState().notificationConfigurations.put(type.getStyle(),
  152. styleSetup);
  153. }
  154. return styleSetup;
  155. }
  156. private NotificationTypeConfiguration getTypeConf(Type type) {
  157. return ui.getState().notificationConfigurations.get(type.getStyle());
  158. }
  159. }