Пример #1
0
  private void constructHeader() {
    pageVersionsSelection = new PageVersionSelectionBox();

    ProjectViewHeader headerLbl =
        new ProjectViewHeader(
            ProjectTypeConstants.PAGE, AppContext.getMessage(Page18InEnum.VIEW_READ_TITLE));
    headerLbl.setWidthUndefined();
    headerLbl.setStyleName(UIConstants.HEADER_TEXT);

    ((MHorizontalLayout) header).addComponent(headerLbl, 0);
    ((MHorizontalLayout) header).addComponent(pageVersionsSelection, 1);
    ((MHorizontalLayout) header)
        .withWidth("100%")
        .withStyleName("hdr-view")
        .expand(pageVersionsSelection)
        .alignAll(Alignment.MIDDLE_LEFT);
  }
Пример #2
0
 private void openEditor(Payee trans) {
   payeeEditor.setEntity(trans);
   // display next to table on desktop class screens
   if (ScreenSize.getScreenSize() == ScreenSize.LARGE) {
     mainContent.addComponent(payeeEditor);
     payeeEditor.focusFirst();
   } else {
     // Replace this view with the editor in smaller devices
     AppUI.get().getContentLayout().replaceComponent(this, payeeEditor);
   }
 }
  @SuppressWarnings("serial")
  @Override
  public void editPhoto(final byte[] imageData) {
    this.removeAllComponents();
    LOG.debug("Receive avatar upload with size: " + imageData.length);
    try {
      originalImage = ImageIO.read(new ByteArrayInputStream(imageData));
    } catch (IOException e) {
      throw new UserInvalidInputException("Invalid image type");
    }
    originalImage = ImageUtil.scaleImage(originalImage, 650, 650);

    MHorizontalLayout previewBox =
        new MHorizontalLayout()
            .withSpacing(true)
            .withMargin(new MarginInfo(false, true, true, false))
            .withWidth("100%");

    Resource defaultPhoto =
        UserAvatarControlFactory.createAvatarResource(AppContext.getUserAvatarId(), 100);
    previewImage = new Embedded(null, defaultPhoto);
    previewImage.setWidth("100px");
    previewBox.with(previewImage).withAlign(previewImage, Alignment.TOP_LEFT);

    VerticalLayout previewBoxRight = new VerticalLayout();
    previewBoxRight.setMargin(new MarginInfo(false, true, false, true));
    Label lbPreview =
        new Label(
            "<p style='margin: 0px;'><strong>To the left is what your profile photo will look like.</strong></p>"
                + "<p style='margin-top: 0px;'>To make adjustment, you can drag around and resize the selection square below. "
                + "When you are happy with your photo, click the &ldquo;Accept&ldquo; button.</p>",
            ContentMode.HTML);
    previewBoxRight.addComponent(lbPreview);

    MHorizontalLayout controlBtns = new MHorizontalLayout();
    controlBtns.setSizeUndefined();

    Button cancelBtn =
        new Button(
            AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
            new Button.ClickListener() {
              @Override
              public void buttonClick(ClickEvent event) {
                EventBusFactory.getInstance()
                    .post(new ProfileEvent.GotoProfileView(ProfilePhotoUploadViewImpl.this, null));
              }
            });
    cancelBtn.setStyleName(UIConstants.THEME_GRAY_LINK);

    Button acceptBtn =
        new Button(
            AppContext.getMessage(GenericI18Enum.BUTTON_ACCEPT),
            new Button.ClickListener() {
              @Override
              public void buttonClick(ClickEvent event) {
                if (scaleImageData != null && scaleImageData.length > 0) {
                  try {
                    BufferedImage image = ImageIO.read(new ByteArrayInputStream(scaleImageData));
                    UserAvatarService userAvatarService =
                        ApplicationContextUtil.getSpringBean(UserAvatarService.class);
                    userAvatarService.uploadAvatar(
                        image, AppContext.getUsername(), AppContext.getUserAvatarId());
                    Page.getCurrent().getJavaScript().execute("window.location.reload();");
                  } catch (IOException e) {
                    throw new MyCollabException("Error when saving user avatar", e);
                  }
                }
              }
            });
    acceptBtn.setStyleName(UIConstants.BUTTON_ACTION);
    acceptBtn.setIcon(FontAwesome.CHECK);

    controlBtns.with(acceptBtn, cancelBtn).alignAll(Alignment.MIDDLE_LEFT);

    previewBoxRight.addComponent(controlBtns);
    previewBoxRight.setComponentAlignment(controlBtns, Alignment.TOP_LEFT);

    previewBox.addComponent(previewBoxRight);
    previewBox.setExpandRatio(previewBoxRight, 1.0f);

    this.addComponent(previewBox);

    CssLayout cropBox = new CssLayout();
    cropBox.addStyleName(UIConstants.PHOTO_CROPBOX);
    cropBox.setWidth("100%");
    VerticalLayout currentPhotoBox = new VerticalLayout();
    Resource resource =
        new ByteArrayImageResource(ImageUtil.convertImageToByteArray(originalImage), "image/png");
    CropField cropField = new CropField(resource);
    cropField.setImmediate(true);
    cropField.setSelectionAspectRatio(1.0f);
    cropField.addValueChangeListener(
        new Property.ValueChangeListener() {

          @Override
          public void valueChange(Property.ValueChangeEvent event) {
            VCropSelection newSelection = (VCropSelection) event.getProperty().getValue();
            int x1 = newSelection.getXTopLeft();
            int y1 = newSelection.getYTopLeft();
            int x2 = newSelection.getXBottomRight();
            int y2 = newSelection.getYBottomRight();
            if (x2 > x1 && y2 > y1) {
              BufferedImage subImage = originalImage.getSubimage(x1, y1, (x2 - x1), (y2 - y1));
              ByteArrayOutputStream outStream = new ByteArrayOutputStream();
              try {
                ImageIO.write(subImage, "png", outStream);
                scaleImageData = outStream.toByteArray();
                displayPreviewImage();
              } catch (IOException e) {
                LOG.error("Error while scale image: ", e);
              }
            }
          }
        });
    currentPhotoBox.setWidth("650px");
    currentPhotoBox.setHeight("650px");

    currentPhotoBox.addComponent(cropField);

    cropBox.addComponent(currentPhotoBox);

    this.addComponent(previewBox);
    this.addComponent(cropBox);
    this.setExpandRatio(cropBox, 1.0f);
  }
    @Override
    public Component generateBlock(final SimpleOpportunity opportunity, int blockIndex) {
      CssLayout beanBlock = new CssLayout();
      beanBlock.addStyleName("bean-block");
      beanBlock.setWidth("350px");

      VerticalLayout blockContent = new VerticalLayout();
      MHorizontalLayout blockTop = new MHorizontalLayout().withWidth("100%");
      CssLayout iconWrap = new CssLayout();
      iconWrap.setStyleName("icon-wrap");
      FontIconLabel opportunityIcon =
          new FontIconLabel(CrmAssetsManager.getAsset(CrmTypeConstants.OPPORTUNITY));
      iconWrap.addComponent(opportunityIcon);
      blockTop.addComponent(iconWrap);

      VerticalLayout opportunityInfo = new VerticalLayout();
      opportunityInfo.setSpacing(true);

      MButton btnDelete = new MButton(FontAwesome.TRASH_O);
      btnDelete.addClickListener(
          new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent clickEvent) {
              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()) {
                        ContactService contactService =
                            ApplicationContextUtil.getSpringBean(ContactService.class);
                        ContactOpportunity associateOpportunity = new ContactOpportunity();
                        associateOpportunity.setContactid(contact.getId());
                        associateOpportunity.setOpportunityid(opportunity.getId());
                        contactService.removeContactOpportunityRelationship(
                            associateOpportunity, AppContext.getAccountId());
                        ContactOpportunityListComp.this.refresh();
                      }
                    }
                  });
            }
          });

      btnDelete.addStyleName(UIConstants.BUTTON_ICON_ONLY);

      blockContent.addComponent(btnDelete);
      blockContent.setComponentAlignment(btnDelete, Alignment.TOP_RIGHT);

      Label opportunityName =
          new Label(
              String.format(
                  "Name: <a href='%s%s'>%s</a>",
                  SiteConfiguration.getSiteUrl(AppContext.getUser().getSubdomain()),
                  CrmLinkGenerator.generateCrmItemLink(
                      CrmTypeConstants.OPPORTUNITY, opportunity.getId()),
                  opportunity.getOpportunityname()),
              ContentMode.HTML);

      opportunityInfo.addComponent(opportunityName);

      Label opportunityAmount =
          new Label("Amount: " + (opportunity.getAmount() != null ? opportunity.getAmount() : ""));
      if (opportunity.getCurrency() != null && opportunity.getAmount() != null) {
        opportunityAmount.setValue(
            opportunityAmount.getValue() + opportunity.getCurrency().getSymbol());
      }
      opportunityInfo.addComponent(opportunityAmount);

      Label opportunitySaleStage =
          new Label(
              "Sale Stage: "
                  + (opportunity.getSalesstage() != null ? opportunity.getSalesstage() : ""));
      opportunityInfo.addComponent(opportunitySaleStage);

      ELabel opportunityExpectedCloseDate =
          new ELabel(
                  "Expected Closed Date: "
                      + AppContext.formatPrettyTime(opportunity.getExpectedcloseddate()))
              .withDescription(AppContext.formatDate(opportunity.getExpectedcloseddate()));
      opportunityInfo.addComponent(opportunityExpectedCloseDate);

      blockTop.with(opportunityInfo).expand(opportunityInfo);
      blockContent.addComponent(blockTop);

      blockContent.setWidth("100%");

      beanBlock.addComponent(blockContent);
      return beanBlock;
    }
  @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 TaskDashboardViewImpl() {
    this.withMargin(new MarginInfo(false, true, true, true));
    taskSearchPanel = new TaskSearchPanel();
    MHorizontalLayout groupWrapLayout = new MHorizontalLayout();
    groupWrapLayout.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);

    groupWrapLayout.addComponent(new Label("Filter:"));
    final TaskSavedFilterComboBox savedFilterComboBox = new TaskSavedFilterComboBox();
    savedFilterComboBox.addQuerySelectListener(
        new SavedFilterComboBox.QuerySelectListener() {
          @Override
          public void querySelect(SavedFilterComboBox.QuerySelectEvent querySelectEvent) {
            List<SearchFieldInfo> fieldInfos = querySelectEvent.getSearchFieldInfos();
            TaskSearchCriteria criteria =
                SearchFieldInfo.buildSearchCriteria(TaskSearchCriteria.class, fieldInfos);
            criteria.setProjectid(new NumberSearchField(CurrentProjectVariables.getProjectId()));
            EventBusFactory.getInstance()
                .post(new TaskEvent.SearchRequest(TaskDashboardViewImpl.this, criteria));
          }
        });
    groupWrapLayout.addComponent(savedFilterComboBox);

    groupWrapLayout.addComponent(new Label("Sort:"));
    final ComboBox sortCombo = new ValueComboBox(false, DESCENDING, ASCENDING);
    sortCombo.setWidth("100px");
    sortCombo.addValueChangeListener(
        new Property.ValueChangeListener() {
          @Override
          public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            String sortValue = (String) sortCombo.getValue();
            if (ASCENDING.equals(sortValue)) {
              sortDirection = SearchCriteria.ASC;
            } else {
              sortDirection = SearchCriteria.DESC;
            }
            queryAndDisplayTasks();
          }
        });
    sortDirection = SearchCriteria.DESC;
    groupWrapLayout.addComponent(sortCombo);

    groupWrapLayout.addComponent(new Label("Group by:"));
    final ComboBox groupCombo =
        new ValueComboBox(false, GROUP_DUE_DATE, GROUP_START_DATE, PLAIN_LIST);
    groupCombo.setWidth("100px");
    groupCombo.addValueChangeListener(
        new Property.ValueChangeListener() {
          @Override
          public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            groupByState = (String) groupCombo.getValue();
            queryAndDisplayTasks();
          }
        });
    groupByState = GROUP_DUE_DATE;
    groupWrapLayout.addComponent(groupCombo);

    taskSearchPanel.addHeaderRight(groupWrapLayout);

    Button exportBtn = new Button("Export");
    final SplitButton exportSplitBtn = new SplitButton(exportBtn);
    exportBtn.addClickListener(
        new Button.ClickListener() {
          @Override
          public void buttonClick(ClickEvent event) {
            exportSplitBtn.setPopupVisible(true);
          }
        });
    exportSplitBtn.addStyleName(UIConstants.THEME_GREEN_LINK);
    OptionPopupContent popupButtonsControl = new OptionPopupContent();

    Button exportPdfBtn = new Button("PDF");
    exportPdfBtn.setIcon(FontAwesome.FILE_PDF_O);
    FileDownloader pdfFileDownloder = new FileDownloader(buildStreamSource(ReportExportType.PDF));
    pdfFileDownloder.extend(exportPdfBtn);
    popupButtonsControl.addOption(exportPdfBtn);

    Button exportExcelBtn = new Button("Excel");
    exportExcelBtn.setIcon(FontAwesome.FILE_EXCEL_O);
    FileDownloader excelFileDownloader =
        new FileDownloader(buildStreamSource(ReportExportType.EXCEL));
    excelFileDownloader.extend(exportExcelBtn);
    popupButtonsControl.addOption(exportExcelBtn);

    exportSplitBtn.setContent(popupButtonsControl);
    groupWrapLayout.with(exportSplitBtn);

    Button newTaskBtn =
        new Button(
            AppContext.getMessage(TaskI18nEnum.BUTTON_NEW_TASK),
            new Button.ClickListener() {
              private static final long serialVersionUID = 1L;

              @Override
              public void buttonClick(final ClickEvent event) {
                SimpleTask newTask = new SimpleTask();
                newTask.setProjectid(CurrentProjectVariables.getProjectId());
                UI.getCurrent().addWindow(new TaskAddWindow(newTask));
              }
            });
    newTaskBtn.setEnabled(CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.TASKS));
    newTaskBtn.setIcon(FontAwesome.PLUS);
    newTaskBtn.setDescription(AppContext.getMessage(TaskI18nEnum.BUTTON_NEW_TASKGROUP));
    newTaskBtn.setStyleName(UIConstants.THEME_GREEN_LINK);
    groupWrapLayout.addComponent(newTaskBtn);

    Button advanceDisplayBtn = new Button();
    advanceDisplayBtn.setWidth("50px");
    advanceDisplayBtn.setIcon(FontAwesome.SITEMAP);
    advanceDisplayBtn.setDescription(
        AppContext.getMessage(TaskGroupI18nEnum.ADVANCED_VIEW_TOOLTIP));

    Button calendarBtn =
        new Button(
            null,
            new Button.ClickListener() {
              @Override
              public void buttonClick(ClickEvent clickEvent) {
                EventBusFactory.getInstance()
                    .post(new TaskEvent.GotoCalendarView(TaskDashboardViewImpl.this));
              }
            });
    calendarBtn.setWidth("50px");
    calendarBtn.setDescription("Calendar View");
    calendarBtn.setIcon(FontAwesome.CALENDAR);

    Button chartDisplayBtn =
        new Button(
            null,
            new Button.ClickListener() {
              private static final long serialVersionUID = -5707546605789537298L;

              @Override
              public void buttonClick(ClickEvent event) {
                displayGanttChartView();
              }
            });
    chartDisplayBtn.setWidth("50px");
    chartDisplayBtn.setDescription("Display Gantt chart");
    chartDisplayBtn.setIcon(FontAwesome.BAR_CHART_O);

    Button kanbanBtn =
        new Button(
            null,
            new Button.ClickListener() {
              @Override
              public void buttonClick(ClickEvent clickEvent) {
                displayKanbanView();
              }
            });
    kanbanBtn.setWidth("50px");
    kanbanBtn.setDescription("Kanban View");
    kanbanBtn.setIcon(FontAwesome.TH);

    ToggleButtonGroup viewButtons = new ToggleButtonGroup();
    viewButtons.addButton(advanceDisplayBtn);
    viewButtons.addButton(calendarBtn);
    viewButtons.addButton(kanbanBtn);
    viewButtons.addButton(chartDisplayBtn);
    viewButtons.setDefaultButton(advanceDisplayBtn);
    groupWrapLayout.addComponent(viewButtons);

    mainLayout = new MHorizontalLayout().withFullHeight().withFullWidth();
    wrapBody = new MVerticalLayout().withMargin(new MarginInfo(false, true, true, false));
    rightColumn =
        new MVerticalLayout()
            .withWidth("350px")
            .withMargin(new MarginInfo(true, false, false, false));
    mainLayout.with(wrapBody, rightColumn).expand(wrapBody);
  }