Пример #1
0
  public void deleteFile(String filename) {
    EmployeeDetail detail = person.getEmployeeDetails();
    Set<String> files = new HashSet<>();
    files.addAll(detail.getFiles());
    files.remove(filename);

    EmployeeDetail newDetail = getEmployeeDetail(detail, files);
    EmployeeDetailFacade.getEmployeeDetailService().merge(newDetail);
    Person newPerson = getPerson(person, newDetail);
    PersonFacade.getPersonService().merge(newPerson);
  }
Пример #2
0
  public PersonUploadTable(
      final MshenguMain main, final Person person, final VerticalLayout content) {
    this.main = main;
    this.person = person;

    addContainerProperty("File Name", String.class, null);
    addContainerProperty("Download", Button.class, null);
    addContainerProperty("Delete", Button.class, null);

    EmployeeDetail detail = person.getEmployeeDetails();
    if (detail.getFiles() != null) {
      for (final String fileId : detail.getFiles()) {
        final Button download = new Button("Download");
        download.setStyleName(Reindeer.BUTTON_LINK);
        download.setData(fileId);

        download.addClickListener(
            new Button.ClickListener() {
              @Override
              public void buttonClick(Button.ClickEvent event) {
                PersonFilesgeUtil personFilesgeUtil = new PersonFilesgeUtil(fileId);
                StreamResource.StreamSource imageSource = personFilesgeUtil;
                StreamResource resource =
                    new StreamResource(imageSource, personFilesgeUtil.getFileName());
                FileDownloader fileDownloader = new FileDownloader(resource);
                fileDownloader.extend(download);
              }
            });
        Button delete = new Button("Delete");
        delete.setStyleName(Reindeer.BUTTON_LINK);
        delete.setData(fileId);
        delete.addClickListener(
            new Button.ClickListener() {
              @Override
              public void buttonClick(Button.ClickEvent event) {
                deleteFile((String) event.getButton().getData());
                removeItem((String) event.getButton().getData());
              }
            });

        addItem(
            new Object[] {
              storageService.getById(fileId).getFilename(), download, delete,
            },
            fileId);
      }
    }

    setNullSelectionAllowed(false);
    setSelectable(true);
    // Send changes in selection immediately to server.
    setImmediate(true);
  }
Пример #3
0
 private Set<String> updateEmpDetails(String fileId) {
   EmployeeDetail detail = person.getEmployeeDetails();
   Set<String> files = new HashSet<>();
   if (detail.getFiles() != null) {
     files = detail.getFiles();
   }
   files.add(fileId);
   EmployeeDetail newDetail = getEmployeeDetail(detail, files);
   EmployeeDetailFacade.getEmployeeDetailService().merge(newDetail);
   Person newPerson = getPerson(person, newDetail);
   PersonFacade.getPersonService().merge(newPerson);
   return newDetail.getFiles();
 }
Пример #4
0
 public EmployeeDetail getEmployeeDetail(EmployeeDetail detail, Set<String> files) {
   EmployeeDetail newDetail =
       new EmployeeDetail.Builder(detail.getId()).EmployeeDetails(detail).files(files).build();
   return newDetail;
 }