public void obtain() { // tag::obtain[] Optional<ViewNavigator> navigator = ViewNavigator.getCurrent(); // <1> ViewNavigator viewNavigator = ViewNavigator.require(); // <2> // end::obtain[] }
/** * Navigate to the {@link View} identified by given <code>viewName</code> using the same behaviour of * {@link #navigateTo(String, Map)} but rendering the View contents in an application Window, using optional * <code>windowConfiguration</code> to setup Window features. * @param viewName View name * @param windowConfiguration View Window configurator * @return The UI Window in which the View is displayed * @throws ViewNavigationException View with given name cannot be found or other view handling error */ default Window navigateInWindow(String viewName, Consumer<ViewWindowConfigurator> windowConfiguration) throws ViewNavigationException { return navigateInWindow(viewName, windowConfiguration, null); }
@Override public void navigate() throws ViewNavigationException { navigator.navigateTo(viewName, parameters); }
/** * Requires the current {@link ViewNavigator}. If not available using {@link #getCurrent()}, an * {@link IllegalStateException} is thrown. * @return Current ViewNavigator * @throws IllegalStateException ViewNavigator is not available as a {@link Context} resource of from current UI */ static ViewNavigator require() { return getCurrent().orElseThrow(() -> new IllegalStateException( "ViewNavigator is not available as context resource or from current UI")); }
@Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof View) { ViewNavigator navigator = ViewNavigator.require(); if (navigator instanceof ViewConfigurationProvider) { return ViewNavigationUtils.injectContext((ViewConfigurationProvider) navigator, (View) bean); } } return bean; }
public void config2() { // tag::config2[] UI ui = getUI(); ViewNavigator.builder() // .viewDisplay(ui) // .withView("view1", View1.class) // <1> .withView("view2", View2.class) // <2> .defaultViewName("view1") // <3> .buildAndBind(ui); // end::config2[] }
@Override public boolean display(View view, String viewName, Map<String, String> parameters) throws ViewNavigationException { addTab(ViewNavigator.getViewContent(view), viewName, FontAwesome.PUZZLE_PIECE); return true; }
public void nav3() { // tag::nav3[] ViewNavigator navigator = getViewNavigator(); navigator.toView("myView").withParameter("parameter1", "test").withParameter("parameter2", 34.5).navigate(); // <1> navigator.toView("myView").navigateInWindow(); // <2> navigator.toView("myView").navigateInWindow(windowConfig -> { windowConfig.fullWidth(); windowConfig.styleName("my-window-style"); }); // <3> // end::nav3[] }
/** * Navigate to given state using concrete {@link Navigator}. * <p> * Authentication check using {@link Authenticate} annotation is performed before the actual view navigation. * </p> * @param viewConfiguration View configuration. If <code>null</code> the view configuration is obtained using * {@link #getViewConfiguration(Class)} * @param navigationState Navigation state */ private void navigateToState(ViewConfiguration viewConfiguration, String navigationState) { // check authentication if (checkAuthentication(navigationState, viewConfiguration)) { navigator.navigateToState(navigationState); } else { // track view in history to allow backward navigation if (!isVolatile(viewConfiguration)) { trackInHistory(navigationState); } } }
@Override protected void init(VaadinRequest request) { ViewNavigator navigator = ViewNavigator.builder() // <1> .viewDisplay(this) // <2> .addProvider(getViewProvider()) // <3> .defaultViewName("home") // <4> .errorView(MY_ERROR_VIEW) // <5> .errorViewProvider(getErrorViewProvider()) // <6> .maxNavigationHistorySize(1000) // <7> .navigateToDefaultViewWhenViewNotAvailable(true) // <8> .withViewChangeListener(new ViewChangeListener() { // <9> @Override public boolean beforeViewChange(ViewChangeEvent event) { // ... return true; } @Override public void afterViewChange(ViewChangeEvent event) { // ... } }).buildAndBind(this); // <10> }
@Override public Window navigateInWindow(Consumer<ViewWindowConfigurator> windowConfiguration) throws ViewNavigationException { return navigator.navigateInWindow(viewName, windowConfiguration, parameters); }
/** * Navigates to the {@link View} identified by given <code>viewName</code>. * <p> * If the view being deactivated indicates it wants a confirmation for the navigation operation, the user is asked * for the confirmation. * </p> * <p> * Registered {@link ViewChangeListener}s are called upon successful view change. * </p> * @param viewName View name * @throws ViewNavigationException View with given name cannot be found or other view handling error */ default void navigateTo(String viewName) throws ViewNavigationException { navigateTo(viewName, null); }
/** * Navigate to the {@link View} identified by given <code>viewName</code> using the same behaviour of * {@link #navigateTo(String, Map)} but rendering the View contents in an application Window, using default Window * configuration. * @param viewName View name * @param parameters Optional view parameters * @return The UI Window in which the View is displayed * @throws ViewNavigationException View with given name cannot be found or other view handling error */ default Window navigateInWindow(String viewName, Map<String, Object> parameters) throws ViewNavigationException { return navigateInWindow(viewName, null, parameters); }
public void nav1() { // tag::nav1[] ViewNavigator navigator = getViewNavigator(); navigator.navigateTo("myView"); // <1> Map<String, Object> parameters = new HashMap<>(); parameters.put("parameter1", "test"); parameters.put("parameter2", 34.5); navigator.navigateTo("myView", parameters); // <2> // end::nav1[] }
/** * Navigate to the {@link View} identified by given <code>viewName</code> using the same behaviour of * {@link #navigateTo(String, Map)} but rendering the View contents in an application Window, using default Window * configuration. * @param viewName View name * @return The UI Window in which the View is displayed * @throws ViewNavigationException View with given name cannot be found or other view handling error */ default Window navigateInWindow(String viewName) throws ViewNavigationException { return navigateInWindow(viewName, null, null); }
public void nav2() { // tag::nav2[] ViewNavigator navigator = getViewNavigator(); navigator.navigateInWindow("myView"); // <1> Map<String, Object> parameters = new HashMap<>(); parameters.put("parameter1", "test"); parameters.put("parameter2", 34.5); navigator.navigateInWindow("myView", windowConfig -> { windowConfig.fullWidth(); windowConfig.styleName("my-window-style"); }, parameters); // <2> // end::nav2[] }