Search in sources :

Example 1 with LocaleChangeEvent

use of com.vaadin.flow.i18n.LocaleChangeEvent in project flow by vaadin.

the class EventUtil method informLocaleChangeObservers.

/**
 * Inform components implementing {@link LocaleChangeObserver} about locale
 * change.
 *
 * @param ui
 *            UI for locale change
 * @param components
 *            components to search
 */
public static void informLocaleChangeObservers(UI ui, List<HasElement> components) {
    LocaleChangeEvent localeChangeEvent = new LocaleChangeEvent(ui, ui.getLocale());
    collectLocaleChangeObservers(components).forEach(observer -> observer.localeChange(localeChangeEvent));
}
Also used : LocaleChangeEvent(com.vaadin.flow.i18n.LocaleChangeEvent)

Example 2 with LocaleChangeEvent

use of com.vaadin.flow.i18n.LocaleChangeEvent in project flow by vaadin.

the class ComponentUtil method onComponentAttach.

/**
 * Handles triggering the {@link Component#onAttach(AttachEvent) onAttach}
 * method and firing the {@link AttachEvent} for the given component when it
 * has been attached to a UI.
 *
 * @param component
 *            the component attached to a UI
 * @param initialAttach
 *            indicates if this is the first time the component (element)
 *            has been attached
 */
public static void onComponentAttach(Component component, boolean initialAttach) {
    if (component instanceof Composite) {
        onComponentAttach(((Composite<?>) component).getContent(), initialAttach);
    }
    Optional<UI> ui = component.getUI();
    if (ui.isPresent() && component instanceof LocaleChangeObserver) {
        LocaleChangeEvent localeChangeEvent = new LocaleChangeEvent(ui.get(), ui.get().getLocale());
        ((LocaleChangeObserver) component).localeChange(localeChangeEvent);
    }
    AttachEvent attachEvent = new AttachEvent(component, initialAttach);
    component.onAttach(attachEvent);
    fireEvent(component, attachEvent);
    // internal state
    if (component instanceof HasEnabled && component.getElement().isEnabled() != component.getElement().getNode().isEnabledSelf()) {
        Element parent = component.getElement().getParent();
        if (parent != null && isAttachedToParent(component.getElement(), parent)) {
            component.onEnabledStateChanged(component.getElement().isEnabled());
        }
    }
}
Also used : LocaleChangeObserver(com.vaadin.flow.i18n.LocaleChangeObserver) MapToExistingElement(com.vaadin.flow.component.Component.MapToExistingElement) Element(com.vaadin.flow.dom.Element) LocaleChangeEvent(com.vaadin.flow.i18n.LocaleChangeEvent)

Example 3 with LocaleChangeEvent

use of com.vaadin.flow.i18n.LocaleChangeEvent in project flow by vaadin.

the class EventUtil method informLocaleChangeObservers.

/**
 * Inform components connected to the given ui that implement
 * {@link LocaleChangeObserver} about locale change.
 *
 * @param ui
 *            UI for locale change
 */
public static void informLocaleChangeObservers(UI ui) {
    LocaleChangeEvent localeChangeEvent = new LocaleChangeEvent(ui, ui.getLocale());
    collectLocaleChangeObservers(ui.getElement()).forEach(observer -> observer.localeChange(localeChangeEvent));
}
Also used : LocaleChangeEvent(com.vaadin.flow.i18n.LocaleChangeEvent)

Aggregations

LocaleChangeEvent (com.vaadin.flow.i18n.LocaleChangeEvent)3 MapToExistingElement (com.vaadin.flow.component.Component.MapToExistingElement)1 Element (com.vaadin.flow.dom.Element)1 LocaleChangeObserver (com.vaadin.flow.i18n.LocaleChangeObserver)1