diff options
author | Henri Sara <hesara@vaadin.com> | 2012-06-29 15:26:32 +0300 |
---|---|---|
committer | Henri Sara <hesara@vaadin.com> | 2012-06-29 15:26:32 +0300 |
commit | 832bd0247a86a5dbfc4eed421d217db88bdd315f (patch) | |
tree | f60bea10263daad142a40f215444f0cb3c54403e /src/com | |
parent | 95697d16a6690cc407c3ddea39856c69a7b531b3 (diff) | |
parent | c13a5b75a4de7953aa9321d775262c90a4389499 (diff) | |
download | vaadin-framework-832bd0247a86a5dbfc4eed421d217db88bdd315f.tar.gz vaadin-framework-832bd0247a86a5dbfc4eed421d217db88bdd315f.zip |
Merge branch 'master' into gwt
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/vaadin/navigator/Navigator.java | 68 | ||||
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/table/VScrollTable.java | 2 |
2 files changed, 57 insertions, 13 deletions
diff --git a/src/com/vaadin/navigator/Navigator.java b/src/com/vaadin/navigator/Navigator.java index 2c340adaa2..c5e7de836a 100644 --- a/src/com/vaadin/navigator/Navigator.java +++ b/src/com/vaadin/navigator/Navigator.java @@ -14,6 +14,7 @@ import com.vaadin.terminal.Page; import com.vaadin.terminal.Page.FragmentChangedEvent; import com.vaadin.terminal.Page.FragmentChangedListener; import com.vaadin.ui.Component; +import com.vaadin.ui.ComponentContainer; import com.vaadin.ui.CssLayout; import com.vaadin.ui.CustomComponent; @@ -132,6 +133,40 @@ public class Navigator implements Serializable { } /** + * View display that replaces the contents of a {@link ComponentContainer} + * with the active {@link View}. + * + * All components of the container are removed before adding the new view to + * it. + * + * This display only supports views that are {@link Component}s themselves. + * Attempting to display a view that is not a component causes an exception + * to be thrown. + */ + public static class ComponentContainerViewDisplay implements ViewDisplay { + + private final ComponentContainer container; + + /** + * Create new {@link ViewDisplay} that updates a + * {@link ComponentContainer} to show the view. + */ + public ComponentContainerViewDisplay(ComponentContainer container) { + this.container = container; + } + + public void showView(View view) { + if (view instanceof Component) { + container.removeAllComponents(); + container.addComponent((Component) view); + } else { + throw new IllegalArgumentException("View is not a component: " + + view); + } + } + } + + /** * View provider which supports mapping a single view name to a single * pre-initialized view instance. * @@ -268,7 +303,17 @@ public class Navigator implements Serializable { private List<ViewProvider> providers = new LinkedList<ViewProvider>(); /** - * Create a navigator that is tracking the active view using URI fragments. + * Create a navigator that is tracking the active view using URI fragments + * of the current {@link Page} and replacing the contents of a + * {@link ComponentContainer} with the active view. + * + * In case the container is not on the current page, use another + * {@link Navigator#Navigator(Page, ViewDisplay)} with an explicitly created + * {@link ComponentContainerViewDisplay}. + * + * All components of the container are removed each time before adding the + * active {@link View}. Views must implement {@link Component} when using + * this constructor. * * <p> * After all {@link View}s and {@link ViewProvider}s have been registered, @@ -279,20 +324,17 @@ public class Navigator implements Serializable { * navigator.navigateTo(Page.getCurrent().getFragment()); * </pre> * - * @param page - * whose URI fragments are used - * @param display - * where to display the views + * @param container + * ComponentContainer whose contents should be replaced with the + * active view on view change */ - public Navigator(Page page, ViewDisplay display) { - this.display = display; - fragmentManager = new UriFragmentManager(page, this); + public Navigator(ComponentContainer container) { + display = new ComponentContainerViewDisplay(container); + fragmentManager = new UriFragmentManager(Page.getCurrent(), this); } /** * Create a navigator that is tracking the active view using URI fragments. - * By default, a {@link SimpleViewDisplay} is used and can be obtained using - * {@link #getDisplay()}. * * <p> * After all {@link View}s and {@link ViewProvider}s have been registered, @@ -305,9 +347,11 @@ public class Navigator implements Serializable { * * @param page * whose URI fragments are used + * @param display + * where to display the views */ - public Navigator(Page page) { - display = new SimpleViewDisplay(); + public Navigator(Page page, ViewDisplay display) { + this.display = display; fragmentManager = new UriFragmentManager(page, this); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/table/VScrollTable.java b/src/com/vaadin/terminal/gwt/client/ui/table/VScrollTable.java index 4021fc1230..e2aedd123f 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/table/VScrollTable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/table/VScrollTable.java @@ -5790,7 +5790,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, if (isDynamicHeight() && totalRows == pageLength) { // fix body height (may vary if lazy loading is offhorizontal // scrollbar appears/disappears) - int bodyHeight = Util.getRequiredHeight(scrollBody); + int bodyHeight = scrollBody.getRequiredHeight(); boolean needsSpaceForHorizontalScrollbar = (availW < usedMinimumWidth); if (needsSpaceForHorizontalScrollbar) { bodyHeight += Util.getNativeScrollbarSize(); |