]> source.dussan.org Git - vaadin-framework.git/commitdiff
Rename FragmentManager to NavigationStateManager (#9367)
authorJohannes Dahlström <johannesd@vaadin.com>
Thu, 30 Aug 2012 13:24:18 +0000 (16:24 +0300)
committerJohannes Dahlström <johannesd@vaadin.com>
Fri, 31 Aug 2012 08:06:45 +0000 (11:06 +0300)
server/src/com/vaadin/navigator/FragmentManager.java [deleted file]
server/src/com/vaadin/navigator/NavigationStateManager.java [new file with mode: 0644]
server/src/com/vaadin/navigator/Navigator.java
server/tests/src/com/vaadin/tests/server/navigator/NavigatorTest.java
server/tests/src/com/vaadin/tests/server/navigator/UriFragmentManagerTest.java

diff --git a/server/src/com/vaadin/navigator/FragmentManager.java b/server/src/com/vaadin/navigator/FragmentManager.java
deleted file mode 100644 (file)
index a42456a..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2011 Vaadin Ltd.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.navigator;
-
-import java.io.Serializable;
-
-/**
- * Fragment manager that handles interaction between Navigator and URI fragments
- * or other similar view identification and bookmarking system.
- * 
- * Alternative implementations can be created for HTML5 pushState, for portlet
- * URL navigation and other similar systems.
- * 
- * This interface is mostly for internal use by {@link Navigator}.
- * 
- * @author Vaadin Ltd
- * @since 7.0
- */
-public interface FragmentManager extends Serializable {
-    /**
-     * Return the current fragment (location string) including view name and any
-     * optional parameters.
-     * 
-     * @return current view and parameter string, not null
-     */
-    public String getFragment();
-
-    /**
-     * Set the current fragment (location string) in the application URL or
-     * similar location, including view name and any optional parameters.
-     * 
-     * @param fragment
-     *            new view and parameter string, not null
-     */
-    public void setFragment(String fragment);
-}
\ No newline at end of file
diff --git a/server/src/com/vaadin/navigator/NavigationStateManager.java b/server/src/com/vaadin/navigator/NavigationStateManager.java
new file mode 100644 (file)
index 0000000..cbbeb59
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2011 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.navigator;
+
+import java.io.Serializable;
+
+/**
+ * An interface for handling interaction between Navigator and the browser
+ * location URI or other similar view identification and bookmarking system. The
+ * state is limited to a single string because in the usual cases it forms a
+ * part of a URI.
+ * <p>
+ * Different implementations can be created for hashbang URIs, HTML5 pushState,
+ * portlet URL navigation and other similar systems.
+ * <p>
+ * This interface is mostly for internal use by {@link Navigator}.
+ * 
+ * @author Vaadin Ltd
+ * @since 7.0
+ */
+public interface NavigationStateManager extends Serializable {
+    /**
+     * Returns the current navigation state including view name and any optional
+     * parameters.
+     * 
+     * @return current view and parameter string, not null
+     */
+    public String getState();
+
+    /**
+     * Set the current navigation state in the location URI or similar location,
+     * including view name and any optional parameters.
+     * 
+     * @param fragment
+     *            new view and parameter string, not null
+     */
+    public void setState(String state);
+}
\ No newline at end of file
index cef27c221d7d99e4a8cacc4285ef996e0e09b336..40805e2c12229a5a2d0e4bd384d83acfd6e2fab0 100644 (file)
@@ -79,7 +79,7 @@ public class Navigator implements Serializable {
      * This class is mostly for internal use by Navigator, and is only public
      * and static to enable testing.
      */
-    public static class UriFragmentManager implements FragmentManager,
+    public static class UriFragmentManager implements NavigationStateManager,
             FragmentChangedListener {
         private final Page page;
         private final Navigator navigator;
@@ -102,18 +102,18 @@ public class Navigator implements Serializable {
         }
 
         @Override
-        public String getFragment() {
+        public String getState() {
             return page.getFragment();
         }
 
         @Override
-        public void setFragment(String fragment) {
+        public void setState(String fragment) {
             page.setFragment(fragment, false);
         }
 
         @Override
         public void fragmentChanged(FragmentChangedEvent event) {
-            UriFragmentManager.this.navigator.navigateTo(getFragment());
+            UriFragmentManager.this.navigator.navigateTo(getState());
         }
     }
 
@@ -318,7 +318,7 @@ public class Navigator implements Serializable {
         }
     }
 
-    private final FragmentManager fragmentManager;
+    private final NavigationStateManager fragmentManager;
     private final ViewDisplay display;
     private View currentView = null;
     private List<ViewChangeListener> listeners = new LinkedList<ViewChangeListener>();
@@ -393,7 +393,7 @@ public class Navigator implements Serializable {
      * @param display
      *            where to display the views
      */
-    public Navigator(FragmentManager fragmentManager, ViewDisplay display) {
+    public Navigator(NavigationStateManager fragmentManager, ViewDisplay display) {
         this.display = display;
         this.fragmentManager = fragmentManager;
     }
@@ -472,8 +472,8 @@ public class Navigator implements Serializable {
             if (!fragmentParameters.equals("")) {
                 currentFragment += "/" + fragmentParameters;
             }
-            if (!currentFragment.equals(getFragmentManager().getFragment())) {
-                getFragmentManager().setFragment(currentFragment);
+            if (!currentFragment.equals(getFragmentManager().getState())) {
+                getFragmentManager().setState(currentFragment);
             }
         }
 
@@ -517,7 +517,7 @@ public class Navigator implements Serializable {
      * 
      * @return fragment manager in use
      */
-    protected FragmentManager getFragmentManager() {
+    protected NavigationStateManager getFragmentManager() {
         return fragmentManager;
     }
 
index 595ddb95db7943989a59a96237ade42219864d6b..5bde04a3b4fc4c0a46c9f6f2a7631cc921c35f7d 100644 (file)
@@ -23,7 +23,7 @@ import junit.framework.TestCase;
 import org.easymock.EasyMock;
 import org.easymock.IMocksControl;
 
-import com.vaadin.navigator.FragmentManager;
+import com.vaadin.navigator.NavigationStateManager;
 import com.vaadin.navigator.Navigator;
 import com.vaadin.navigator.View;
 import com.vaadin.navigator.ViewChangeListener;
@@ -45,14 +45,14 @@ public class NavigatorTest extends TestCase {
         }
     }
 
-    public static class NullFragmentManager implements FragmentManager {
+    public static class NullFragmentManager implements NavigationStateManager {
         @Override
-        public String getFragment() {
+        public String getState() {
             return null;
         }
 
         @Override
-        public void setFragment(String fragment) {
+        public void setState(String fragment) {
             // do nothing
         }
     }
@@ -171,7 +171,7 @@ public class NavigatorTest extends TestCase {
 
     public void testBasicNavigation() {
         IMocksControl control = EasyMock.createControl();
-        FragmentManager manager = control.createMock(FragmentManager.class);
+        NavigationStateManager manager = control.createMock(NavigationStateManager.class);
         ViewDisplay display = control.createMock(ViewDisplay.class);
         ViewProvider provider = control.createMock(ViewProvider.class);
         View view1 = control.createMock(View.class);
@@ -180,25 +180,25 @@ public class NavigatorTest extends TestCase {
         // prepare mocks: what to expect
         EasyMock.expect(provider.getViewName("test1")).andReturn("test1");
         EasyMock.expect(provider.getView("test1")).andReturn(view1);
-        EasyMock.expect(manager.getFragment()).andReturn("");
+        EasyMock.expect(manager.getState()).andReturn("");
         view1.navigateTo("");
         display.showView(view1);
-        manager.setFragment("test1");
+        manager.setState("test1");
 
         EasyMock.expect(provider.getViewName("test2/")).andReturn("test2");
         EasyMock.expect(provider.getView("test2")).andReturn(view2);
-        EasyMock.expect(manager.getFragment()).andReturn("view1");
+        EasyMock.expect(manager.getState()).andReturn("view1");
         view2.navigateTo("");
         display.showView(view2);
-        manager.setFragment("test2");
+        manager.setState("test2");
 
         EasyMock.expect(provider.getViewName("test1/params"))
                 .andReturn("test1");
         EasyMock.expect(provider.getView("test1")).andReturn(view1);
-        EasyMock.expect(manager.getFragment()).andReturn("view2");
+        EasyMock.expect(manager.getState()).andReturn("view2");
         view1.navigateTo("params");
         display.showView(view1);
-        manager.setFragment("test1/params");
+        manager.setState("test1/params");
 
         control.replay();
 
@@ -213,7 +213,7 @@ public class NavigatorTest extends TestCase {
 
     public void testMainView() {
         IMocksControl control = EasyMock.createControl();
-        FragmentManager manager = control.createMock(FragmentManager.class);
+        NavigationStateManager manager = control.createMock(NavigationStateManager.class);
         ViewDisplay display = control.createMock(ViewDisplay.class);
         ViewProvider provider = control.createMock(ViewProvider.class);
         View view1 = control.createMock(View.class);
@@ -222,25 +222,25 @@ public class NavigatorTest extends TestCase {
         // prepare mocks: what to expect
         EasyMock.expect(provider.getViewName("test2")).andReturn("test2");
         EasyMock.expect(provider.getView("test2")).andReturn(view2);
-        EasyMock.expect(manager.getFragment()).andReturn("view1");
+        EasyMock.expect(manager.getState()).andReturn("view1");
         view2.navigateTo("");
         display.showView(view2);
-        manager.setFragment("test2");
+        manager.setState("test2");
 
         EasyMock.expect(provider.getViewName("")).andReturn("test1");
         EasyMock.expect(provider.getView("test1")).andReturn(view1);
-        EasyMock.expect(manager.getFragment()).andReturn("");
+        EasyMock.expect(manager.getState()).andReturn("");
         view1.navigateTo("");
         display.showView(view1);
-        manager.setFragment("test1");
+        manager.setState("test1");
 
         EasyMock.expect(provider.getViewName("test1/params"))
                 .andReturn("test1");
         EasyMock.expect(provider.getView("test1")).andReturn(view1);
-        EasyMock.expect(manager.getFragment()).andReturn("view2");
+        EasyMock.expect(manager.getState()).andReturn("view2");
         view1.navigateTo("params");
         display.showView(view1);
-        manager.setFragment("test1/params");
+        manager.setState("test1/params");
 
         control.replay();
 
@@ -255,7 +255,7 @@ public class NavigatorTest extends TestCase {
 
     public void testListeners() {
         IMocksControl control = EasyMock.createControl();
-        FragmentManager manager = control.createMock(FragmentManager.class);
+        NavigationStateManager manager = control.createMock(NavigationStateManager.class);
         ViewDisplay display = control.createMock(ViewDisplay.class);
         ViewProvider provider = control.createMock(ViewProvider.class);
         View view1 = control.createMock(View.class);
@@ -271,10 +271,10 @@ public class NavigatorTest extends TestCase {
         ViewChangeEvent event1 = new ViewChangeEvent(navigator, null, view1,
                 "test1", "");
         listener.addExpectedIsViewChangeAllowed(event1, true);
-        EasyMock.expect(manager.getFragment()).andReturn("");
+        EasyMock.expect(manager.getState()).andReturn("");
         view1.navigateTo("");
         display.showView(view1);
-        manager.setFragment("test1");
+        manager.setState("test1");
         listener.addExpectedNavigatorViewChange(event1);
 
         EasyMock.expect(provider.getViewName("test2")).andReturn("test2");
@@ -282,10 +282,10 @@ public class NavigatorTest extends TestCase {
         ViewChangeEvent event2 = new ViewChangeEvent(navigator, view1, view2,
                 "test2", "");
         listener.addExpectedIsViewChangeAllowed(event2, true);
-        EasyMock.expect(manager.getFragment()).andReturn("view1");
+        EasyMock.expect(manager.getState()).andReturn("view1");
         view2.navigateTo("");
         display.showView(view2);
-        manager.setFragment("test2");
+        manager.setState("test2");
         listener.addExpectedNavigatorViewChange(event2);
 
         control.replay();
@@ -304,7 +304,7 @@ public class NavigatorTest extends TestCase {
 
     public void testBlockNavigation() {
         IMocksControl control = EasyMock.createControl();
-        FragmentManager manager = control.createMock(FragmentManager.class);
+        NavigationStateManager manager = control.createMock(NavigationStateManager.class);
         ViewDisplay display = control.createMock(ViewDisplay.class);
         ViewProvider provider = control.createMock(ViewProvider.class);
         View view1 = control.createMock(View.class);
@@ -318,7 +318,7 @@ public class NavigatorTest extends TestCase {
         // first listener blocks first view change
         EasyMock.expect(provider.getViewName("test1")).andReturn("test1");
         EasyMock.expect(provider.getView("test1")).andReturn(view1);
-        EasyMock.expect(manager.getFragment()).andReturn("");
+        EasyMock.expect(manager.getState()).andReturn("");
         ViewChangeEvent event1 = new ViewChangeEvent(navigator, null, view1,
                 "test1", "");
         listener1.addExpectedIsViewChangeAllowed(event1, false);
@@ -326,7 +326,7 @@ public class NavigatorTest extends TestCase {
         // second listener blocks second view change
         EasyMock.expect(provider.getViewName("test1/test")).andReturn("test1");
         EasyMock.expect(provider.getView("test1")).andReturn(view1);
-        EasyMock.expect(manager.getFragment()).andReturn("");
+        EasyMock.expect(manager.getState()).andReturn("");
         ViewChangeEvent event2 = new ViewChangeEvent(navigator, null, view1,
                 "test1", "test");
         listener1.addExpectedIsViewChangeAllowed(event2, true);
@@ -335,28 +335,28 @@ public class NavigatorTest extends TestCase {
         // both listeners allow view change
         EasyMock.expect(provider.getViewName("test1/bar")).andReturn("test1");
         EasyMock.expect(provider.getView("test1")).andReturn(view1);
-        EasyMock.expect(manager.getFragment()).andReturn("");
+        EasyMock.expect(manager.getState()).andReturn("");
         ViewChangeEvent event3 = new ViewChangeEvent(navigator, null, view1,
                 "test1", "bar");
         listener1.addExpectedIsViewChangeAllowed(event3, true);
         listener2.addExpectedIsViewChangeAllowed(event3, true);
         view1.navigateTo("bar");
         display.showView(view1);
-        manager.setFragment("test1/bar");
+        manager.setState("test1/bar");
         listener1.addExpectedNavigatorViewChange(event3);
         listener2.addExpectedNavigatorViewChange(event3);
 
         // both listeners allow view change from non-null view
         EasyMock.expect(provider.getViewName("test2")).andReturn("test2");
         EasyMock.expect(provider.getView("test2")).andReturn(view2);
-        EasyMock.expect(manager.getFragment()).andReturn("view1");
+        EasyMock.expect(manager.getState()).andReturn("view1");
         ViewChangeEvent event4 = new ViewChangeEvent(navigator, view1, view2,
                 "test2", "");
         listener1.addExpectedIsViewChangeAllowed(event4, true);
         listener2.addExpectedIsViewChangeAllowed(event4, true);
         view2.navigateTo("");
         display.showView(view2);
-        manager.setFragment("test2");
+        manager.setState("test2");
         listener1.addExpectedNavigatorViewChange(event4);
         listener2.addExpectedNavigatorViewChange(event4);
 
index 18ed52cc2a383a08a5a4c92784f41c184fd04a8a..d58ff28b0054da98e112d0ae402b480111f510f8 100644 (file)
@@ -39,9 +39,9 @@ public class UriFragmentManagerTest extends TestCase {
         EasyMock.replay(page);
 
         // test manager using the mock
-        assertEquals("Incorrect fragment value", "", manager.getFragment());
-        manager.setFragment("test");
-        assertEquals("Incorrect fragment value", "test", manager.getFragment());
+        assertEquals("Incorrect fragment value", "", manager.getState());
+        manager.setState("test");
+        assertEquals("Incorrect fragment value", "test", manager.getState());
     }
 
     public void testListener() {