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);
}
Aggregations