+package com.vaadin.navigator;
+
/*
-@VaadinApache2LicenseForJavaFiles@
+ @VaadinApache2LicenseForJavaFiles@
*/
-package com.vaadin.navigator;
-
import java.io.Serializable;
import java.util.Iterator;
import java.util.LinkedList;
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.
}
/**
- * 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
/**
* 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)}
}
public void setFragment(String fragment) {
- // TODO ", false" ???
- page.setFragment(fragment);
+ page.setFragment(fragment, false);
}
public void fragmentChanged(FragmentChangedEvent event) {
/**
* 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
public Navigator(Page page, ViewDisplay display) {
this.display = display;
fragmentManager = new UriFragmentManager(page, this);
+ navigateTo(page.getFragment());
}
/**
* 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
* 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;