/* * Copyright 2000-2022 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */packagecom.vaadin.ui;importjava.io.Serializable;importcom.vaadin.shared.ui.ui.NotificationRole;importcom.vaadin.shared.ui.ui.UIState.NotificationTypeConfiguration;importcom.vaadin.ui.Notification.Type;/** * Provides methods for configuring the notification. * * @author Vaadin Ltd * @since 7.2 */publicinterfaceNotificationConfigurationextendsSerializable{/** * Sets the accessibility prefix for a notification type. * <p> * This prefix is read to assistive device users before the content of the * notification, but not visible on the page. * * @param type * type of the notification * @param prefix * string that is placed before the notification content */publicvoidsetAssistivePrefix(Typetype,Stringprefix);/** * Gets the accessibility prefix for a notification type. * <p> * This prefix is read to assistive device users before the content of the * notification, but not visible on the page. * * @param type * type of the notification * @return The accessibility prefix for the provided notification type */publicStringgetAssistivePrefix(Typetype);/** * Sets the accessibility postfix for a notification type. * <p> * This postfix is read to assistive device users after the content of the * notification, but not visible on the page. * * @param type * type of the notification * @param postfix * string that is placed after the notification content */publicvoidsetAssistivePostfix(Typetype,Stringpostfix);/** * Gets the accessibility postfix for a notification type. * <p> * This postfix is read to assistive device users after the content of the * notification, but not visible on the page. * * @param type * type of the notification * @return The accessibility postfix for the provided notification type */publicStringgetAssistivePostfix(Typetype);/** * Sets the WAI-ARIA role for a notification type. * <p> * This role defines how an assistive device handles a notification. * Available roles are alert and status (@see * <a href="http://www.w3.org/TR/2011/CR-wai-aria-20110118/roles">Roles * Model</a>). * * The default role is alert. * * @param type * type of the notification * @param role * role to set for the notification type */publicvoidsetAssistiveRole(Typetype,NotificationRolerole);/** * Gets the WAI-ARIA role for a notification type. * <p> * This role defines how an assistive device handles a notification. * Available roles are alert and status (@see * <a href="http://www.w3.org/TR/2011/CR-wai-aria-20110118/roles">Roles * Model</a>) * <p> * The default role is alert. * * @param type * type of the notification * @return role to set for the notification type */publicNotificationRolegetAssistiveRole(Typetype);}classNotificationConfigurationImplimplementsNotificationConfiguration{privatefinalUIui;publicNotificationConfigurationImpl(UIui){this.ui=ui;}@OverridepublicvoidsetAssistivePrefix(Typetype,Stringprefix){getConfigurationBean(type).prefix=prefix;}@OverridepublicStringgetAssistivePrefix(Typetype){NotificationTypeConfigurationstyleSetup=getTypeConf(type);if(styleSetup!=null){returnstyleSetup.prefix;}returnnull;}@OverridepublicvoidsetAssistivePostfix(Typetype,Stringpostfix){getConfigurationBean(type).postfix=postfix;}@OverridepublicStringgetAssistivePostfix(Typetype){NotificationTypeConfigurationstyleSetup=getTypeConf(type);if(styleSetup!=null){returnstyleSetup.postfix;}returnnull;}@OverridepublicvoidsetAssistiveRole(Typetype,NotificationRolerole){getConfigurationBean(type).notificationRole=role;}@OverridepublicNotificationRolegetAssistiveRole(Typetype){NotificationTypeConfigurationstyleSetup=getTypeConf(type);if(styleSetup!=null){returnstyleSetup.notificationRole;}returnnull;}privateNotificationTypeConfigurationgetConfigurationBean(Typetype){NotificationTypeConfigurationstyleSetup=getTypeConf(type);if(styleSetup==null){styleSetup=newNotificationTypeConfiguration();ui.getState().notificationConfigurations.put(type.getStyle(),styleSetup);}returnstyleSetup;}privateNotificationTypeConfigurationgetTypeConf(Typetype){returnui.getState().notificationConfigurations.get(type.getStyle());}}