HtmlUploadComponentImpl(final UploadComponentOptions options, final boolean zip) { this.zip = zip; if (zip) { types = "*.zip"; typesDescription = "Zip"; } else { types = options.getTypes() == null ? null : options.getTypes(); typesDescription = options.getTypesDescription() == null ? null : options.getTypesDescription(); } this.options = options; if (isMultiple()) { formPanel.setHeight("125px"); scrollPanel.setHeight("125px"); formPanel.setWidth("320px"); scrollPanel.setWidth("320px"); } else { formPanel.setHeight("30px"); scrollPanel.setHeight("30px"); formPanel.setWidth("310px"); scrollPanel.setWidth("310px"); } panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); formPanel.setWidget(scrollPanel); formPanel.setAction(GWT.getHostPageBaseURL() + "fileupload?zip=" + zip); formPanel.setEncoding(FormPanel.ENCODING_MULTIPART); formPanel.setMethod(FormPanel.METHOD_POST); formPanel.addSubmitHandler( new SubmitHandler() { public void onSubmit(final SubmitEvent submitEvent) {} }); formPanel.addSubmitCompleteHandler( new SubmitCompleteHandler() { public void onSubmitComplete(final SubmitCompleteEvent completeEvent) { System.out.println("Submit complete " + completeEvent.getResults()); final String result = completeEvent.getResults(); try { final List<FileSource> fileSources = toFileSources(result); options.getCompletionCallback().onSuccess(fileSources); } catch (final Exception e) { options.getCompletionCallback().onFailure(e); } } }); final Layout parent = getParentCanvas(options); // final String parentPreix; // if(isZip) { // parentPrefix = DomConstants.UPLOAD_PANEL_ZIP; // } else { // parentPrefix = DomConstants.UPLOAD_PANEL_PLAIN; // } parent.setWidth100(); if (debug) { parent.setBorder("1px solid pink"); } parent.setAlign(VerticalAlignment.CENTER); parent.setLayoutAlign(VerticalAlignment.CENTER); final Layout wrapperLayout = new VLayout(); // wrapperLayout.setHeight100(); wrapperLayout.setWidth100(); if (isMultiple()) { wrapperLayout.setHeight("140px"); } else { wrapperLayout.setHeight("30px"); } if (debug) { wrapperLayout.setBorder("1px solid blue"); } wrapperLayout.setAlign(VerticalAlignment.CENTER); wrapperLayout.setLayoutAlign(VerticalAlignment.CENTER); /* * wrapperLayout.setGroupTitle(isMultiple() ? "File(s)" : (zip ? "Zip File" : "File")); * wrapperLayout.setIsGroup(true); * wrapperLayout.setPadding(15); * wrapperLayout.setLayoutAlign(Alignment.CENTER); * wrapperLayout.setAlign(Alignment.CENTER); */ if (isMultiple()) { final Label addLabel = SmartUtils.smartParagraph( "<span style=\"color:blue;cursor:pointer; text-decoration: underline;\">Add Upload</span>"); addLabel.addClickHandler( new ClickHandler() { public void onClick(final ClickEvent clickEvent) { addFileUploadWidget(); } }); wrapperLayout.addMember(addLabel); } wrapperLayout.addMember(formPanel); parent.addMember(wrapperLayout); // parent.setLayoutAlign(Alignment.CENTER); // parent.setAlign(Alignment.CENTER); addFileUploadWidget(); setWidget(parent); parent.addDrawHandler( new DrawHandler() { public void onDraw(DrawEvent event) { if (zip) { parent.getDOM().addClassName(DomConstants.UPLOAD_PANEL_ZIP); } else { parent.getDOM().addClassName(DomConstants.UPLOAD_PANEL_PLAIN); } } }); }
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); }