fi.evolver.ai.vaadin.AbstractAppConfigurator Maven / Gradle / Ivy
package fi.evolver.ai.vaadin;
import java.io.Serial;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.vaadin.flow.router.RouteConfiguration;
import com.vaadin.flow.router.RouterLayout;
import com.vaadin.flow.server.ErrorHandler;
import com.vaadin.flow.server.ServiceInitEvent;
import com.vaadin.flow.server.VaadinServiceInitListener;
import com.vaadin.flow.server.VaadinSession;
import fi.evolver.ai.vaadin.view.AdminView;
import fi.evolver.ai.vaadin.view.ProfileView;
public abstract class AbstractAppConfigurator implements VaadinServiceInitListener {
@Serial
private static final long serialVersionUID = 1L;
private static final Logger LOG = LoggerFactory.getLogger(AbstractAppConfigurator.class);
protected abstract Class extends RouterLayout> getLayout();
protected ErrorHandler getErrorHandler() {
return null;
}
@Override
public void serviceInit(ServiceInitEvent event) {
event.getSource().addSessionInitListener(initEvent -> {
LOG.debug("Setting up evolver-ai-vaadin routes");
RouteConfiguration.forSessionScope().setRoute("profile", ProfileView.class, List.of(getLayout()));
RouteConfiguration.forSessionScope().setRoute("admin", AdminView.class, List.of(getLayout()));
ErrorHandler errorHandler = getErrorHandler();
if (errorHandler != null) {
LOG.debug("Attaching custom error handler");
VaadinSession.getCurrent().setErrorHandler(errorHandler);
}
});
}
}