Ejemplo n.º 1
0
  public void loadTable(InputStream in, String fileName, String mimeType) {
    //        String uploadDate = dateTimeFormatHelper.getDayMonthYear(new Date());
    String fileId = storageService.save(in, mimeType, fileName);
    Set<String> files = updateEmpDetails(fileId);

    for (String filesId : files) {

      Button download = new Button("Download");
      download.setStyleName(Reindeer.BUTTON_LINK);
      download.setData(filesId);

      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(filesId);
      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(filesId).getFilename(), download, delete,
          },
          filesId);
    }
    // Allow selecting items from the table.
    setNullSelectionAllowed(false);
    setSelectable(true);
    // Send changes in selection immediately to server.
    setImmediate(true);
  }
Ejemplo n.º 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);
  }