com.vaadin.event.UIEvents Maven / Gradle / Ivy
/*
* 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.event;
import java.io.Serializable;
import java.lang.reflect.Method;
import com.vaadin.shared.Registration;
import com.vaadin.ui.Component;
import com.vaadin.ui.UI;
import com.vaadin.util.ReflectTools;
/**
* A class that contains events, listeners and handlers specific to the
* {@link UI} class.
*
* @since 7.2
* @author Vaadin Ltd
*/
public interface UIEvents {
/**
* A {@link PollListener} receives and handles {@link PollEvent PollEvents}
* fired by {@link PollNotifier PollNotifiers}.
*
* @since 7.2
* @author Vaadin Ltd
*/
@FunctionalInterface
public interface PollListener extends SerializableEventListener {
public static final Method POLL_METHOD = ReflectTools
.findMethod(PollListener.class, "poll", PollEvent.class);
/**
* A poll request has been received by the server.
*
* @param event
* poll event
*/
public void poll(PollEvent event);
}
/**
* An event that is fired whenever a client polls the server for
* asynchronous UI updates.
*
* @since 7.2
* @author Vaadin Ltd
*/
public static class PollEvent extends Component.Event {
public PollEvent(UI ui) {
super(ui);
}
/**
* Get the {@link UI} instance that received the poll request.
*
* @return the {@link UI} that received the poll request. Never
* null
.
*/
public UI getUI() {
/*
* This cast is safe to make, since this class' constructor
* constrains the source to be a UI instance.
*/
return (UI) getComponent();
}
}
/**
* The interface for adding and removing {@link PollEvent} listeners.
*
* By implementing this interface, a class publicly announces that it is
* able to send {@link PollEvent PollEvents} whenever the client sends a
* periodic poll message to the client, to check for asynchronous
* server-side modifications.
*
* @since 7.2
* @see UI#setPollInterval(int)
*/
public interface PollNotifier extends Serializable {
/**
* Add a poll listener.
*
* The listener is called whenever the client polls the server for
* asynchronous UI updates.
*
* @see UI#setPollInterval(int)
* @see #removePollListener(PollListener)
* @see Registration
* @param listener
* the {@link PollListener} to add, not null
* @return a registration object for removing the listener
* @since 8.0
*/
public Registration addPollListener(PollListener listener);
/**
* Remove a poll listener.
*
* @see #addPollListener(PollListener)
* @param listener
* the listener to be removed
*
* @deprecated As of 8.0, replaced by {@link Registration#remove()} in
* the registration object returned from
* {@link #addPollListener(PollListener)}.
*/
@Deprecated
public void removePollListener(PollListener listener);
}
}