Ejemplo n.º 1
0
    @Override
    public ComponentContainer getLayout() {
      String title =
          (user.getUsername() == null)
              ? AppContext.getMessage(UserI18nEnum.VIEW_NEW_USER)
              : user.getDisplayName();
      final AddViewLayout formAddLayout = new AddViewLayout(title, FontAwesome.USER);

      final VerticalLayout layout = new VerticalLayout();
      final Label organizationHeader =
          new Label(AppContext.getMessage(UserI18nEnum.SECTION_BASIC_INFORMATION));
      organizationHeader.setStyleName("h2");
      layout.addComponent(organizationHeader);

      this.basicInformationLayout =
          new GridFormLayoutHelper(2, 1, "100%", "167px", Alignment.TOP_LEFT);
      this.basicInformationLayout.getLayout().setWidth("100%");
      this.basicInformationLayout.getLayout().setMargin(false);
      this.basicInformationLayout.getLayout().addStyleName(UIConstants.COLORED_GRIDLAYOUT);

      layout.addComponent(this.basicInformationLayout.getLayout());

      formAddLayout.addHeaderRight(createButtonControls());
      formAddLayout.addBody(layout);
      formAddLayout.addBottomControls(createBottomPanel());
      return formAddLayout;
    }
    @Override
    public ComponentContainer getLayout() {
      VerticalLayout formLayout = new VerticalLayout();
      formLayout.setDefaultComponentAlignment(Alignment.TOP_CENTER);

      Label organizationHeader =
          new Label(AppContext.getMessage(ContactI18nEnum.SECTION_DESCRIPTION));
      organizationHeader.setStyleName(UIConstants.H2_STYLE2);
      formLayout.addComponent(organizationHeader);

      informationLayout = GridFormLayoutHelper.defaultFormLayoutHelper(2, 6);
      formLayout.addComponent(informationLayout.getLayout());

      addressLayout = GridFormLayoutHelper.defaultFormLayoutHelper(2, 6);
      Label addressHeader = new Label(AppContext.getMessage(ContactI18nEnum.SECTION_ADDRESS));
      addressHeader.setStyleName(UIConstants.H2_STYLE2);
      formLayout.addComponent(addressHeader);
      formLayout.addComponent(addressLayout.getLayout());
      formLayout.addComponent(buildButtonControls());
      return formLayout;
    }
  @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;
  }