예제 #1
0
 public List<String> getNames() {
   final List<String> names = Lists.newArrayList();
   for (ListGridRecord record : filesGrid.getRecords()) {
     names.add(record.getAttributeAsString("name"));
   }
   return names;
 }
예제 #2
0
 public CanUpload canUpload() {
   final CanUpload canUpload;
   if (filesGrid.getDataAsRecordList().isEmpty()) {
     canUpload = CanUpload.cannotUpload("No files selected");
   } else {
     canUpload = CanUpload.canUpload();
   }
   return canUpload;
 }
예제 #3
0
 public int getNumSelectedFiles() {
   final ListGridRecord[] records = filesGrid.getRecords();
   return records == null ? 0 : records.length;
 }
예제 #4
0
    FlashUploadComponentImpl(final UploadComponentOptions options) {
      filesGrid.setHeight(100);
      filesGrid.setWidth100();
      if (options.isAllowMultiple()) {
        filesGrid.setEmptyMessage("No files selected.");
      } else {
        filesGrid.setEmptyMessage("File not selected.");
      }
      final ListGridField nameField = new ListGridField("name", "File Name");
      nameField.setType(ListGridFieldType.TEXT);
      nameField.setWidth("*");

      filesGrid.setFields(nameField);

      final UploadBuilder builder = new UploadBuilder();
      // Configure which file types may be selected
      if (options.getTypes() != null) {
        builder.setFileTypes(options.getTypes());
      }
      if (options.getTypesDescription() != null) {
        builder.setFileTypesDescription(options.getTypesDescription());
      }
      if (options.getTypesDescription() != null) {
        builder.setFileTypesDescription(options.getTypesDescription());
      }
      clientId = getUniqueId();

      final HTMLPane pane = new HTMLPane();
      pane.setHeight(22);
      builder.setButtonPlaceholderID(clientId);
      builder.setButtonHeight(22);
      builder.setButtonWidth(100);
      pane.setWidth(100);
      if (options.isAllowMultiple()) {
        builder.setButtonImageURL(GWT.getHostPageBaseURL() + "images/uploadImageAddFiles.jpg");
      } else {
        builder.setButtonImageURL(GWT.getHostPageBaseURL() + "images/uploadImageChooseFile.jpg");
      }
      // Use ButtonAction.SELECT_FILE to only allow selection of a single file

      builder.setButtonAction(
          options.isAllowMultiple() ? ButtonAction.SELECT_FILES : ButtonAction.SELECT_FILE);
      builder.setFileQueuedHandler(
          new FileQueuedHandler() {
            public void onFileQueued(final FileQueuedEvent queuedEvent) {
              if (!options.isAllowMultiple()) {
                SmartUtils.removeAllRecords(filesGrid);
              }
              final ListGridRecord record = new ListGridRecord();
              record.setAttribute("id", queuedEvent.getFile().getId());
              record.setAttribute("name", queuedEvent.getFile().getName());
              filesGrid.addData(record);
            }
          });
      builder.setUploadSuccessHandler(
          new UploadSuccessHandler() {
            public void onUploadSuccess(final UploadSuccessEvent uploadEvent) {
              try {
                filesUploaded++;
                bytesUploaded += uploadEvent.getFile().getSize();
                final String serverResponse = uploadEvent.getServerData();
                fileSources.addAll(toFileSources(serverResponse));
                updateUrl();
                if (upload.getStats().getFilesQueued() > 0) {
                  upload.startUpload();
                } else {
                  options.getCompletionCallback().onSuccess(fileSources);
                }
              } catch (final Exception e) {
                options.getCompletionCallback().onFailure(e);
              }
            }
          });
      builder.setUploadErrorHandler(
          new UploadErrorHandler() {
            public void onUploadError(final UploadErrorEvent e) {
              options
                  .getCompletionCallback()
                  .onFailure(new Exception("Upload failed " + e.getMessage()));
            }
          });

      // The button to start the transfer
      final Layout parent = getParentCanvas(options);
      setWidget(parent);

      // pane.setMargin(5);
      pane.setContents("<span id=\"" + clientId + "\" />");
      reg =
          get()
              .addDrawHandler(
                  new DrawHandler() {
                    public void onDraw(final DrawEvent event) {
                      upload = builder.build();
                      reg.removeHandler();
                    }
                  });
      final Button removeButton = SmartUtils.getButton("Remove File", Resources.CROSS);
      removeButton.addClickHandler(
          new ClickHandler() {
            public void onClick(final ClickEvent event) {
              final ListGridRecord record = filesGrid.getSelectedRecord();
              final String id = record.getAttribute("id");
              filesGrid.removeData(record);
              upload.cancelUpload(id, false);
            }
          });
      SmartUtils.enabledWhenHasSelection(removeButton, filesGrid);
      removeButton.setDisabled(true);
      if (!options.isAllowMultiple()) {
        removeButton.hide();
      }

      final CanvasWithOpsLayout<ClientListGrid> layout =
          new CanvasWithOpsLayout<ClientListGrid>(filesGrid, pane, removeButton);
      if (debug) {
        layout.setBorder("1px solid red");
        parent.setBorder("1px solid orange");
      }
      parent.addMember(layout);
    }