Search in sources :

Example 1 with ListenerPriority

use of com.vaadin.flow.router.ListenerPriority in project flow by vaadin.

the class UIInternals method addListener.

private <E> Registration addListener(Class<E> handler, E listener) {
    session.checkHasLock();
    List<E> list = (List<E>) listeners.computeIfAbsent(handler, key -> new ArrayList<>());
    list.add(listener);
    list.sort((o1, o2) -> {
        Class<?> o1Class = o1.getClass();
        Class<?> o2Class = o2.getClass();
        final ListenerPriority listenerPriority1 = o1Class.getAnnotation(ListenerPriority.class);
        final ListenerPriority listenerPriority2 = o2Class.getAnnotation(ListenerPriority.class);
        final int priority1 = listenerPriority1 != null ? listenerPriority1.value() : 0;
        final int priority2 = listenerPriority2 != null ? listenerPriority2.value() : 0;
        // we want to have a descending order
        return Integer.compare(priority2, priority1);
    });
    return () -> list.remove(listener);
}
Also used : CssImportData(com.vaadin.flow.server.frontend.FallbackChunk.CssImportData) HeartbeatEvent(com.vaadin.flow.component.HeartbeatEvent) Component(com.vaadin.flow.component.Component) JavaScript(com.vaadin.flow.component.dependency.JavaScript) LoadingIndicatorConfigurationMap(com.vaadin.flow.internal.nodefeature.LoadingIndicatorConfigurationMap) CssImport(com.vaadin.flow.component.dependency.CssImport) ComponentUtil(com.vaadin.flow.component.ComponentUtil) Registration(com.vaadin.flow.shared.Registration) LoggerFactory(org.slf4j.LoggerFactory) BeforeEnterHandler(com.vaadin.flow.router.internal.BeforeEnterHandler) Router(com.vaadin.flow.router.Router) ExtendedClientDetails(com.vaadin.flow.component.page.ExtendedClientDetails) PushConfigurationMap(com.vaadin.flow.internal.nodefeature.PushConfigurationMap) AfterNavigationListener(com.vaadin.flow.router.AfterNavigationListener) PushMode(com.vaadin.flow.shared.communication.PushMode) AfterNavigationHandler(com.vaadin.flow.router.internal.AfterNavigationHandler) Map(java.util.Map) PushConnection(com.vaadin.flow.server.communication.PushConnection) ContinueNavigationAction(com.vaadin.flow.router.BeforeLeaveEvent.ContinueNavigationAction) UI(com.vaadin.flow.component.UI) ConstantPool(com.vaadin.flow.internal.ConstantPool) VaadinSession(com.vaadin.flow.server.VaadinSession) IdentityHashMap(java.util.IdentityHashMap) BeforeLeaveListener(com.vaadin.flow.router.BeforeLeaveListener) BasicElementStateProvider(com.vaadin.flow.dom.impl.BasicElementStateProvider) AnnotationReader(com.vaadin.flow.internal.AnnotationReader) PushConfiguration(com.vaadin.flow.component.PushConfiguration) Set(java.util.Set) Collectors(java.util.stream.Collectors) ReconnectDialogConfigurationMap(com.vaadin.flow.internal.nodefeature.ReconnectDialogConfigurationMap) Serializable(java.io.Serializable) BeforeLeaveHandler(com.vaadin.flow.router.internal.BeforeLeaveHandler) List(java.util.List) VaadinContext(com.vaadin.flow.server.VaadinContext) Stream(java.util.stream.Stream) FallbackChunk(com.vaadin.flow.server.frontend.FallbackChunk) VaadinService(com.vaadin.flow.server.VaadinService) Optional(java.util.Optional) JsModule(com.vaadin.flow.component.dependency.JsModule) UrlUtil(com.vaadin.flow.internal.UrlUtil) HashMap(java.util.HashMap) StateTree(com.vaadin.flow.internal.StateTree) BeforeEnterListener(com.vaadin.flow.router.BeforeEnterListener) ListenerPriority(com.vaadin.flow.router.ListenerPriority) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) NodeFeature(com.vaadin.flow.internal.nodefeature.NodeFeature) ElementUtil(com.vaadin.flow.dom.ElementUtil) JsonCodec(com.vaadin.flow.internal.JsonCodec) Location(com.vaadin.flow.router.Location) HeartbeatListener(com.vaadin.flow.component.HeartbeatListener) Page(com.vaadin.flow.component.page.Page) RouterLayout(com.vaadin.flow.router.RouterLayout) Logger(org.slf4j.Logger) HasElement(com.vaadin.flow.component.HasElement) StyleSheet(com.vaadin.flow.component.dependency.StyleSheet) DependencyInfo(com.vaadin.flow.component.internal.ComponentMetaData.DependencyInfo) ArrayDeque(java.util.ArrayDeque) PollConfigurationMap(com.vaadin.flow.internal.nodefeature.PollConfigurationMap) Collections(java.util.Collections) Push(com.vaadin.flow.component.page.Push) ListenerPriority(com.vaadin.flow.router.ListenerPriority) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

Component (com.vaadin.flow.component.Component)1 ComponentUtil (com.vaadin.flow.component.ComponentUtil)1 HasElement (com.vaadin.flow.component.HasElement)1 HeartbeatEvent (com.vaadin.flow.component.HeartbeatEvent)1 HeartbeatListener (com.vaadin.flow.component.HeartbeatListener)1 PushConfiguration (com.vaadin.flow.component.PushConfiguration)1 UI (com.vaadin.flow.component.UI)1 CssImport (com.vaadin.flow.component.dependency.CssImport)1 JavaScript (com.vaadin.flow.component.dependency.JavaScript)1 JsModule (com.vaadin.flow.component.dependency.JsModule)1 StyleSheet (com.vaadin.flow.component.dependency.StyleSheet)1 DependencyInfo (com.vaadin.flow.component.internal.ComponentMetaData.DependencyInfo)1 ExtendedClientDetails (com.vaadin.flow.component.page.ExtendedClientDetails)1 Page (com.vaadin.flow.component.page.Page)1 Push (com.vaadin.flow.component.page.Push)1 ElementUtil (com.vaadin.flow.dom.ElementUtil)1 BasicElementStateProvider (com.vaadin.flow.dom.impl.BasicElementStateProvider)1 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)1 AnnotationReader (com.vaadin.flow.internal.AnnotationReader)1 ConstantPool (com.vaadin.flow.internal.ConstantPool)1