From 58ca6dff762e14512d4e4a9fec92a27345988b52 Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Mon, 25 Jun 2012 09:57:22 +0300 Subject: [PATCH] Fixes for Navigator: empty view name, no extra event, javadoc (#8859) --- src/com/vaadin/navigator/Navigator.java | 34 ++++++++++++++----------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/com/vaadin/navigator/Navigator.java b/src/com/vaadin/navigator/Navigator.java index 387f1d4eae..3ff727b504 100644 --- a/src/com/vaadin/navigator/Navigator.java +++ b/src/com/vaadin/navigator/Navigator.java @@ -1,9 +1,9 @@ +package com.vaadin.navigator; + /* -@VaadinApache2LicenseForJavaFiles@ + @VaadinApache2LicenseForJavaFiles@ */ -package com.vaadin.navigator; - import java.io.Serializable; import java.util.Iterator; import java.util.LinkedList; @@ -16,7 +16,6 @@ import com.vaadin.terminal.Page.FragmentChangedListener; import com.vaadin.ui.Component; import com.vaadin.ui.CssLayout; import com.vaadin.ui.CustomComponent; -import com.vaadin.ui.Root; /** * Navigator utility that allows switching of views in a part of an application. @@ -60,7 +59,7 @@ public class Navigator implements Serializable { } /** - * Fragment manager using URI fragments of a Root to track views and enable + * Fragment manager using URI fragments of a Page to track views and enable * listening to view changes. * * This class is mostly for internal use by Navigator, and is only public @@ -73,10 +72,10 @@ public class Navigator implements Serializable { /** * Create a new URIFragmentManager and attach it to listen to URI - * fragment changes of a {@link Root}. + * fragment changes of a {@link Page}. * - * @param root - * root whose URI fragment to get and modify + * @param page + * page whose URI fragment to get and modify * @param navigator * {@link Navigator} to notify of fragment changes (using * {@link Navigator#navigateTo(String)} @@ -93,8 +92,7 @@ public class Navigator implements Serializable { } public void setFragment(String fragment) { - // TODO ", false" ??? - page.setFragment(fragment); + page.setFragment(fragment, false); } public void fragmentChanged(FragmentChangedEvent event) { @@ -272,7 +270,7 @@ public class Navigator implements Serializable { /** * Create a navigator that is tracking the active view using URI fragments. * - * @param root + * @param page * whose URI fragments are used * @param display * where to display the views @@ -280,6 +278,7 @@ public class Navigator implements Serializable { public Navigator(Page page, ViewDisplay display) { this.display = display; fragmentManager = new UriFragmentManager(page, this); + navigateTo(page.getFragment()); } /** @@ -287,21 +286,25 @@ public class Navigator implements Serializable { * By default, a {@link SimpleViewDisplay} is used and can be obtained using * {@link #getDisplay()}. * - * @param root + * @param page * whose URI fragments are used */ public Navigator(Page page) { display = new SimpleViewDisplay(); fragmentManager = new UriFragmentManager(page, this); + navigateTo(page.getFragment()); } /** * Create a navigator. * * When a custom fragment manager is not needed, use the constructor - * {@link #Navigator(Root, ViewDisplay)} which uses a URI fragment based + * {@link #Navigator(Page, ViewDisplay)} which uses a URI fragment based * fragment manager. * + * Note that navigation to the initial view must be performed explicitly by + * the application after creating a Navigator using this constructor. + * * @param fragmentManager * fragment manager keeping track of the active view and enabling * bookmarking and direct navigation @@ -335,12 +338,13 @@ public class Navigator implements Serializable { * view name and parameters */ public void navigateTo(String viewAndParameters) { - String longestViewName = ""; + String longestViewName = null; View viewWithLongestName = null; for (ViewProvider provider : providers) { String viewName = provider.getViewName(viewAndParameters); if (null != viewName - && viewName.length() > longestViewName.length()) { + && (longestViewName == null || viewName.length() > longestViewName + .length())) { View view = provider.getView(viewName); if (null != view) { longestViewName = viewName; -- 2.39.5