Exemplo n.º 1
0
    void displayPageInfo(Page beanItem) {
      MVerticalLayout header = new MVerticalLayout().withMargin(false);
      Label titleLbl = new Label(beanItem.getSubject());
      titleLbl.setStyleName("headerName");
      header.with(titleLbl);
      Div footer = new Div().setStyle("width:100%").setCSSClass("footer2");
      Span lastUpdatedTimeTxt =
          new Span()
              .appendText(
                  AppContext.getMessage(
                      DayI18nEnum.LAST_UPDATED_ON,
                      AppContext.formatPrettyTime(beanItem.getLastUpdatedTime().getTime())))
              .setTitle(AppContext.formatDateTime(beanItem.getLastUpdatedTime().getTime()));
      String uid = UUID.randomUUID().toString();
      ProjectMemberService projectMemberService =
          ApplicationContextUtil.getSpringBean(ProjectMemberService.class);
      SimpleProjectMember member =
          projectMemberService.findMemberByUsername(
              beanItem.getCreatedUser(),
              CurrentProjectVariables.getProjectId(),
              AppContext.getAccountId());
      if (member != null) {
        Img userAvatar =
            new Img("", StorageFactory.getInstance().getAvatarPath(member.getMemberAvatarId(), 16));
        A userLink =
            new A()
                .setId("tag" + uid)
                .setHref(
                    ProjectLinkBuilder.generateProjectMemberFullLink(
                        member.getProjectid(), member.getUsername()))
                .appendText(StringUtils.trim(member.getMemberFullName(), 30, true));
        userLink.setAttribute(
            "onmouseover", TooltipHelper.userHoverJsFunction(uid, member.getUsername()));
        userLink.setAttribute("onmouseleave", TooltipHelper.itemMouseLeaveJsFunction(uid));
        footer.appendChild(
            lastUpdatedTimeTxt,
            new Text(" - Created by: "),
            userAvatar,
            DivLessFormatter.EMPTY_SPACE(),
            userLink,
            DivLessFormatter.EMPTY_SPACE(),
            TooltipHelper.buildDivTooltipEnable(uid));
      } else {
        footer.appendChild(lastUpdatedTimeTxt);
      }

      header.addComponent(new Label(footer.write(), ContentMode.HTML));
      this.addHeader(header);
    }
  @Override
  public Component generateRow(final SimpleComment comment, int rowIndex) {
    final MHorizontalLayout layout =
        new MHorizontalLayout()
            .withMargin(new MarginInfo(true, true, true, false))
            .withWidth("100%")
            .withStyleName("message");

    UserBlock memberBlock =
        new UserBlock(
            comment.getCreateduser(), comment.getOwnerAvatarId(), comment.getOwnerFullName());
    layout.addComponent(memberBlock);

    CssLayout rowLayout = new CssLayout();
    rowLayout.setStyleName("message-container");
    rowLayout.setWidth("100%");

    MHorizontalLayout messageHeader =
        new MHorizontalLayout()
            .withMargin(new MarginInfo(true, true, false, true))
            .withWidth("100%")
            .withStyleName("message-header");
    messageHeader.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);

    ELabel timePostLbl =
        new ELabel(
                AppContext.getMessage(
                    GenericI18Enum.EXT_ADDED_COMMENT,
                    comment.getOwnerFullName(),
                    AppContext.formatPrettyTime(comment.getCreatedtime())),
                ContentMode.HTML)
            .withDescription(AppContext.formatDateTime(comment.getCreatedtime()));

    timePostLbl.setSizeUndefined();
    timePostLbl.setStyleName("time-post");
    messageHeader.with(timePostLbl).expand(timePostLbl);

    // Message delete button
    Button msgDeleteBtn = new Button();
    msgDeleteBtn.setIcon(FontAwesome.TRASH_O);
    msgDeleteBtn.setStyleName(UIConstants.BUTTON_ICON_ONLY);
    messageHeader.addComponent(msgDeleteBtn);

    if (hasDeletePermission(comment)) {
      msgDeleteBtn.setVisible(true);
      msgDeleteBtn.addClickListener(
          new Button.ClickListener() {
            private static final long serialVersionUID = 1L;

            @Override
            public void buttonClick(Button.ClickEvent event) {
              ConfirmDialogExt.show(
                  UI.getCurrent(),
                  AppContext.getMessage(
                      GenericI18Enum.DIALOG_DELETE_TITLE, AppContext.getSiteName()),
                  AppContext.getMessage(GenericI18Enum.DIALOG_DELETE_SINGLE_ITEM_MESSAGE),
                  AppContext.getMessage(GenericI18Enum.BUTTON_YES),
                  AppContext.getMessage(GenericI18Enum.BUTTON_NO),
                  new ConfirmDialog.Listener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void onClose(ConfirmDialog dialog) {
                      if (dialog.isConfirmed()) {
                        CommentService commentService =
                            ApplicationContextUtil.getSpringBean(CommentService.class);
                        commentService.removeWithSession(
                            comment, AppContext.getUsername(), AppContext.getAccountId());
                        owner.removeRow(layout);
                      }
                    }
                  });
            }
          });
    } else {
      msgDeleteBtn.setVisible(false);
    }

    rowLayout.addComponent(messageHeader);

    Label messageContent = new SafeHtmlLabel(comment.getComment());
    messageContent.setStyleName("message-body");
    rowLayout.addComponent(messageContent);

    List<Content> attachments = comment.getAttachments();
    if (!CollectionUtils.isEmpty(attachments)) {
      MVerticalLayout messageFooter =
          new MVerticalLayout()
              .withSpacing(false)
              .withWidth("100%")
              .withStyleName("message-footer");
      AttachmentDisplayComponent attachmentDisplay = new AttachmentDisplayComponent(attachments);
      attachmentDisplay.setWidth("100%");
      messageFooter.with(attachmentDisplay).withAlign(attachmentDisplay, Alignment.MIDDLE_RIGHT);
      rowLayout.addComponent(messageFooter);
    }

    layout.with(rowLayout).expand(rowLayout);
    return layout;
  }
  public UpgradeConfirmWindow(
      final String version, String manualDownloadLink, final String installerFilePath) {
    super("A new update is ready to install");
    this.setModal(true);
    this.setResizable(false);
    this.center();
    this.setWidth("600px");
    this.installerFilePath = installerFilePath;

    currentUI = UI.getCurrent();

    MVerticalLayout content = new MVerticalLayout();
    this.setContent(content);

    Div titleDiv =
        new Div().appendText(String.format(headerTemplate, version)).setStyle("font-weight:bold");
    content.with(new Label(titleDiv.write(), ContentMode.HTML));

    Div manualInstallLink =
        new Div()
            .appendText("&nbsp;&nbsp;&nbsp;&nbsp;Manual install: ")
            .appendChild(new A(manualDownloadLink, "_blank").appendText("Download link"));
    content.with(new Label(manualInstallLink.write(), ContentMode.HTML));

    Div releaseNoteLink =
        new Div()
            .appendText("&nbsp;&nbsp;&nbsp;&nbsp;Release Notes: ")
            .appendChild(
                new A("https://community.mycollab.com/release-notes/", "_blank")
                    .appendText("Link"));
    content.with(new Label(releaseNoteLink.write(), ContentMode.HTML));

    MHorizontalLayout buttonControls = new MHorizontalLayout().withMargin(true);
    Button skipBtn =
        new Button(
            "Skip",
            new Button.ClickListener() {
              @Override
              public void buttonClick(Button.ClickEvent clickEvent) {
                UpgradeConfirmWindow.this.close();
              }
            });
    skipBtn.addStyleName(UIConstants.BUTTON_OPTION);

    Button autoUpgradeBtn =
        new Button(
            "Auto Upgrade",
            new Button.ClickListener() {
              @Override
              public void buttonClick(Button.ClickEvent clickEvent) {
                UpgradeConfirmWindow.this.close();
                navigateToWaitingUpgradePage();
              }
            });
    if (installerFilePath == null) {
      autoUpgradeBtn.setEnabled(false);
    }
    autoUpgradeBtn.addStyleName(UIConstants.BUTTON_ACTION);
    buttonControls.with(skipBtn, autoUpgradeBtn);
    content.with(buttonControls).withAlign(buttonControls, Alignment.MIDDLE_RIGHT);
  }