diff options
author | Henri Sara <hesara@vaadin.com> | 2015-10-14 09:49:45 -0700 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2015-10-23 11:35:54 +0000 |
commit | ce161ac530bb9122e7a9c09d48b8f27218a8940b (patch) | |
tree | 413007a228b007b668773ff09dbfc0d302526a85 /server/src/com/vaadin | |
parent | e776732e571846e566f36490043780f2d8f078a5 (diff) | |
download | vaadin-framework-ce161ac530bb9122e7a9c09d48b8f27218a8940b.tar.gz vaadin-framework-ce161ac530bb9122e7a9c09d48b8f27218a8940b.zip |
Make it possible to inject Navigators (#14006)
This change makes it possible to create an injectable subclass of
the navigator by providing a protected no-args constructor and a
separate initialization method.
Change-Id: I7d55fca2a84570d47e2767b0fb81a82e0732fd21
Diffstat (limited to 'server/src/com/vaadin')
-rw-r--r-- | server/src/com/vaadin/navigator/Navigator.java | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/server/src/com/vaadin/navigator/Navigator.java b/server/src/com/vaadin/navigator/Navigator.java index 049c29423d..b9f270c0d8 100644 --- a/server/src/com/vaadin/navigator/Navigator.java +++ b/server/src/com/vaadin/navigator/Navigator.java @@ -365,9 +365,9 @@ public class Navigator implements Serializable { } } - private final UI ui; - private final NavigationStateManager stateManager; - private final ViewDisplay display; + private UI ui; + private NavigationStateManager stateManager; + private ViewDisplay display; private View currentView = null; private List<ViewChangeListener> listeners = new LinkedList<ViewChangeListener>(); private List<ViewProvider> providers = new LinkedList<ViewProvider>(); @@ -457,15 +457,54 @@ public class Navigator implements Serializable { * The UI to which this Navigator is attached. * @param stateManager * The NavigationStateManager keeping track of the active view - * and enabling bookmarking and direct navigation + * and enabling bookmarking and direct navigation or null to use + * the default implementation * @param display * The ViewDisplay used to display the views handled by this * navigator */ public Navigator(UI ui, NavigationStateManager stateManager, ViewDisplay display) { + init(ui, stateManager, display); + } + + /** + * Creates a navigator. This method is for use by dependency injection + * frameworks etc. and must be followed by a call to + * {@link #init(UI, NavigationStateManager, ViewDisplay)} before use. + */ + protected Navigator() { + } + + /** + * Initializes a navigator created with the no arguments constructor. + * <p> + * When a custom navigation state manager is not needed, use null to create + * a default one based on URI fragments. + * <p> + * Navigation is automatically initiated after {@code UI.init()} if a + * navigator was created. If at a later point changes are made to the + * navigator, {@code navigator.navigateTo(navigator.getState())} may need to + * be explicitly called to ensure the current view matches the navigation + * state. + * + * @param ui + * The UI to which this Navigator is attached. + * @param stateManager + * The NavigationStateManager keeping track of the active view + * and enabling bookmarking and direct navigation or null for + * default + * @param display + * The ViewDisplay used to display the views handled by this + * navigator + */ + protected void init(UI ui, NavigationStateManager stateManager, + ViewDisplay display) { this.ui = ui; this.ui.setNavigator(this); + if (stateManager == null) { + stateManager = new UriFragmentManager(ui.getPage()); + } this.stateManager = stateManager; this.stateManager.setNavigator(this); this.display = display; |