aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Dahlström <johannesd@vaadin.com>2012-09-19 17:22:49 +0300
committerJohannes Dahlström <johannesd@vaadin.com>2012-09-19 17:22:49 +0300
commit6949ba97ab5d79b23903475ab92a2f0e950bc3b2 (patch)
tree257d94b2aef199990e08ac568f06beb6c95a9b66
parentc4323e999fcbc05e04388dd37374487cb9f72634 (diff)
downloadvaadin-framework-6949ba97ab5d79b23903475ab92a2f0e950bc3b2.tar.gz
vaadin-framework-6949ba97ab5d79b23903475ab92a2f0e950bc3b2.zip
Bind Navigator to a UI (#9550)
-rw-r--r--server/src/com/vaadin/navigator/Navigator.java49
-rw-r--r--server/src/com/vaadin/ui/UI.java22
-rw-r--r--server/tests/src/com/vaadin/tests/server/navigator/NavigatorTest.java16
-rw-r--r--uitest/src/com/vaadin/tests/navigator/NavigatorTest.java5
4 files changed, 65 insertions, 27 deletions
diff --git a/server/src/com/vaadin/navigator/Navigator.java b/server/src/com/vaadin/navigator/Navigator.java
index d3098903c5..257dfa208f 100644
--- a/server/src/com/vaadin/navigator/Navigator.java
+++ b/server/src/com/vaadin/navigator/Navigator.java
@@ -29,6 +29,7 @@ import com.vaadin.ui.Component;
import com.vaadin.ui.ComponentContainer;
import com.vaadin.ui.CssLayout;
import com.vaadin.ui.CustomComponent;
+import com.vaadin.ui.UI;
/**
* A navigator utility that allows switching of views in a part of an
@@ -124,7 +125,7 @@ public class Navigator implements Serializable {
@Override
public void fragmentChanged(FragmentChangedEvent event) {
- UriFragmentManager.this.navigator.navigateTo(getState());
+ navigator.navigateTo(getState());
}
}
@@ -331,6 +332,7 @@ public class Navigator implements Serializable {
}
}
+ private final UI ui;
private final NavigationStateManager stateManager;
private final ViewDisplay display;
private View currentView = null;
@@ -354,30 +356,34 @@ public class Navigator implements Serializable {
* the application should trigger navigation to the current fragment using
* {@link #navigate()}.
*
+ * @param ui
+ * The UI to which this Navigator is attached.
* @param container
- * ComponentContainer whose contents should be replaced with the
- * active view on view change
+ * The ComponentContainer whose contents should be replaced with
+ * the active view on view change
*/
- public Navigator(ComponentContainer container) {
- display = new ComponentContainerViewDisplay(container);
- stateManager = new UriFragmentManager(Page.getCurrent(), this);
+ public Navigator(UI ui, ComponentContainer container) {
+ this(ui, new ComponentContainerViewDisplay(container));
}
/**
- * Creates a navigator that is tracking the active view using URI fragments.
+ * 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,
* the application should trigger navigation to the current fragment using
* {@link #navigate()}.
*
- * @param page
- * whose URI fragments are used
+ * @param ui
+ * The UI to which this Navigator is attached.
* @param display
- * where to display the views
+ * The ViewDisplay used to display the views.
*/
- public Navigator(Page page, ViewDisplay display) {
+ public Navigator(UI ui, ViewDisplay display) {
+ this.ui = ui;
+ this.ui.setNavigator(this);
this.display = display;
- stateManager = new UriFragmentManager(page, this);
+ stateManager = new UriFragmentManager(ui.getPage(), this);
}
/**
@@ -391,14 +397,19 @@ public class Navigator implements Serializable {
* the application should trigger navigation to the current fragment using
* {@link #navigate()}.
*
+ * @param ui
+ * The UI to which this Navigator is attached.
* @param stateManager
- * {@link NavigationStateManager} keeping track of the active
- * view and enabling bookmarking and direct navigation
+ * The NavigationStateManager keeping track of the active view
+ * and enabling bookmarking and direct navigation
* @param display
- * {@ViewDisplay} used to display the views handled
- * by this navigator
+ * The ViewDisplay used to display the views handled by this
+ * navigator
*/
- public Navigator(NavigationStateManager stateManager, ViewDisplay display) {
+ public Navigator(UI ui, NavigationStateManager stateManager,
+ ViewDisplay display) {
+ this.ui = ui;
+ this.ui.setNavigator(this);
this.display = display;
this.stateManager = stateManager;
}
@@ -547,6 +558,10 @@ public class Navigator implements Serializable {
return display;
}
+ public UI getUI() {
+ return ui;
+ }
+
/**
* Fires an event after the current view has changed.
* <p>
diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java
index dd5bcd231f..b15a83cdce 100644
--- a/server/src/com/vaadin/ui/UI.java
+++ b/server/src/com/vaadin/ui/UI.java
@@ -33,6 +33,7 @@ import com.vaadin.event.Action.Handler;
import com.vaadin.event.ActionManager;
import com.vaadin.event.MouseEvents.ClickEvent;
import com.vaadin.event.MouseEvents.ClickListener;
+import com.vaadin.navigator.Navigator;
import com.vaadin.server.LegacyComponent;
import com.vaadin.server.Page;
import com.vaadin.server.Page.BrowserWindowResizeEvent;
@@ -845,6 +846,8 @@ public abstract class UI extends AbstractComponentContainer implements
private String theme;
+ private Navigator navigator;
+
/**
* This method is used by Component.Focusable objects to request focus to
* themselves. Focus renders must be handled at window level (instead of
@@ -1188,6 +1191,25 @@ public abstract class UI extends AbstractComponentContainer implements
}
/**
+ * Returns the navigator attached to this UI or null if there is no
+ * navigator.
+ *
+ * @return
+ */
+ public Navigator getNavigator() {
+ return navigator;
+ }
+
+ /**
+ * For internal use only.
+ *
+ * @param navigator
+ */
+ public void setNavigator(Navigator navigator) {
+ this.navigator = navigator;
+ }
+
+ /**
* Setting the caption of a UI is not supported. To set the title of the
* HTML page, use Page.setTitle
*
diff --git a/server/tests/src/com/vaadin/tests/server/navigator/NavigatorTest.java b/server/tests/src/com/vaadin/tests/server/navigator/NavigatorTest.java
index a78c76cb70..f97c2fdeb5 100644
--- a/server/tests/src/com/vaadin/tests/server/navigator/NavigatorTest.java
+++ b/server/tests/src/com/vaadin/tests/server/navigator/NavigatorTest.java
@@ -73,7 +73,7 @@ public class NavigatorTest extends TestCase {
public static class TestNavigator extends Navigator {
public TestNavigator() {
- super(new NullFragmentManager(), new TestDisplay());
+ super(null, new NullFragmentManager(), new TestDisplay());
}
public View getView(String viewAndParameters) {
@@ -221,7 +221,7 @@ public class NavigatorTest extends TestCase {
control.replay();
// create and test navigator
- Navigator navigator = new Navigator(manager, display);
+ Navigator navigator = new Navigator(null, manager, display);
navigator.addProvider(provider);
navigator.navigateTo("test1");
@@ -264,7 +264,7 @@ public class NavigatorTest extends TestCase {
control.replay();
// create and test navigator
- Navigator navigator = new Navigator(manager, display);
+ Navigator navigator = new Navigator(null, manager, display);
navigator.addProvider(provider);
navigator.navigateTo("test2");
@@ -283,7 +283,7 @@ public class NavigatorTest extends TestCase {
ViewChangeTestListener listener = new ViewChangeTestListener();
// create navigator to test
- Navigator navigator = new Navigator(manager, display);
+ Navigator navigator = new Navigator(null, manager, display);
// prepare mocks: what to expect
EasyMock.expect(provider.getViewName("test1")).andReturn("test1");
@@ -333,7 +333,7 @@ public class NavigatorTest extends TestCase {
ViewChangeTestListener listener1 = new ViewChangeTestListener();
ViewChangeTestListener listener2 = new ViewChangeTestListener();
- Navigator navigator = new Navigator(manager, display);
+ Navigator navigator = new Navigator(null, manager, display);
// prepare mocks: what to expect
// first listener blocks first view change
@@ -467,7 +467,7 @@ public class NavigatorTest extends TestCase {
}
public void testAddViewWithNullName() throws Exception {
- Navigator navigator = new Navigator(new NullFragmentManager(),
+ Navigator navigator = new Navigator(null, new NullFragmentManager(),
new NullDisplay());
try {
@@ -483,7 +483,7 @@ public class NavigatorTest extends TestCase {
}
public void testAddViewWithNullInstance() throws Exception {
- Navigator navigator = new Navigator(new NullFragmentManager(),
+ Navigator navigator = new Navigator(null, new NullFragmentManager(),
new NullDisplay());
try {
@@ -494,7 +494,7 @@ public class NavigatorTest extends TestCase {
}
public void testAddViewWithNullClass() throws Exception {
- Navigator navigator = new Navigator(new NullFragmentManager(),
+ Navigator navigator = new Navigator(null, new NullFragmentManager(),
new NullDisplay());
try {
diff --git a/uitest/src/com/vaadin/tests/navigator/NavigatorTest.java b/uitest/src/com/vaadin/tests/navigator/NavigatorTest.java
index ef9130a2b1..4986bd21e6 100644
--- a/uitest/src/com/vaadin/tests/navigator/NavigatorTest.java
+++ b/uitest/src/com/vaadin/tests/navigator/NavigatorTest.java
@@ -104,7 +104,7 @@ public class NavigatorTest extends UI {
@Override
protected void init(WrappedRequest req) {
try {
- navi = new Navigator(naviLayout);
+ navi = new Navigator(this, naviLayout);
navi.addView("", new DefaultView());
@@ -113,7 +113,8 @@ public class NavigatorTest extends UI {
navi.addView("forbidden", new ForbiddenView());
navi.addViewChangeListener(new NaviListener());
- // navi.navigate();
+
+ navi.navigate();
addComponent(new NaviButton("list"));
addComponent(new NaviButton("edit"));