All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vaadin.ui.NotificationConfiguration Maven / Gradle / Ivy

There is a newer version: 8.27.3
Show newest version
/*
 * Copyright (C) 2000-2024 Vaadin Ltd
 *
 * This program is available under Vaadin Commercial License and Service Terms.
 *
 * See  for the full
 * license.
 */

package com.vaadin.ui;

import java.io.Serializable;

import com.vaadin.shared.ui.ui.NotificationRole;
import com.vaadin.shared.ui.ui.UIState.NotificationTypeConfiguration;
import com.vaadin.ui.Notification.Type;

/**
 * Provides methods for configuring the notification.
 *
 * @author Vaadin Ltd
 * @since 7.2
 */
public interface NotificationConfiguration extends Serializable {
    /**
     * Sets the accessibility prefix for a notification type.
     * 

* 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 */ public void setAssistivePrefix(Type type, String prefix); /** * Gets the accessibility prefix for a notification type. *

* 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 */ public String getAssistivePrefix(Type type); /** * Sets the accessibility postfix for a notification type. *

* 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 */ public void setAssistivePostfix(Type type, String postfix); /** * Gets the accessibility postfix for a notification type. *

* 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 */ public String getAssistivePostfix(Type type); /** * Sets the WAI-ARIA role for a notification type. *

* This role defines how an assistive device handles a notification. * Available roles are alert and status (@see * Roles * Model). * * The default role is alert. * * @param type * type of the notification * @param role * role to set for the notification type */ public void setAssistiveRole(Type type, NotificationRole role); /** * Gets the WAI-ARIA role for a notification type. *

* This role defines how an assistive device handles a notification. * Available roles are alert and status (@see * Roles * Model) *

* The default role is alert. * * @param type * type of the notification * @return role to set for the notification type */ public NotificationRole getAssistiveRole(Type type); } class NotificationConfigurationImpl implements NotificationConfiguration { private final UI ui; public NotificationConfigurationImpl(UI ui) { this.ui = ui; } @Override public void setAssistivePrefix(Type type, String prefix) { getConfigurationBean(type).prefix = prefix; } @Override public String getAssistivePrefix(Type type) { NotificationTypeConfiguration styleSetup = getTypeConf(type); if (styleSetup != null) { return styleSetup.prefix; } return null; } @Override public void setAssistivePostfix(Type type, String postfix) { getConfigurationBean(type).postfix = postfix; } @Override public String getAssistivePostfix(Type type) { NotificationTypeConfiguration styleSetup = getTypeConf(type); if (styleSetup != null) { return styleSetup.postfix; } return null; } @Override public void setAssistiveRole(Type type, NotificationRole role) { getConfigurationBean(type).notificationRole = role; } @Override public NotificationRole getAssistiveRole(Type type) { NotificationTypeConfiguration styleSetup = getTypeConf(type); if (styleSetup != null) { return styleSetup.notificationRole; } return null; } private NotificationTypeConfiguration getConfigurationBean(Type type) { NotificationTypeConfiguration styleSetup = getTypeConf(type); if (styleSetup == null) { styleSetup = new NotificationTypeConfiguration(); ui.getState().notificationConfigurations.put(type.getStyle(), styleSetup); } return styleSetup; } private NotificationTypeConfiguration getTypeConf(Type type) { return ui.getState().notificationConfigurations.get(type.getStyle()); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy