예제 #1
0
  private void setupNavigator() {
    navigator = new Navigator(DemoUI.getCurrent(), content);

    registerViews();

    // Add view change listeners so we can do things like select the correct menu item and update
    // the page title
    navigator.addViewChangeListener(navBar);
    navigator.addViewChangeListener(new PageTitleUpdater());

    navigator.navigateTo(navigator.getState());
  }
  public MainView() {
    Navigator navigator = new Navigator(UI.getCurrent(), scroll_panel);
    navigator.addView(DashboardView.VIEW_NAME, DashboardView.class);
    navigator.addView(OrderView.VIEW_NAME, OrderView.class);
    navigator.addView(AboutView.VIEW_NAME, AboutView.class);
    if (navigator.getState().isEmpty()) {
      navigator.navigateTo(DashboardView.VIEW_NAME);
    }

    //		menuButton1.addClickListener(event -> scroll_panel.setContent(new DashboardView()));
    //        menuButton2.addClickListener(event -> scroll_panel.setContent(new OrderView()));
    //        menuButton3.addClickListener(event -> scroll_panel.setContent(new AboutView()));

    menuButton1.addClickListener(event -> doNavigate(DashboardView.VIEW_NAME));
    menuButton2.addClickListener(event -> doNavigate(OrderView.VIEW_NAME));
    menuButton3.addClickListener(event -> doNavigate(AboutView.VIEW_NAME));
  }
  public void checkAccessRestrictionForRequestedView(Navigator navigator) {
    final View targetView = viewProvider.getView(navigator.getState());

    if (targetView != null) {
      final Collection<ConfigAttribute> attributes =
          new SecuredAnnotationSecurityMetadataSource()
              .getAttributes(
                  new SimpleMethodInvocation(
                      targetView,
                      ReflectionUtils.findMethod(
                          View.class, "enter", ViewChangeListener.ViewChangeEvent.class)));
      try {
        accessDecisionManager.decide(
            SecurityContextHolder.getContext().getAuthentication(), targetView, attributes);
      } catch (AccessDeniedException adExc) {
        // must be ignored as this exception is already handled in the AccessDecisionManager
      }
    }
  }
예제 #4
0
  /**
   * Internal initialization method, should not be overridden. This method is not declared as final
   * because that would break compatibility with e.g. CDI.
   *
   * @param request the initialization request
   * @param uiId the id of the new ui
   */
  public void doInit(VaadinRequest request, int uiId) {
    if (this.uiId != -1) {
      throw new IllegalStateException("UI id has already been defined");
    }
    this.uiId = uiId;

    // Actual theme - used for finding CustomLayout templates
    theme = request.getParameter("theme");

    getPage().init(request);

    // Call the init overridden by the application developer
    init(request);

    Navigator navigator = getNavigator();
    if (navigator != null) {
      // Kickstart navigation if a navigator was attached in init()
      navigator.navigateTo(navigator.getState());
    }
  }
예제 #5
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);
    }
  }