Search in sources :

Example 1 with UrlParamsChangedEvent

use of io.jmix.ui.navigation.UrlParamsChangedEvent in project jmix by jmix-framework.

the class ParamsNavigationHandler method doHandle.

@Override
public boolean doHandle(NavigationState requestedState, AppUI ui) {
    UrlChangeHandler urlChangeHandler = ui.getUrlChangeHandler();
    if (urlChangeHandler.isEmptyState(requestedState)) {
        return false;
    }
    Screen screen = urlChangeHandler.getActiveScreen();
    if (screen == null) {
        log.debug("Unable to find a screen for state: '{}", requestedState);
        return false;
    }
    Map<String, String> params = requestedState.getParams() != null ? requestedState.getParams() : Collections.emptyMap();
    WindowImpl window = (WindowImpl) screen.getWindow();
    NavigationState resolvedState = window.getResolvedState();
    if (resolvedState == null || params.equals(resolvedState.getParams())) {
        return false;
    }
    NavigationState newState = new NavigationState(resolvedState.getRoot(), resolvedState.getStateMark(), resolvedState.getNestedRoute(), params);
    window.setResolvedState(newState);
    UiControllerUtils.fireEvent(screen, UrlParamsChangedEvent.class, new UrlParamsChangedEvent(screen, params));
    return true;
}
Also used : UrlParamsChangedEvent(io.jmix.ui.navigation.UrlParamsChangedEvent) WindowImpl(io.jmix.ui.component.impl.WindowImpl) Screen(io.jmix.ui.screen.Screen) NavigationState(io.jmix.ui.navigation.NavigationState) UrlChangeHandler(io.jmix.ui.navigation.UrlChangeHandler)

Example 2 with UrlParamsChangedEvent

use of io.jmix.ui.navigation.UrlParamsChangedEvent in project jmix by jmix-framework.

the class RootNavigationHandler method doHandle.

@Override
public boolean doHandle(NavigationState requestedState, AppUI ui) {
    UrlChangeHandler urlChangeHandler = ui.getUrlChangeHandler();
    if (urlChangeHandler.isEmptyState(requestedState)) {
        urlChangeHandler.revertNavigationState();
        return false;
    }
    if (!rootChanged(requestedState, ui)) {
        return false;
    }
    String rootRoute = requestedState.getRoot();
    WindowInfo windowInfo = windowConfig.findWindowInfoByRoute(rootRoute);
    if (windowInfo == null) {
        log.info("No registered screen found for route: '{}'", rootRoute);
        urlChangeHandler.revertNavigationState();
        handle404(rootRoute, ui);
        return true;
    }
    if (urlChangeHandler.shouldRedirect(windowInfo)) {
        urlChangeHandler.redirect(requestedState);
        return true;
    }
    if (!urlChangeHandler.isPermittedToNavigate(requestedState, windowInfo)) {
        return true;
    }
    Screen screen = ui.getScreens().create(windowInfo.getId(), OpenMode.ROOT);
    boolean hasNestedRoute = StringUtils.isNotEmpty(requestedState.getNestedRoute());
    if (!hasNestedRoute && MapUtils.isNotEmpty(requestedState.getParams())) {
        UiControllerUtils.fireEvent(screen, UrlParamsChangedEvent.class, new UrlParamsChangedEvent(screen, requestedState.getParams()));
        ((WindowImpl) screen.getWindow()).setResolvedState(requestedState);
    }
    screen.show();
    return !hasNestedRoute;
}
Also used : UrlParamsChangedEvent(io.jmix.ui.navigation.UrlParamsChangedEvent) WindowImpl(io.jmix.ui.component.impl.WindowImpl) Screen(io.jmix.ui.screen.Screen) NotFoundScreen(io.jmix.ui.app.navigation.notfoundwindow.NotFoundScreen) UrlChangeHandler(io.jmix.ui.navigation.UrlChangeHandler) WindowInfo(io.jmix.ui.WindowInfo)

Example 3 with UrlParamsChangedEvent

use of io.jmix.ui.navigation.UrlParamsChangedEvent in project jmix-docs by Haulmont.

the class EventInfo method onUrlParamsChanged.

// end::select-btn[]
// tag::url-params-changed-event[]
@Subscribe
protected void onUrlParamsChanged(UrlParamsChangedEvent event) {
    // <1>
    String serializedEventId = event.getParams().get("event_id");
    // <2>
    UUID eventId = (UUID) UrlIdSerializer.deserializeId(UUID.class, serializedEventId);
    // <3>
    eventField.setValue(dataManager.load(Event.class).id(eventId).one());
}
Also used : Event(ui.ex1.entity.Event) UrlParamsChangedEvent(io.jmix.ui.navigation.UrlParamsChangedEvent) UUID(java.util.UUID) Subscribe(io.jmix.ui.screen.Subscribe)

Example 4 with UrlParamsChangedEvent

use of io.jmix.ui.navigation.UrlParamsChangedEvent in project jmix-docs by jmix-framework.

the class EventInfo method onUrlParamsChanged.

// end::select-btn[]
// tag::url-params-changed-event[]
@Subscribe
protected void onUrlParamsChanged(UrlParamsChangedEvent event) {
    // <1>
    String serializedEventId = event.getParams().get("event_id");
    // <2>
    UUID eventId = (UUID) UrlIdSerializer.deserializeId(UUID.class, serializedEventId);
    // <3>
    eventField.setValue(dataManager.load(Event.class).id(eventId).one());
}
Also used : Event(ui.ex1.entity.Event) UrlParamsChangedEvent(io.jmix.ui.navigation.UrlParamsChangedEvent) UUID(java.util.UUID) Subscribe(io.jmix.ui.screen.Subscribe)

Aggregations

UrlParamsChangedEvent (io.jmix.ui.navigation.UrlParamsChangedEvent)4 WindowImpl (io.jmix.ui.component.impl.WindowImpl)2 UrlChangeHandler (io.jmix.ui.navigation.UrlChangeHandler)2 Screen (io.jmix.ui.screen.Screen)2 Subscribe (io.jmix.ui.screen.Subscribe)2 UUID (java.util.UUID)2 Event (ui.ex1.entity.Event)2 WindowInfo (io.jmix.ui.WindowInfo)1 NotFoundScreen (io.jmix.ui.app.navigation.notfoundwindow.NotFoundScreen)1 NavigationState (io.jmix.ui.navigation.NavigationState)1