Example #1
0
  void openLogoutWindow() {
    Window logout = new Window(getPbMessages("btnLogout"));
    logout.setModal(true);
    //        logout.setStyleName(Reindeer.WINDOW_BLACK);
    logout.setWidth("260px");
    logout.setResizable(false);
    logout.setClosable(false);
    logout.setDraggable(false);
    logout.setCloseShortcut(KeyCode.ESCAPE, null);

    Label helpText = new Label("Are you sure you want to log out?", Label.CONTENT_XHTML);
    logout.addComponent(helpText);

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);
    Button yes =
        new Button(
            getPbMessages("btnLogout"),
            new Button.ClickListener() {

              public void buttonClick(ClickEvent event) {

                PbApplication app = (PbApplication) getApplication();
                app.setUser(null);
                Cookie cookie = null;
                for (Cookie c : app.getHttpServletRequest().getCookies()) {
                  if ("username".equals(c.getName())) {
                    cookie = c;
                    break;
                  }
                }
                if (cookie != null) {
                  Cookie del = new Cookie("username", "");
                  cookie.setMaxAge(0); // Delete
                  app.getHttpServletResponse().addCookie(del);
                }
                WebApplicationContext applicationContext =
                    (WebApplicationContext) getApplication().getContext();
                getApplication().close();
                applicationContext.getHttpSession().invalidate();
              }
            });
    yes.setStyleName(Reindeer.BUTTON_DEFAULT);
    yes.focus();
    buttons.addComponent(yes);
    Button no =
        new Button(
            getPbMessages("btnCancel"),
            new Button.ClickListener() {

              public void buttonClick(ClickEvent event) {
                removeWindow(event.getButton().getWindow());
              }
            });
    buttons.addComponent(no);

    logout.addComponent(buttons);
    ((VerticalLayout) logout.getContent()).setComponentAlignment(buttons, Alignment.MIDDLE_CENTER);
    ((VerticalLayout) logout.getContent()).setSpacing(true);

    addWindow(logout);
  }
Example #2
0
  private void openNotificationsPopup(final ClickEvent event) {
    VerticalLayout notificationsLayout = new VerticalLayout();

    Label title = new Label("Notifications");
    title.addStyleName(ValoTheme.LABEL_H3);
    title.addStyleName(ValoTheme.LABEL_NO_MARGIN);
    notificationsLayout.addComponent(title);

    Collection<DashboardNotification> notifications =
        DashboardUI.getDataProvider().getNotifications();
    DashboardEventBus.post(new NotificationsCountUpdatedEvent());

    for (DashboardNotification notification : notifications) {
      VerticalLayout notificationLayout = new VerticalLayout();
      notificationLayout.setMargin(false);
      notificationLayout.setSpacing(false);
      notificationLayout.addStyleName("notification-item");

      Label titleLabel =
          new Label(
              notification.getFirstName()
                  + " "
                  + notification.getLastName()
                  + " "
                  + notification.getAction());
      titleLabel.addStyleName("notification-title");

      Label timeLabel = new Label(notification.getPrettyTime());
      timeLabel.addStyleName("notification-time");

      Label contentLabel = new Label(notification.getContent());
      contentLabel.addStyleName("notification-content");

      notificationLayout.addComponents(titleLabel, timeLabel, contentLabel);
      notificationsLayout.addComponent(notificationLayout);
    }

    HorizontalLayout footer = new HorizontalLayout();
    footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);
    footer.setWidth("100%");
    footer.setSpacing(false);
    Button showAll =
        new Button(
            "View All Notifications",
            new ClickListener() {
              @Override
              public void buttonClick(final ClickEvent event) {
                Notification.show("Not implemented in this demo");
              }
            });
    showAll.addStyleName(ValoTheme.BUTTON_BORDERLESS_COLORED);
    showAll.addStyleName(ValoTheme.BUTTON_SMALL);
    footer.addComponent(showAll);
    footer.setComponentAlignment(showAll, Alignment.TOP_CENTER);
    notificationsLayout.addComponent(footer);

    if (notificationsWindow == null) {
      notificationsWindow = new Window();
      notificationsWindow.setWidth(300.0f, Unit.PIXELS);
      notificationsWindow.addStyleName("notifications");
      notificationsWindow.setClosable(false);
      notificationsWindow.setResizable(false);
      notificationsWindow.setDraggable(false);
      notificationsWindow.setCloseShortcut(KeyCode.ESCAPE, null);
      notificationsWindow.setContent(notificationsLayout);
    }

    if (!notificationsWindow.isAttached()) {
      notificationsWindow.setPositionY(event.getClientY() - event.getRelativeY() + 40);
      getUI().addWindow(notificationsWindow);
      notificationsWindow.focus();
    } else {
      notificationsWindow.close();
    }
  }