diff options
-rw-r--r-- | server/src/com/vaadin/navigator/NavigationStateManager.java | 25 | ||||
-rw-r--r-- | server/src/com/vaadin/navigator/Navigator.java | 45 |
2 files changed, 49 insertions, 21 deletions
diff --git a/server/src/com/vaadin/navigator/NavigationStateManager.java b/server/src/com/vaadin/navigator/NavigationStateManager.java index cbbeb59c30..c3f1f0f11e 100644 --- a/server/src/com/vaadin/navigator/NavigationStateManager.java +++ b/server/src/com/vaadin/navigator/NavigationStateManager.java @@ -19,15 +19,15 @@ 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. + * An interface for handling interaction between {@link 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}. + * This interface is mostly for internal use by Navigator. * * @author Vaadin Ltd * @since 7.0 @@ -42,11 +42,22 @@ public interface NavigationStateManager extends Serializable { public String getState(); /** - * Set the current navigation state in the location URI or similar location, - * including view name and any optional parameters. + * Sets the current navigation state in the location URI or similar + * location, including view name and any optional parameters. + * <p> + * This method should be only called by a Navigator. * * @param fragment * new view and parameter string, not null */ public void setState(String state); + + /** + * Sets the Navigator used with this state manager. The state manager should + * notify the provided navigator of user-triggered navigation state changes + * by invoking <code>navigator.navigateTo(getState())</code>. + * <p> + * This method should only be called by a Navigator. + */ + public void setNavigator(Navigator navigator); }
\ No newline at end of file diff --git a/server/src/com/vaadin/navigator/Navigator.java b/server/src/com/vaadin/navigator/Navigator.java index a3b0ad89a0..df9e5059fa 100644 --- a/server/src/com/vaadin/navigator/Navigator.java +++ b/server/src/com/vaadin/navigator/Navigator.java @@ -87,7 +87,7 @@ public class Navigator implements Serializable { public static class UriFragmentManager implements NavigationStateManager, FragmentChangedListener { private final Page page; - private final Navigator navigator; + private Navigator navigator; /** * Creates a new URIFragmentManager and attach it to listen to URI @@ -95,20 +95,20 @@ public class Navigator implements Serializable { * * @param page * page whose URI fragment to get and modify - * @param navigator - * {@link Navigator} to notify of fragment changes (using - * {@link Navigator#navigateTo(String)} */ - public UriFragmentManager(Page page, Navigator navigator) { + public UriFragmentManager(Page page) { this.page = page; - this.navigator = navigator; - page.addFragmentChangedListener(this); } @Override + public void setNavigator(Navigator navigator) { + this.navigator = navigator; + } + + @Override public String getState() { - String fragment = page.getFragment(); + String fragment = getFragment(); if (fragment.startsWith("!")) { return fragment.substring(1); } else { @@ -118,13 +118,32 @@ public class Navigator implements Serializable { @Override public void setState(String state) { - page.setFragment("!" + state, false); + setFragment("!" + state); } @Override public void fragmentChanged(FragmentChangedEvent event) { navigator.navigateTo(getState()); } + + /** + * Returns the current URI fragment tracked by this UriFragentManager. + * + * @return The URI fragment. + */ + protected String getFragment() { + return page.getFragment(); + } + + /** + * Sets the URI fragment to the given string. + * + * @param fragment + * The new URI fragment. + */ + protected void setFragment(String fragment) { + page.setFragment(fragment, false); + } } /** @@ -379,10 +398,7 @@ public class Navigator implements Serializable { * The ViewDisplay used to display the views. */ public Navigator(UI ui, ViewDisplay display) { - this.ui = ui; - this.ui.setNavigator(this); - this.display = display; - stateManager = new UriFragmentManager(ui.getPage(), this); + this(ui, new UriFragmentManager(ui.getPage()), display); } /** @@ -409,8 +425,9 @@ public class Navigator implements Serializable { ViewDisplay display) { this.ui = ui; this.ui.setNavigator(this); - this.display = display; this.stateManager = stateManager; + this.stateManager.setNavigator(this); + this.display = display; } /** |