use of com.vaadin.flow.router.RouteConfiguration in project flow by vaadin.
the class UidlWriterTest method initializeUIForDependenciesTest.
private UI initializeUIForDependenciesTest(UI ui) throws Exception {
mocks = new MockServletServiceSessionSetup();
VaadinServletContext context = (VaadinServletContext) mocks.getService().getContext();
Lookup lookup = context.getAttribute(Lookup.class);
Mockito.when(lookup.lookup(RoutePathProvider.class)).thenReturn(new RoutePathProviderImpl());
VaadinSession session = mocks.getSession();
session.lock();
ui.getInternals().setSession(session);
RouteConfiguration routeConfiguration = RouteConfiguration.forRegistry(ui.getInternals().getRouter().getRegistry());
routeConfiguration.update(() -> {
routeConfiguration.getHandledRegistry().clean();
routeConfiguration.setAnnotatedRoute(BaseClass.class);
});
for (String type : new String[] { "html", "js", "css" }) {
mocks.getServlet().addServletContextResource("inline." + type, "inline." + type);
}
HttpServletRequest servletRequestMock = mock(HttpServletRequest.class);
VaadinServletRequest vaadinRequestMock = mock(VaadinServletRequest.class);
when(vaadinRequestMock.getHttpServletRequest()).thenReturn(servletRequestMock);
ui.doInit(vaadinRequestMock, 1);
ui.getInternals().getRouter().initializeUI(ui, BootstrapHandlerTest.requestToLocation(vaadinRequestMock));
return ui;
}
use of com.vaadin.flow.router.RouteConfiguration in project flow by vaadin.
the class RouteUtil method updateRouteRegistry.
/**
* Updates route registry as necessary when classes have been added /
* modified / deleted.
*
* @param registry
* route registry
* @param addedClasses
* added classes
* @param modifiedClasses
* modified classes
* @param deletedClasses
* deleted classes
*/
public static void updateRouteRegistry(RouteRegistry registry, Set<Class<?>> addedClasses, Set<Class<?>> modifiedClasses, Set<Class<?>> deletedClasses) {
RouteConfiguration routeConf = RouteConfiguration.forRegistry(registry);
Logger logger = LoggerFactory.getLogger(RouteUtil.class);
registry.update(() -> {
// remove deleted classes and classes that lost the annotation from
// registry
Stream.concat(deletedClasses.stream(), modifiedClasses.stream().filter(clazz -> !clazz.isAnnotationPresent(Route.class))).filter(Component.class::isAssignableFrom).forEach(clazz -> {
Class<? extends Component> componentClass = (Class<? extends Component>) clazz;
logger.debug("Removing route to {}", componentClass);
routeConf.removeRoute(componentClass);
});
// add new routes to registry
Stream.concat(addedClasses.stream(), modifiedClasses.stream()).distinct().filter(Component.class::isAssignableFrom).filter(clazz -> clazz.isAnnotationPresent(Route.class)).forEach(clazz -> {
Class<? extends Component> componentClass = (Class<? extends Component>) clazz;
logger.debug("Updating route {} to {}", componentClass.getAnnotation(Route.class).value(), clazz);
routeConf.removeRoute(componentClass);
routeConf.setAnnotatedRoute(componentClass);
});
});
}
use of com.vaadin.flow.router.RouteConfiguration in project flow by vaadin.
the class CustomInitListener method serviceInit.
@Override
public void serviceInit(ServiceInitEvent event) {
final CustomRouteRegistry registry = CustomRouteRegistry.getInstance(event.getSource().getContext());
RouteConfiguration configuration = RouteConfiguration.forRegistry(registry);
configuration.setRoute("", CustomRoute.class);
}
use of com.vaadin.flow.router.RouteConfiguration in project flow by vaadin.
the class TestingServiceInitListener method serviceInit.
@Override
public void serviceInit(ServiceInitEvent event) {
event.getSource().addUIInitListener(this::handleUIInit);
initCount.incrementAndGet();
RouteConfiguration configuration = RouteConfiguration.forApplicationScope();
// lock registry from any other updates to get registrations correctly.
configuration.getHandledRegistry().update(() -> {
if (!configuration.isPathRegistered(DYNAMICALLY_REGISTERED_ROUTE)) {
configuration.setRoute(DYNAMICALLY_REGISTERED_ROUTE, DynamicallyRegisteredRoute.class);
}
});
event.addRequestHandler((session, request, response) -> {
requestCount.incrementAndGet();
return false;
});
}
use of com.vaadin.flow.router.RouteConfiguration in project flow by vaadin.
the class UI method navigate.
/**
* Updates this UI to show the view corresponding to the given navigation
* target with the specified parameters. The parameters needs to comply with
* the ones defined in one of the {@link com.vaadin.flow.router.Route} or
* {@link com.vaadin.flow.router.RouteAlias} annotating the navigationTarget
* and with any {@link com.vaadin.flow.router.RoutePrefix} annotating the
* parent layouts of the navigationTarget.
* <p>
* Besides the navigation to the {@code location} this method also updates
* the browser location (and page history).
*
* @param navigationTarget
* navigation target to navigate to.
* @param parameters
* parameters to pass to view.
* @throws IllegalArgumentException
* if navigationTarget is a {@link HasUrlParameter} with a
* mandatory parameter, but parameters argument doesn't provide
* {@link HasUrlParameterFormat#PARAMETER_NAME} parameter.
* @throws NotFoundException
* in case there is no route defined for the given
* navigationTarget matching the parameters.
*/
public void navigate(Class<? extends Component> navigationTarget, RouteParameters parameters) {
RouteConfiguration configuration = RouteConfiguration.forRegistry(getInternals().getRouter().getRegistry());
navigate(configuration.getUrl(navigationTarget, parameters));
}
Aggregations