@Override
  protected Component initContent() {
    ResourceService resourceService = ApplicationContextUtil.getSpringBean(ResourceService.class);
    List<Content> attachments =
        resourceService.getContents(
            AttachmentUtils.getProjectEntityAttachmentPath(
                AppContext.getAccountId(), projectid, type, typeid));
    if (CollectionUtils.isNotEmpty(attachments)) {
      VerticalLayout comp = new VerticalLayout();
      comp.setStyleName("attachment-view-panel");

      for (final Content attachment : attachments) {
        String docName = attachment.getPath();
        int lastIndex = docName.lastIndexOf("/");
        if (lastIndex != -1) {
          docName = docName.substring(lastIndex + 1, docName.length());
        }

        if (MimeTypesUtil.isImageType(docName)) {
          Button b =
              new Button(
                  attachment.getTitle(),
                  new Button.ClickListener() {

                    private static final long serialVersionUID = 293396615972447886L;

                    @Override
                    public void buttonClick(Button.ClickEvent event) {
                      AttachmentPreviewView previewView =
                          new AttachmentPreviewView(
                              VaadinResourceManager.getResourceManager()
                                  .getImagePreviewResource(attachment.getPath(), DEFAULT_SOURCE));
                      EventBusFactory.getInstance()
                          .post(new ShellEvent.PushView(this, previewView));
                    }
                  });
          b.setWidth("100%");
          comp.addComponent(b);
        } else {
          Label l = new Label(attachment.getTitle());
          l.setWidth("100%");
          comp.addComponent(l);
        }
      }

      return comp;
    }
    return new Label("&nbsp;", ContentMode.HTML);
  }
    @Override
    public Component generateRow(final SimpleMessage message, final int rowIndex) {
      final HorizontalLayout messageLayout = new HorizontalLayout();
      messageLayout.setStyleName("message");
      messageLayout.setSpacing(true);
      if (message.getIsstick() != null && message.getIsstick()) {
        messageLayout.addStyleName("important-message");
      }
      messageLayout.setWidth("100%");
      VerticalLayout userBlock = new VerticalLayout();
      userBlock.setDefaultComponentAlignment(Alignment.TOP_CENTER);
      userBlock.setWidth("80px");
      userBlock.setSpacing(true);
      userBlock.addComponent(
          UserAvatarControlFactory.createUserAvatarButtonLink(
              message.getPostedUserAvatarId(), message.getFullPostedUserName()));
      Label userName = new Label(message.getFullPostedUserName());
      userName.setStyleName("user-name");
      userBlock.addComponent(userName);
      messageLayout.addComponent(userBlock);

      final CssLayout rowLayout = new CssLayout();
      rowLayout.setStyleName("message-container");
      rowLayout.setWidth("100%");
      final Button title =
          new Button(
              message.getTitle(),
              new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(final ClickEvent event) {
                  EventBus.getInstance()
                      .fireEvent(
                          new MessageEvent.GotoRead(MessageListViewImpl.this, message.getId()));
                }
              });

      title.setWidth("550px");
      title.setStyleName("link");
      title.addStyleName(UIConstants.WORD_WRAP);

      final HorizontalLayout messageHeader = new HorizontalLayout();
      messageHeader.setStyleName("message-header");
      messageHeader.setMargin(new MarginInfo(true, true, false, true));
      final VerticalLayout leftHeader = new VerticalLayout();

      title.addStyleName("message-title");
      leftHeader.addComponent(title);

      final HorizontalLayout rightHeader = new HorizontalLayout();
      rightHeader.setSpacing(true);

      final Label timePostLbl =
          new Label(DateTimeUtils.getStringDateFromNow(message.getPosteddate()));
      timePostLbl.setSizeUndefined();
      timePostLbl.setStyleName("time-post");

      final HorizontalLayout notification = new HorizontalLayout();
      notification.setStyleName("notification");
      notification.setSizeUndefined();
      notification.setSpacing(true);
      if (message.getCommentsCount() > 0) {
        final HorizontalLayout commentNotification = new HorizontalLayout();
        final Label commentCountLbl = new Label(Integer.toString(message.getCommentsCount()));
        commentCountLbl.setStyleName("comment-count");
        commentCountLbl.setSizeUndefined();
        commentNotification.addComponent(commentCountLbl);
        final Image commentIcon =
            new Image(null, MyCollabResource.newResource("icons/16/project/message.png"));
        commentNotification.addComponent(commentIcon);

        notification.addComponent(commentNotification);
      }
      ResourceService attachmentService =
          ApplicationContextUtil.getSpringBean(ResourceService.class);
      List<Content> attachments =
          attachmentService.getContents(
              AttachmentUtils.getProjectEntityAttachmentPath(
                  AppContext.getAccountId(),
                  message.getProjectid(),
                  AttachmentType.PROJECT_MESSAGE,
                  message.getId()));
      if (attachments != null && !attachments.isEmpty()) {
        final HorizontalLayout attachmentNotification = new HorizontalLayout();
        final Label attachmentCountLbl = new Label(Integer.toString(attachments.size()));
        attachmentCountLbl.setStyleName("attachment-count");
        attachmentCountLbl.setSizeUndefined();
        attachmentNotification.addComponent(attachmentCountLbl);
        final Image attachmentIcon =
            new Image(null, MyCollabResource.newResource("icons/16/attachment.png"));
        attachmentNotification.addComponent(attachmentIcon);

        notification.addComponent(attachmentNotification);
      }

      Button deleteBtn =
          new Button(
              "",
              new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(ClickEvent event) {
                  ConfirmDialogExt.show(
                      UI.getCurrent(),
                      LocalizationHelper.getMessage(
                          GenericI18Enum.DELETE_DIALOG_TITLE, SiteConfiguration.getSiteName()),
                      LocalizationHelper.getMessage(
                          GenericI18Enum.CONFIRM_DELETE_RECORD_DIALOG_MESSAGE),
                      LocalizationHelper.getMessage(GenericI18Enum.BUTTON_YES_LABEL),
                      LocalizationHelper.getMessage(GenericI18Enum.BUTTON_NO_LABEL),
                      new ConfirmDialog.Listener() {
                        private static final long serialVersionUID = 1L;

                        @Override
                        public void onClose(final ConfirmDialog dialog) {
                          if (dialog.isConfirmed()) {
                            final MessageService messageService =
                                ApplicationContextUtil.getSpringBean(MessageService.class);
                            messageService.removeWithSession(
                                message.getId(),
                                AppContext.getUsername(),
                                AppContext.getAccountId());
                            MessageListViewImpl.this.tableItem.setSearchCriteria(searchCriteria);
                          }
                        }
                      });
                }
              });
      deleteBtn.setIcon(MyCollabResource.newResource("icons/12/project/icon_x.png"));
      deleteBtn.addStyleName("link");
      deleteBtn.setEnabled(
          CurrentProjectVariables.canAccess(ProjectRolePermissionCollections.MESSAGES));

      rightHeader.addComponent(timePostLbl);
      rightHeader.addComponent(deleteBtn);
      rightHeader.setExpandRatio(timePostLbl, 1.0f);

      messageHeader.addComponent(leftHeader);
      messageHeader.setExpandRatio(leftHeader, 1.0f);
      messageHeader.addComponent(rightHeader);
      messageHeader.setWidth("100%");

      rowLayout.addComponent(messageHeader);

      final Label messageContent =
          new Label(StringUtils.formatExtraLink(message.getMessage()), ContentMode.HTML);
      messageContent.setStyleName("message-body");
      rowLayout.addComponent(messageContent);

      if (notification.getComponentCount() > 0) {
        VerticalLayout messageFooter = new VerticalLayout();
        messageFooter.setWidth("100%");
        messageFooter.setStyleName("message-footer");
        messageFooter.addComponent(notification);
        messageFooter.setMargin(true);
        messageFooter.setComponentAlignment(notification, Alignment.MIDDLE_RIGHT);
        rowLayout.addComponent(messageFooter);
      }

      messageLayout.addComponent(rowLayout);
      messageLayout.setExpandRatio(rowLayout, 1.0f);

      return messageLayout;
    }