예제 #1
0
 @Override
 protected void init(VaadinRequest vaadinRequest) {
   Navigator navigator = new Navigator(this, this);
   navigator.setErrorView(errorView);
   navigator.addProvider(viewProvider);
   setNavigator(navigator);
 }
 @PostConstruct
 public void initialize() {
   if (ui.getNavigator() == null) {
     Navigator navigator = new Navigator(ui, ui);
     navigator.addProvider(viewProvider);
     navigator.setErrorView(errorView);
   }
 }
예제 #3
0
  /** Registers av given view to the navigator and adds it to the NavBar */
  private void addView(Class<? extends View> viewClass) {
    ViewConfig viewConfig = viewClass.getAnnotation(ViewConfig.class);

    switch (viewConfig.createMode()) {
      case ALWAYS_NEW:
        navigator.addView(viewConfig.uri(), viewClass);
        break;
      case LAZY_INIT:
        navigator.addProvider(new LazyProvider(viewConfig.uri(), viewClass));
        break;
      case EAGER_INIT:
        try {
          navigator.addView(viewConfig.uri(), viewClass.newInstance());
        } catch (Exception e) {
          e.printStackTrace();
        }
    }
    navBar.addView(viewConfig.uri(), viewConfig.displayName());
  }
예제 #4
0
  @Override
  protected void init(VaadinRequest request) {
    setLocale(Locale.ENGLISH);
    // Let's register a custom error handler to make the 'access denied' messages a bit friendlier.
    setErrorHandler(
        new DefaultErrorHandler() {
          @Override
          public void error(com.vaadin.server.ErrorEvent event) {
            if (SecurityExceptionUtils.isAccessDeniedException(event.getThrowable())) {
              Notification.show("Sorry, you don't have access to do that.");
            } else {
              super.error(event);
            }
          }
        });

    VerticalLayout layout = new VerticalLayout();
    Panel viewContent = new Panel();
    MenuBar menu = new MenuBar();
    menu.addStyleName("navigation-menu");

    layout.addComponents(menu, viewContent);
    layout.setSizeFull();
    viewContent.setSizeFull();
    layout.setExpandRatio(viewContent, 1);

    menu.addItem("Trading Area", e -> onDashboardClicked());
    menu.addItem("Users", e -> onCustomersClicked());

    navigator = new Navigator(this, viewContent);
    springViewProvider.setAccessDeniedViewClass(AccessDeniedView.class);
    navigator.addProvider(springViewProvider);
    navigator.setErrorView(ErrorView.class);
    setContent(layout);
    String state = navigator.getState();
    if (state != null && !state.isEmpty()) {
      navigator.navigateTo(state);
    } else {
      navigator.navigateTo(TradingAreaView.NAME);
    }
  }