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 ViewDisplay that is a component itself and replaces its contents with
- * the view.
- * <p>
- * 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.
- * <p>
- * By default, the view display has full size.
- */
- public static class SimpleViewDisplay extends CustomComponent implements
- ViewDisplay {
-
- /**
- * Create new {@link ViewDisplay} that is itself a component displaying
- * the view.
- */
- public SimpleViewDisplay() {
- setSizeFull();
- }
-
- @Override
- public void showView(View view) {
- if (view instanceof Component) {
- setCompositionRoot((Component) view);
- } else {
- throw new IllegalArgumentException("View is not a component: "
- + view);
- }
- }
- }
-
/**
* A ViewDisplay that replaces the contents of a {@link ComponentContainer}
* with the active {@link View}.
import com.vaadin.navigator.ViewProvider;
import com.vaadin.tests.server.navigator.ClassBasedViewProviderTest.TestView;
import com.vaadin.tests.server.navigator.ClassBasedViewProviderTest.TestView2;
+import com.vaadin.ui.Component;
import com.vaadin.ui.UI;
+import com.vaadin.ui.VerticalLayout;
public class NavigatorTest extends TestCase {
}
}
+ public void testComponentContainerViewDisplay() {
+ abstract class TestView implements Component, View {
+ }
+
+ TestView tv1 = EasyMock.createNiceMock(TestView.class);
+ TestView tv2 = EasyMock.createNiceMock(TestView.class);
+ EasyMock.replay(tv1, tv2);
+
+ VerticalLayout container = new VerticalLayout();
+ ViewDisplay display = new Navigator.ComponentContainerViewDisplay(
+ container);
+ Navigator navigator = createNavigator(new NullFragmentManager(),
+ display);
+
+ navigator.addView("tv1", tv1);
+ navigator.addView("tv2", tv2);
+
+ navigator.navigateTo("tv1");
+
+ assertSame(tv1, container.getComponent(0));
+ assertEquals(1, container.getComponentCount());
+
+ navigator.navigateTo("tv2");
+
+ assertSame(tv2, container.getComponent(0));
+ assertEquals(1, container.getComponentCount());
+ }
+
public void testBlockNavigation() {
IMocksControl control = EasyMock.createControl();
NavigationStateManager manager = control