From: Artur Signell Date: Thu, 15 Nov 2012 07:15:44 +0000 (+0200) Subject: Made it possible again to use Navigator with UI/Panel/Window (#10211) X-Git-Tag: 7.0.0.beta9^0 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e54ff59fbe6a5452b469a355176351cd710663d1;p=vaadin-framework.git Made it possible again to use Navigator with UI/Panel/Window (#10211) Change-Id: I4b9c6c5eecb7b6d18e1ef7afcb38889bd7fec8aa --- diff --git a/server/src/com/vaadin/navigator/Navigator.java b/server/src/com/vaadin/navigator/Navigator.java index edc101bb44..acfaf45516 100644 --- a/server/src/com/vaadin/navigator/Navigator.java +++ b/server/src/com/vaadin/navigator/Navigator.java @@ -28,6 +28,7 @@ import com.vaadin.server.Page.UriFragmentChangedListener; import com.vaadin.ui.Component; import com.vaadin.ui.ComponentContainer; import com.vaadin.ui.CssLayout; +import com.vaadin.ui.SingleComponentContainer; import com.vaadin.ui.UI; /** @@ -180,6 +181,39 @@ public class Navigator implements Serializable { } } + /** + * A ViewDisplay that replaces the contents of a + * {@link SingleComponentContainer} with the active {@link View}. + *

+ * This display only supports views that are {@link Component}s themselves. + * Attempting to display a view that is not a component causes an exception + * to be thrown. + */ + public static class SingleComponentContainerViewDisplay implements + ViewDisplay { + + private final SingleComponentContainer container; + + /** + * Create new {@link ViewDisplay} that updates a + * {@link SingleComponentContainer} to show the view. + */ + public SingleComponentContainerViewDisplay( + SingleComponentContainer container) { + this.container = container; + } + + @Override + public void showView(View view) { + if (view instanceof Component) { + container.setContent((Component) view); + } else { + throw new IllegalArgumentException("View is not a component: " + + view); + } + } + } + /** * A ViewProvider which supports mapping a single view name to a single * pre-initialized view instance. @@ -351,6 +385,31 @@ public class Navigator implements Serializable { this(ui, new ComponentContainerViewDisplay(container)); } + /** + * Creates a navigator that is tracking the active view using URI fragments + * of the current {@link Page} and replacing the contents of a + * {@link SingleComponentContainer} with the active view. + *

+ * In case the container is not on the current page, use another + * {@link Navigator#Navigator(Page, ViewDisplay)} with an explicitly created + * {@link SingleComponentContainerViewDisplay}. + *

+ * Views must implement {@link Component} when using this constructor. + *

+ * After all {@link View}s and {@link ViewProvider}s have been registered, + * the application should trigger navigation to the current fragment using + * {@link #navigate()}. + * + * @param ui + * The UI to which this Navigator is attached. + * @param container + * The SingleComponentContainer whose contents should be replaced + * with the active view on view change + */ + public Navigator(UI ui, SingleComponentContainer container) { + this(ui, new SingleComponentContainerViewDisplay(container)); + } + /** * Creates a navigator that is tracking the active view using URI fragments * of the Page containing the given UI.