Example usage for com.vaadin.navigator ViewDisplay ViewDisplay

List of usage examples for com.vaadin.navigator ViewDisplay ViewDisplay

Introduction

In this page you can find the example usage for com.vaadin.navigator ViewDisplay ViewDisplay.

Prototype

ViewDisplay

Source Link

Usage

From source file:org.lucidj.ui.gauss.GaussUI.java

License:Apache License

protected void initNavigator(UI ui) {
    navigator = new SafeNavigator(ui, new ViewDisplay() {
        @Override/*from   w  w w . ja  va2s. co  m*/
        public void showView(View view) {
            if (view instanceof com.vaadin.ui.Component) {
                set_contents((com.vaadin.ui.Component) view);
            } else {
                String msg = "Invalid component:\n" + view.getClass().getCanonicalName();
                set_contents(emptyContents);
            }
        }
    });

    //        navigator.setErrorView (FancyEmptyView.class);  ---> make it better
    navigator.addView(DAMN, damage_report_view);
    nav_manager.configureNavigator(navigator, null);

    navigator.addViewChangeListener(new ViewChangeListener() {
        @Override
        public boolean beforeViewChange(final ViewChangeEvent event) {
            if (false /* go somewhere else */) {
                navigator.navigateTo("neverland");
                return (false);
            }

            // Go ahead
            return (true);
        }

        @Override
        public void afterViewChange(final ViewChangeEvent event) {
            String navid = event.getViewName();

            // TODO: BUBBLE EVENT INTO PROPER MenuInstance
            //                highlight_menu_item(navid);

            View new_view = event.getNewView();
            AbstractComponent sidebar = null;
            AbstractComponent toolbar = null;

            // TODO: CHANGE TO Aggregates
            if (new_view instanceof ApplicationInterface) {
                ApplicationInterface app_view = (ApplicationInterface) new_view;

                sidebar = app_view.getSidebar();
                toolbar = app_view.getToolbar();
            }

            log.debug("Sidebar navid:{} = {}", navid, sidebar);
            log.debug("Toolbar navid:{} = {}", navid, toolbar);

            //---------------
            // Place sidebar
            //---------------

            set_sidebar(sidebar);

            //---------------
            // Place toolbar
            //---------------

            hToolbarPlaceholder.removeAllComponents();

            if (toolbar != null) {
                // Attach a new toolbar
                hToolbarPlaceholder.addComponent(toolbar);
            }

            // TODO: FIGURE OUT THE DESTINY OF THIS
            // This exists to autohide responsive sandwich menu.
            //menu.removeStyleName ("valo-menu-visible");
        }
    });

    // Start on default Home
    navigator.navigateTo("home");
}

From source file:org.vaadin.spring.samples.sidebar.SideBarUI.java

License:Apache License

@Override
protected void init(VaadinRequest vaadinRequest) {
    getPage().setTitle("Vaadin4Spring Side Bar Sample");
    final HorizontalSplitPanel rootLayout = new HorizontalSplitPanel();
    rootLayout.setStyleName(Reindeer.SPLITPANEL_SMALL);
    rootLayout.setSizeFull();/*from  w  ww .j a v a 2s .c  om*/
    setContent(rootLayout);

    final Navigator navigator = new Navigator(this, new ViewDisplay() {
        @Override
        public void showView(View view) {
            System.out.println("Showing view " + view);
            rootLayout.setSecondComponent((com.vaadin.ui.Component) view);
        }
    });
    navigator.setErrorView(new ErrorView());
    navigator.addProvider(viewProvider);
    setNavigator(navigator);

    rootLayout.setFirstComponent(sideBar);
    rootLayout.setSplitPosition(150, Unit.PIXELS);
}