]> source.dussan.org Git - vaadin-framework.git/commitdiff
Change View.navigateTo(String) to View.enter(ViewChangeEvent) (#9055, #9056)
authorJohannes Dahlström <johannesd@vaadin.com>
Fri, 31 Aug 2012 10:57:37 +0000 (13:57 +0300)
committerJohannes Dahlström <johannesd@vaadin.com>
Fri, 31 Aug 2012 11:03:04 +0000 (14:03 +0300)
server/src/com/vaadin/navigator/Navigator.java
server/src/com/vaadin/navigator/View.java
server/tests/src/com/vaadin/tests/server/navigator/ClassBasedViewProviderTest.java
server/tests/src/com/vaadin/tests/server/navigator/NavigatorTest.java

index 8332c0e45e1fd85cbf2486acab95db7e3c122a9d..bda422379cc69760000bc3d88ae04b90a36380aa 100644 (file)
@@ -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) {
index ffe9cfd0a9ea5e8a282bda07914e4754d8163944..53dbf013198e06353ebf2a81e40036352ea293d5 100644 (file)
@@ -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 <code>this</code>.
      * 
-     * @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
index 5db0df4280546b3dc795588b5c7f06d8061e3448..2b9d0e533d3aa5032f25039dff8b39fcd0594dff 100644 (file)
@@ -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();
         }
 
     }
index ca060a4651b1ca60ca6f59abaa14e92334edc103..fa48e4bff61c8a50a69b9af1b741a224e746748e 100644 (file)
@@ -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);