From: Johannes Dahlström Date: Fri, 31 Aug 2012 10:57:37 +0000 (+0300) Subject: Change View.navigateTo(String) to View.enter(ViewChangeEvent) (#9055, #9056) X-Git-Tag: 7.0.0.beta1~209^2~9 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=61a1218d388b85b496e0fd98f2a5c5226ab4f83d;p=vaadin-framework.git Change View.navigateTo(String) to View.enter(ViewChangeEvent) (#9055, #9056) --- diff --git a/server/src/com/vaadin/navigator/Navigator.java b/server/src/com/vaadin/navigator/Navigator.java index 8332c0e45e..bda422379c 100644 --- a/server/src/com/vaadin/navigator/Navigator.java +++ b/server/src/com/vaadin/navigator/Navigator.java @@ -67,7 +67,7 @@ public class Navigator implements Serializable { } @Override - public void navigateTo(String parameters) { + public void enter(ViewChangeEvent event) { // nothing to do } } @@ -483,7 +483,7 @@ public class Navigator implements Serializable { } } - view.navigateTo(parameters); + view.enter(event); currentView = view; if (display != null) { diff --git a/server/src/com/vaadin/navigator/View.java b/server/src/com/vaadin/navigator/View.java index ffe9cfd0a9..53dbf01319 100644 --- a/server/src/com/vaadin/navigator/View.java +++ b/server/src/com/vaadin/navigator/View.java @@ -18,6 +18,7 @@ package com.vaadin.navigator; import java.io.Serializable; +import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; import com.vaadin.ui.Component; /** @@ -34,13 +35,15 @@ public interface View extends Serializable { /** * This view is navigated to. * - * This method is always called before the view is shown on screen. If there - * is any additional id to data what should be shown in the view, it is also - * optionally passed as parameter. + * This method is always called before the view is shown on screen. + * {@link ViewChangeEvent#getParameters() event.getParameters()} may contain + * extra parameters relevant to the view. + * + * @param event + * ViewChangeEvent representing the view change that is + * occurring. {@link ViewChangeEvent#getNewView() + * event.getNewView()} returns this. * - * @param parameters - * parameters to the view or empty string if none given. This is - * the string that appears e.g. in URI after "viewname/" */ - public void navigateTo(String parameters); + public void enter(ViewChangeEvent event); } \ No newline at end of file diff --git a/server/tests/src/com/vaadin/tests/server/navigator/ClassBasedViewProviderTest.java b/server/tests/src/com/vaadin/tests/server/navigator/ClassBasedViewProviderTest.java index 5db0df4280..2b9d0e533d 100644 --- a/server/tests/src/com/vaadin/tests/server/navigator/ClassBasedViewProviderTest.java +++ b/server/tests/src/com/vaadin/tests/server/navigator/ClassBasedViewProviderTest.java @@ -20,6 +20,7 @@ import junit.framework.TestCase; import com.vaadin.navigator.Navigator.ClassBasedViewProvider; import com.vaadin.navigator.View; +import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; import com.vaadin.ui.Label; public class ClassBasedViewProviderTest extends TestCase { @@ -28,8 +29,8 @@ public class ClassBasedViewProviderTest extends TestCase { public String parameters = null; @Override - public void navigateTo(String parameters) { - this.parameters = parameters; + public void enter(ViewChangeEvent event) { + parameters = event.getParameters(); } } 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 ca060a4651..fa48e4bff6 100644 --- a/server/tests/src/com/vaadin/tests/server/navigator/NavigatorTest.java +++ b/server/tests/src/com/vaadin/tests/server/navigator/NavigatorTest.java @@ -21,6 +21,7 @@ import java.util.LinkedList; import junit.framework.TestCase; import org.easymock.EasyMock; +import org.easymock.IArgumentMatcher; import org.easymock.IMocksControl; import com.vaadin.navigator.NavigationStateManager; @@ -168,6 +169,23 @@ public class NavigatorTest extends TestCase { } } + public static ViewChangeEvent eventParametersEqual(final String expected) { + EasyMock.reportMatcher(new IArgumentMatcher() { + @Override + public void appendTo(StringBuffer buffer) { + buffer.append("paramsIs(\"" + expected + "\")"); + } + + @Override + public boolean matches(Object actual) { + return actual instanceof ViewChangeEvent + && expected.equals(((ViewChangeEvent) actual) + .getParameters()); + } + }); + return null; + } + public void testBasicNavigation() { IMocksControl control = EasyMock.createControl(); NavigationStateManager manager = control @@ -181,14 +199,14 @@ public class NavigatorTest extends TestCase { EasyMock.expect(provider.getViewName("test1")).andReturn("test1"); EasyMock.expect(provider.getView("test1")).andReturn(view1); EasyMock.expect(manager.getState()).andReturn(""); - view1.navigateTo(""); + view1.enter(eventParametersEqual("")); display.showView(view1); manager.setState("test1"); EasyMock.expect(provider.getViewName("test2/")).andReturn("test2"); EasyMock.expect(provider.getView("test2")).andReturn(view2); EasyMock.expect(manager.getState()).andReturn("view1"); - view2.navigateTo(""); + view2.enter(eventParametersEqual("")); display.showView(view2); manager.setState("test2"); @@ -196,7 +214,7 @@ public class NavigatorTest extends TestCase { .andReturn("test1"); EasyMock.expect(provider.getView("test1")).andReturn(view1); EasyMock.expect(manager.getState()).andReturn("view2"); - view1.navigateTo("params"); + view1.enter(eventParametersEqual("params")); display.showView(view1); manager.setState("test1/params"); @@ -224,14 +242,14 @@ public class NavigatorTest extends TestCase { EasyMock.expect(provider.getViewName("test2")).andReturn("test2"); EasyMock.expect(provider.getView("test2")).andReturn(view2); EasyMock.expect(manager.getState()).andReturn("view1"); - view2.navigateTo(""); + view2.enter(eventParametersEqual("")); display.showView(view2); manager.setState("test2"); EasyMock.expect(provider.getViewName("")).andReturn("test1"); EasyMock.expect(provider.getView("test1")).andReturn(view1); EasyMock.expect(manager.getState()).andReturn(""); - view1.navigateTo(""); + view1.enter(eventParametersEqual("")); display.showView(view1); manager.setState("test1"); @@ -239,7 +257,7 @@ public class NavigatorTest extends TestCase { .andReturn("test1"); EasyMock.expect(provider.getView("test1")).andReturn(view1); EasyMock.expect(manager.getState()).andReturn("view2"); - view1.navigateTo("params"); + view1.enter(eventParametersEqual("params")); display.showView(view1); manager.setState("test1/params"); @@ -274,7 +292,7 @@ public class NavigatorTest extends TestCase { "test1", ""); listener.addExpectedIsViewChangeAllowed(event1, true); EasyMock.expect(manager.getState()).andReturn(""); - view1.navigateTo(""); + view1.enter(eventParametersEqual("")); display.showView(view1); manager.setState("test1"); listener.addExpectedNavigatorViewChange(event1); @@ -285,7 +303,7 @@ public class NavigatorTest extends TestCase { "test2", ""); listener.addExpectedIsViewChangeAllowed(event2, true); EasyMock.expect(manager.getState()).andReturn("view1"); - view2.navigateTo(""); + view2.enter(eventParametersEqual("")); display.showView(view2); manager.setState("test2"); listener.addExpectedNavigatorViewChange(event2); @@ -343,7 +361,7 @@ public class NavigatorTest extends TestCase { "test1", "bar"); listener1.addExpectedIsViewChangeAllowed(event3, true); listener2.addExpectedIsViewChangeAllowed(event3, true); - view1.navigateTo("bar"); + view1.enter(EasyMock.isA(ViewChangeEvent.class)); display.showView(view1); manager.setState("test1/bar"); listener1.addExpectedNavigatorViewChange(event3); @@ -357,7 +375,7 @@ public class NavigatorTest extends TestCase { "test2", ""); listener1.addExpectedIsViewChangeAllowed(event4, true); listener2.addExpectedIsViewChangeAllowed(event4, true); - view2.navigateTo(""); + view2.enter(EasyMock.isA(ViewChangeEvent.class)); display.showView(view2); manager.setState("test2"); listener1.addExpectedNavigatorViewChange(event4);