Class Registrations

java.lang.Object
com.vaadin.swingbridge.surrogates.internal.Registrations

public final class Registrations extends Object
Unified registry of Swing-listener → Vaadin-Registration pairs. Replaces the per-family *Support holders (see SD_vaadin_first_binding: Vaadin-first direct-binding stance).

Each addXListener on a mixin creates the matching Vaadin subscription (on FocusNotifier etc.), calls add(EventListener, Registration) with the Swing listener as the key and the Vaadin Registration as the value, and returns. removeXListener looks up the Swing listener, calls Registration.remove(), and drops the entry. getXListeners() filters the keys by type — LinkedHashMap preserves insertion order, which matches Swing's listener-array order.

One Registrations per component; concurrent multi-threaded access isn't modelled (Vaadin's session lock serialises UI-thread access, which is where these operations happen).

Adding the same listener instance twice collapses to a single entry — the second add(EventListener, Registration) replaces the first registration and removes the stale one. Swing's contract does let the same listener register twice and fire twice; the current pattern treats that as a programming error we'd rather squash than replicate, and it keeps the map semantics clean. Revisit if a migration target relies on double-fire.

  • Method Details

    • of

      public static Registrations of(com.vaadin.flow.component.Component target)
    • add

      public void add(EventListener listener, com.vaadin.flow.shared.Registration registration)
      Register listener with the Vaadin-side registration. If the listener was already registered, the previous registration is removed first so the callback count stays at one.
    • remove

      public void remove(EventListener listener)
      Remove and Registration.remove() the Vaadin registration for listener. No-op when the listener wasn't registered.
    • getListeners

      public <T extends EventListener> T[] getListeners(Class<T> type)
      Return all listeners of type type in registration order. Used by getXListeners() accessors on the mixins — getFocusListeners() passes FocusListener.class, getHierarchyListeners() passes HierarchyListener.class, and so on.
    • size

      public int size()
      Test/diagnostic accessor — total registration count.