aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/main/java/com/vaadin/navigator
diff options
context:
space:
mode:
authorArtur <artur@vaadin.com>2017-06-12 13:19:12 +0300
committerIlia Motornyi <elmot@vaadin.com>2017-06-12 13:19:12 +0300
commit585c9ec24dc6f71f008218929aa91cabdc54c000 (patch)
treeb40a76fd6476be23db151158f9556faefc90aad7 /server/src/main/java/com/vaadin/navigator
parentf8f8cc0385acc3d205de16d3183dd1fc410524a1 (diff)
downloadvaadin-framework-585c9ec24dc6f71f008218929aa91cabdc54c000.tar.gz
vaadin-framework-585c9ec24dc6f71f008218929aa91cabdc54c000.zip
Add support for Views which are not components
Diffstat (limited to 'server/src/main/java/com/vaadin/navigator')
-rw-r--r--server/src/main/java/com/vaadin/navigator/Navigator.java16
-rw-r--r--server/src/main/java/com/vaadin/navigator/View.java20
2 files changed, 22 insertions, 14 deletions
diff --git a/server/src/main/java/com/vaadin/navigator/Navigator.java b/server/src/main/java/com/vaadin/navigator/Navigator.java
index 567c271211..2341479832 100644
--- a/server/src/main/java/com/vaadin/navigator/Navigator.java
+++ b/server/src/main/java/com/vaadin/navigator/Navigator.java
@@ -170,13 +170,8 @@ public class Navigator implements Serializable {
@Override
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);
- }
+ container.removeAllComponents();
+ container.addComponent(view.getViewComponent());
}
}
@@ -204,12 +199,7 @@ public class Navigator implements Serializable {
@Override
public void showView(View view) {
- if (view instanceof Component) {
- container.setContent((Component) view);
- } else {
- throw new IllegalArgumentException(
- "View is not a component: " + view);
- }
+ container.setContent(view.getViewComponent());
}
}
diff --git a/server/src/main/java/com/vaadin/navigator/View.java b/server/src/main/java/com/vaadin/navigator/View.java
index 8e083c6833..72e60dfdc4 100644
--- a/server/src/main/java/com/vaadin/navigator/View.java
+++ b/server/src/main/java/com/vaadin/navigator/View.java
@@ -25,7 +25,8 @@ import com.vaadin.ui.Component;
* Interface for all views controlled by the navigator.
*
* Each view added to the navigator must implement this interface. Typically, a
- * view is a {@link Component}.
+ * view is a {@link Component}, if it is not then you should override
+ * {@link #getViewComponent()} to define the component to show for the view.
*
* @author Vaadin Ltd
* @since 7.0
@@ -46,4 +47,21 @@ public interface View extends Serializable {
*
*/
public void enter(ViewChangeEvent event);
+
+ /**
+ * Gets the component to show when navigating to the view.
+ *
+ * By default casts this View to a {@link Component} if possible, otherwise
+ * throws an IllegalStateException.
+ *
+ * @since
+ * @return the component to show, by default the view instance itself
+ */
+ public default Component getViewComponent() {
+ if (!(this instanceof Component)) {
+ throw new IllegalStateException(
+ "View is not a Component. Override getViewComponent() to return the root view component");
+ }
+ return (Component) this;
+ }
}