@@ -29,6 +29,7 @@ import com.vaadin.ui.Component; | |||
import com.vaadin.ui.ComponentContainer; | |||
import com.vaadin.ui.CssLayout; | |||
import com.vaadin.ui.CustomComponent; | |||
import com.vaadin.ui.UI; | |||
/** | |||
* A navigator utility that allows switching of views in a part of an | |||
@@ -124,7 +125,7 @@ public class Navigator implements Serializable { | |||
@Override | |||
public void fragmentChanged(FragmentChangedEvent event) { | |||
UriFragmentManager.this.navigator.navigateTo(getState()); | |||
navigator.navigateTo(getState()); | |||
} | |||
} | |||
@@ -331,6 +332,7 @@ public class Navigator implements Serializable { | |||
} | |||
} | |||
private final UI ui; | |||
private final NavigationStateManager stateManager; | |||
private final ViewDisplay display; | |||
private View currentView = null; | |||
@@ -354,30 +356,34 @@ public class Navigator implements Serializable { | |||
* the application should trigger navigation to the current fragment using | |||
* {@link #navigate()}. | |||
* | |||
* @param ui | |||
* The UI to which this Navigator is attached. | |||
* @param container | |||
* ComponentContainer whose contents should be replaced with the | |||
* active view on view change | |||
* The ComponentContainer whose contents should be replaced with | |||
* the active view on view change | |||
*/ | |||
public Navigator(ComponentContainer container) { | |||
display = new ComponentContainerViewDisplay(container); | |||
stateManager = new UriFragmentManager(Page.getCurrent(), this); | |||
public Navigator(UI ui, ComponentContainer container) { | |||
this(ui, new ComponentContainerViewDisplay(container)); | |||
} | |||
/** | |||
* Creates a navigator that is tracking the active view using URI fragments. | |||
* Creates a navigator that is tracking the active view using URI fragments | |||
* of the Page containing the given UI. | |||
* <p> | |||
* After all {@link View}s and {@link ViewProvider}s have been registered, | |||
* the application should trigger navigation to the current fragment using | |||
* {@link #navigate()}. | |||
* | |||
* @param page | |||
* whose URI fragments are used | |||
* @param ui | |||
* The UI to which this Navigator is attached. | |||
* @param display | |||
* where to display the views | |||
* The ViewDisplay used to display the views. | |||
*/ | |||
public Navigator(Page page, ViewDisplay display) { | |||
public Navigator(UI ui, ViewDisplay display) { | |||
this.ui = ui; | |||
this.ui.setNavigator(this); | |||
this.display = display; | |||
stateManager = new UriFragmentManager(page, this); | |||
stateManager = new UriFragmentManager(ui.getPage(), this); | |||
} | |||
/** | |||
@@ -391,14 +397,19 @@ public class Navigator implements Serializable { | |||
* the application should trigger navigation to the current fragment using | |||
* {@link #navigate()}. | |||
* | |||
* @param ui | |||
* The UI to which this Navigator is attached. | |||
* @param stateManager | |||
* {@link NavigationStateManager} keeping track of the active | |||
* view and enabling bookmarking and direct navigation | |||
* The NavigationStateManager keeping track of the active view | |||
* and enabling bookmarking and direct navigation | |||
* @param display | |||
* {@ViewDisplay} used to display the views handled | |||
* by this navigator | |||
* The ViewDisplay used to display the views handled by this | |||
* navigator | |||
*/ | |||
public Navigator(NavigationStateManager stateManager, ViewDisplay display) { | |||
public Navigator(UI ui, NavigationStateManager stateManager, | |||
ViewDisplay display) { | |||
this.ui = ui; | |||
this.ui.setNavigator(this); | |||
this.display = display; | |||
this.stateManager = stateManager; | |||
} | |||
@@ -547,6 +558,10 @@ public class Navigator implements Serializable { | |||
return display; | |||
} | |||
public UI getUI() { | |||
return ui; | |||
} | |||
/** | |||
* Fires an event after the current view has changed. | |||
* <p> |
@@ -33,6 +33,7 @@ import com.vaadin.event.Action.Handler; | |||
import com.vaadin.event.ActionManager; | |||
import com.vaadin.event.MouseEvents.ClickEvent; | |||
import com.vaadin.event.MouseEvents.ClickListener; | |||
import com.vaadin.navigator.Navigator; | |||
import com.vaadin.server.LegacyComponent; | |||
import com.vaadin.server.Page; | |||
import com.vaadin.server.Page.BrowserWindowResizeEvent; | |||
@@ -845,6 +846,8 @@ public abstract class UI extends AbstractComponentContainer implements | |||
private String theme; | |||
private Navigator navigator; | |||
/** | |||
* This method is used by Component.Focusable objects to request focus to | |||
* themselves. Focus renders must be handled at window level (instead of | |||
@@ -1187,6 +1190,25 @@ public abstract class UI extends AbstractComponentContainer implements | |||
return page; | |||
} | |||
/** | |||
* Returns the navigator attached to this UI or null if there is no | |||
* navigator. | |||
* | |||
* @return | |||
*/ | |||
public Navigator getNavigator() { | |||
return navigator; | |||
} | |||
/** | |||
* For internal use only. | |||
* | |||
* @param navigator | |||
*/ | |||
public void setNavigator(Navigator navigator) { | |||
this.navigator = navigator; | |||
} | |||
/** | |||
* Setting the caption of a UI is not supported. To set the title of the | |||
* HTML page, use Page.setTitle |
@@ -73,7 +73,7 @@ public class NavigatorTest extends TestCase { | |||
public static class TestNavigator extends Navigator { | |||
public TestNavigator() { | |||
super(new NullFragmentManager(), new TestDisplay()); | |||
super(null, new NullFragmentManager(), new TestDisplay()); | |||
} | |||
public View getView(String viewAndParameters) { | |||
@@ -221,7 +221,7 @@ public class NavigatorTest extends TestCase { | |||
control.replay(); | |||
// create and test navigator | |||
Navigator navigator = new Navigator(manager, display); | |||
Navigator navigator = new Navigator(null, manager, display); | |||
navigator.addProvider(provider); | |||
navigator.navigateTo("test1"); | |||
@@ -264,7 +264,7 @@ public class NavigatorTest extends TestCase { | |||
control.replay(); | |||
// create and test navigator | |||
Navigator navigator = new Navigator(manager, display); | |||
Navigator navigator = new Navigator(null, manager, display); | |||
navigator.addProvider(provider); | |||
navigator.navigateTo("test2"); | |||
@@ -283,7 +283,7 @@ public class NavigatorTest extends TestCase { | |||
ViewChangeTestListener listener = new ViewChangeTestListener(); | |||
// create navigator to test | |||
Navigator navigator = new Navigator(manager, display); | |||
Navigator navigator = new Navigator(null, manager, display); | |||
// prepare mocks: what to expect | |||
EasyMock.expect(provider.getViewName("test1")).andReturn("test1"); | |||
@@ -333,7 +333,7 @@ public class NavigatorTest extends TestCase { | |||
ViewChangeTestListener listener1 = new ViewChangeTestListener(); | |||
ViewChangeTestListener listener2 = new ViewChangeTestListener(); | |||
Navigator navigator = new Navigator(manager, display); | |||
Navigator navigator = new Navigator(null, manager, display); | |||
// prepare mocks: what to expect | |||
// first listener blocks first view change | |||
@@ -467,7 +467,7 @@ public class NavigatorTest extends TestCase { | |||
} | |||
public void testAddViewWithNullName() throws Exception { | |||
Navigator navigator = new Navigator(new NullFragmentManager(), | |||
Navigator navigator = new Navigator(null, new NullFragmentManager(), | |||
new NullDisplay()); | |||
try { | |||
@@ -483,7 +483,7 @@ public class NavigatorTest extends TestCase { | |||
} | |||
public void testAddViewWithNullInstance() throws Exception { | |||
Navigator navigator = new Navigator(new NullFragmentManager(), | |||
Navigator navigator = new Navigator(null, new NullFragmentManager(), | |||
new NullDisplay()); | |||
try { | |||
@@ -494,7 +494,7 @@ public class NavigatorTest extends TestCase { | |||
} | |||
public void testAddViewWithNullClass() throws Exception { | |||
Navigator navigator = new Navigator(new NullFragmentManager(), | |||
Navigator navigator = new Navigator(null, new NullFragmentManager(), | |||
new NullDisplay()); | |||
try { |
@@ -104,7 +104,7 @@ public class NavigatorTest extends UI { | |||
@Override | |||
protected void init(WrappedRequest req) { | |||
try { | |||
navi = new Navigator(naviLayout); | |||
navi = new Navigator(this, naviLayout); | |||
navi.addView("", new DefaultView()); | |||
@@ -113,7 +113,8 @@ public class NavigatorTest extends UI { | |||
navi.addView("forbidden", new ForbiddenView()); | |||
navi.addViewChangeListener(new NaviListener()); | |||
// navi.navigate(); | |||
navi.navigate(); | |||
addComponent(new NaviButton("list")); | |||
addComponent(new NaviButton("edit")); |