summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-11-15 09:15:44 +0200
committerArtur Signell <artur@vaadin.com>2012-11-15 09:15:44 +0200
commite54ff59fbe6a5452b469a355176351cd710663d1 (patch)
tree66832e17048e7019e96b1a96377f1a1ff1c88a53 /server
parent49961b55b83af764364fb4b19bff4c3a7e575eb9 (diff)
downloadvaadin-framework-e54ff59fbe6a5452b469a355176351cd710663d1.tar.gz
vaadin-framework-e54ff59fbe6a5452b469a355176351cd710663d1.zip
Made it possible again to use Navigator with UI/Panel/Window (#10211)7.0.0.beta9
Change-Id: I4b9c6c5eecb7b6d18e1ef7afcb38889bd7fec8aa
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/navigator/Navigator.java59
1 files changed, 59 insertions, 0 deletions
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;
/**
@@ -181,6 +182,39 @@ public class Navigator implements Serializable {
}
/**
+ * A ViewDisplay that replaces the contents of a
+ * {@link SingleComponentContainer} with the active {@link View}.
+ * <p>
+ * 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.
*
@@ -353,6 +387,31 @@ public class Navigator implements Serializable {
/**
* 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.
+ * <p>
+ * In case the container is not on the current page, use another
+ * {@link Navigator#Navigator(Page, ViewDisplay)} with an explicitly created
+ * {@link SingleComponentContainerViewDisplay}.
+ * <p>
+ * Views must implement {@link Component} when using this constructor.
+ * <p>
+ * 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.
* <p>
* After all {@link View}s and {@link ViewProvider}s have been registered,