}
@Override
- public void navigateTo(String fragmentParameters) {
+ public void navigateTo(String parameters) {
// nothing to do
}
}
/**
- * Fragment manager using URI fragments of a Page to track views and enable
- * listening to view changes.
- *
+ * A {@link NavigationStateManager} using hashbang fragments in the Page
+ * location URI to track views and enable listening to view changes.
+ * <p>
+ * A hashbang URI is one where the optional fragment or "hash" part - the
+ * part following a # sign - is used to encode navigation state in a web
+ * application. The advantage of this is that the fragment can be
+ * dynamically manipulated by javascript without causing page reloads.
+ * <p>
* This class is mostly for internal use by Navigator, and is only public
* and static to enable testing.
*/
}
@Override
- public void setState(String fragment) {
- page.setFragment(fragment, false);
+ public void setState(String state) {
+ page.setFragment(state, false);
}
@Override
}
@Override
- public String getViewName(String viewAndParameters) {
- if (null == viewAndParameters) {
+ public String getViewName(String navigationState) {
+ if (null == navigationState) {
return null;
}
- if (viewAndParameters.startsWith(viewName)) {
+ if (navigationState.startsWith(viewName)) {
return viewName;
}
return null;
}
@Override
- public String getViewName(String viewAndParameters) {
- if (null == viewAndParameters) {
+ public String getViewName(String navigationState) {
+ if (null == navigationState) {
return null;
}
- if (viewAndParameters.equals(viewName)
- || viewAndParameters.startsWith(viewName + "/")) {
+ if (navigationState.equals(viewName)
+ || navigationState.startsWith(viewName + "/")) {
return viewName;
}
return null;
}
}
- private final NavigationStateManager fragmentManager;
+ private final NavigationStateManager stateManager;
private final ViewDisplay display;
private View currentView = null;
private List<ViewChangeListener> listeners = new LinkedList<ViewChangeListener>();
*/
public Navigator(ComponentContainer container) {
display = new ComponentContainerViewDisplay(container);
- fragmentManager = new UriFragmentManager(Page.getCurrent(), this);
+ stateManager = new UriFragmentManager(Page.getCurrent(), this);
}
/**
*/
public Navigator(Page page, ViewDisplay display) {
this.display = display;
- fragmentManager = new UriFragmentManager(page, this);
+ stateManager = new UriFragmentManager(page, this);
}
/**
* Create a navigator.
*
- * When a custom fragment manager is not needed, use the constructor
+ * When a custom navigation state manager is not needed, use the constructor
* {@link #Navigator(Page, ViewDisplay)} which uses a URI fragment based
- * fragment manager.
+ * state 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
+ * @param stateManager
+ * {@link NavigationStateManager} keeping track of the active
+ * view and enabling bookmarking and direct navigation
* @param display
- * where to display the views
+ * {@ViewDisplay} used to display the views handled
+ * by this navigator
*/
- public Navigator(NavigationStateManager fragmentManager, ViewDisplay display) {
+ public Navigator(NavigationStateManager stateManager, ViewDisplay display) {
this.display = display;
- this.fragmentManager = fragmentManager;
+ this.stateManager = stateManager;
}
/**
* Navigate to a view and initialize the view with given parameters.
*
* The view string consists of a view name optionally followed by a slash
- * and (fragment) parameters. ViewProviders are used to find and create the
- * correct type of view.
+ * and a parameters part that is passed as-is to the view. ViewProviders are
+ * used to find and create the correct type of view.
*
* If multiple providers return a matching view, the view with the longest
* name is selected. This way, e.g. hierarchies of subviews can be
* Registered {@link ViewChangeListener}s are called upon successful view
* change.
*
- * @param viewAndParameters
+ * @param navigationState
* view name and parameters
*/
- public void navigateTo(String viewAndParameters) {
+ public void navigateTo(String navigationState) {
String longestViewName = null;
View viewWithLongestName = null;
for (ViewProvider provider : providers) {
- String viewName = provider.getViewName(viewAndParameters);
+ String viewName = provider.getViewName(navigationState);
if (null != viewName
&& (longestViewName == null || viewName.length() > longestViewName
.length())) {
}
if (viewWithLongestName != null) {
String parameters = "";
- if (viewAndParameters.length() > longestViewName.length() + 1) {
- parameters = viewAndParameters.substring(longestViewName
- .length() + 1);
+ if (navigationState.length() > longestViewName.length() + 1) {
+ parameters = navigationState
+ .substring(longestViewName.length() + 1);
}
navigateTo(viewWithLongestName, longestViewName, parameters);
}
* @param view
* view to activate
* @param viewName
- * (optional) name of the view or null not to set the fragment
- * @param fragmentParameters
- * parameters passed in the fragment for the view
+ * (optional) name of the view or null not to change the
+ * navigation state
+ * @param parameters
+ * parameters passed in the navigation state to the view
*/
- protected void navigateTo(View view, String viewName,
- String fragmentParameters) {
+ protected void navigateTo(View view, String viewName, String parameters) {
ViewChangeEvent event = new ViewChangeEvent(this, currentView, view,
- viewName, fragmentParameters);
+ viewName, parameters);
if (!isViewChangeAllowed(event)) {
return;
}
- if (null != viewName && getFragmentManager() != null) {
- String currentFragment = viewName;
- if (!fragmentParameters.equals("")) {
- currentFragment += "/" + fragmentParameters;
+ if (null != viewName && getStateManager() != null) {
+ String navigationState = viewName;
+ if (!parameters.equals("")) {
+ navigationState += "/" + parameters;
}
- if (!currentFragment.equals(getFragmentManager().getState())) {
- getFragmentManager().setState(currentFragment);
+ if (!navigationState.equals(getStateManager().getState())) {
+ getStateManager().setState(navigationState);
}
}
- view.navigateTo(fragmentParameters);
+ view.navigateTo(parameters);
currentView = view;
if (display != null) {
}
/**
- * Return the fragment manager that is used to get, listen to and manipulate
- * the URI fragment or other source of navigation information.
+ * Returns the {@link NavigationStateManager} that is used to get, listen to
+ * and manipulate the navigation state used by this Navigator.
*
- * @return fragment manager in use
+ * @return NavigationStateManager in use
*/
- protected NavigationStateManager getFragmentManager() {
- return fragmentManager;
+ protected NavigationStateManager getStateManager() {
+ return stateManager;
}
/**
- * Returns the ViewDisplay used by the navigator. Unless another display is
+ * Return the ViewDisplay used by the navigator. Unless another display is
* specified, a {@link SimpleViewDisplay} (which is a {@link Component}) is
* used by default.
*
if (!stringEquals(reference.getViewName(), event.getViewName())) {
return false;
}
- if (!stringEquals(reference.getFragmentParameters(),
- event.getFragmentParameters())) {
+ if (!stringEquals(reference.getParameters(), event.getParameters())) {
return false;
}
return true;
public void testBasicNavigation() {
IMocksControl control = EasyMock.createControl();
- NavigationStateManager manager = control.createMock(NavigationStateManager.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);
public void testMainView() {
IMocksControl control = EasyMock.createControl();
- NavigationStateManager manager = control.createMock(NavigationStateManager.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);
public void testListeners() {
IMocksControl control = EasyMock.createControl();
- NavigationStateManager manager = control.createMock(NavigationStateManager.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);
public void testBlockNavigation() {
IMocksControl control = EasyMock.createControl();
- NavigationStateManager manager = control.createMock(NavigationStateManager.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);