List of usage examples for com.google.gwt.user.client.ui FileUpload setName
public void setName(String name)
From source file:com.edgenius.wiki.gwt.client.space.SpaceLogoForm.java
License:Open Source License
public SpaceLogoForm() { final FormPanel form = new FormPanel(); form.setAction(GwtClientUtils.getBaseUrl() + "space/logo.do"); form.setMethod(FormPanel.METHOD_POST); form.setEncoding(FormPanel.ENCODING_MULTIPART); form.addSubmitHandler(this); form.addSubmitCompleteHandler(this); VerticalPanel panel = new VerticalPanel(); panel.add(message);//from w w w. j a v a 2 s . c o m panel.add(spaceUname); HorizontalPanel h1 = new HorizontalPanel(); Label uploadLabel = new Label(Msg.consts.logo()); uploadLabel.setStyleName(Css.FORM_LABEL); FileUpload upload = new FileUpload(); upload.setName("file"); h1.add(uploadLabel); h1.add(upload); panel.add(h1); form.setWidget(panel); // Button update = new Button(Msg.consts.update()); update.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { form.submit(); } }); Button cancel = new Button(Msg.consts.cancel()); cancel.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { //return to link panel for (Iterator<SpaceUpdateListener> iter = listener.iterator(); iter.hasNext();) { iter.next().spaceUpdateCancelled(); } } }); ButtonBar btnBar = new ButtonBar(); btnBar.add(update); btnBar.add(cancel); VerticalPanel main = new VerticalPanel(); main.add(form); main.add(btnBar); setWidget(main); }
From source file:com.edgenius.wiki.gwt.client.user.PortraitForm.java
License:Open Source License
public PortraitForm() { form.setAction(GwtClientUtils.getBaseUrl() + "user/portrait.do"); form.setMethod(FormPanel.METHOD_POST); form.setEncoding(FormPanel.ENCODING_MULTIPART); form.addSubmitHandler(this); form.addSubmitCompleteHandler(this); VerticalPanel panel = new VerticalPanel(); panel.add(message);// w w w.ja v a 2 s. co m panel.add(userUid); Label uploadLabel = new Label(Msg.consts.portrait()); uploadLabel.setStyleName(Css.FORM_LABEL); FileUpload upload = new FileUpload(); upload.setName("file"); panel.add(uploadLabel); panel.add(upload); form.setWidget(panel); update.addClickHandler(this); cancel.addClickHandler(this); ButtonBar btnBar = new ButtonBar(); btnBar.add(update); btnBar.add(cancel); VerticalPanel main = new VerticalPanel(); main.add(form); main.add(btnBar); setWidget(main); }
From source file:com.eduworks.russel.ui.client.pagebuilder.screen.EditScreen.java
License:Apache License
/** * buildEmptyUploadTile0 Initiates a tile in the EditScreen to represent a file that is uploading * @param idPrefix String id assigned to the new tile *///w w w. j a va2 s .c om private void buildEmptyUploadTile0(final String idPrefix) { final FormPanel formPanel = (FormPanel) PageAssembler.elementToWidget("addFileForm", PageAssembler.FORM); final FileUpload fileUpload = (FileUpload) PageAssembler.elementToWidget("addFileData", PageAssembler.FILE); formPanel.setEncoding(FormPanel.ENCODING_MULTIPART); formPanel.setAction(RusselApi.getESBActionURL("addResource") + "?inline=true"); FileHandler.pendingFileUploads++; final StatusRecord status = StatusHandler.createMessage(StatusHandler.getFileMessageBusy(""), StatusRecord.ALERT_BUSY); formPanel.addSubmitCompleteHandler(new SubmitCompleteHandler() { @Override public void onSubmitComplete(SubmitCompleteEvent event) { ESBPacket node = new ESBPacket(event.getResults()); RUSSELFileRecord fr = new RUSSELFileRecord(); fr.setGuid(node.getPayloadString()); String filename = fileUpload.getFilename(); final String justFileName = filename.substring(filename.lastIndexOf("\\") + 1); fr.setFilename(justFileName); if (DOM.getElementById(idPrefix + "-objectDescription") != null) { RootPanel.get(idPrefix + "-objectDescription").getElement().setInnerText(""); fillTemplateDetails0(fr, idPrefix); DOM.getElementById(idPrefix + "-objectDetailButton").removeAttribute("hidden"); } FileHandler.pendingFileUploads--; status.setState(StatusRecord.ALERT_SUCCESS); status.setMessage(StatusHandler.getFileMessageDone(justFileName)); StatusHandler.alterMessage(status); // if (justFileName.substring(justFileName.lastIndexOf(".")+1).equalsIgnoreCase("rpf")) // ProjectRecord.updatePfmNodeId(fr); thumbIDs.put(idPrefix + "-object", fr); //checkIEAndPromptServerDisaggregation0(fr); refreshInformation0(); } }); formPanel.addSubmitHandler(new SubmitHandler() { @Override public void onSubmit(SubmitEvent event) { String fn = fileUpload.getFilename(); String justFileName = fn.substring(fn.lastIndexOf("\\") + 1); PageAssembler.attachHandler(idPrefix + "-objectDetail", Event.ONCLICK, new EventCallback() { @Override public void onEvent(Event event) { toggleSelection0(idPrefix + "-object"); } }); if (fn == "") { status.setState(StatusRecord.ALERT_WARNING); status.setMessage(StatusHandler.INVALID_FILENAME); StatusHandler.alterMessage(status); fileUpload.setName("data"); DOM.getElementById(idPrefix + "-object").removeFromParent(); FileHandler.pendingFileUploads--; event.cancel(); } else { DOM.getElementById(idPrefix + "-objectDetailButton").setAttribute("hidden", "hidden"); status.setMessage(StatusHandler.getFileMessageBusy(justFileName)); StatusHandler.alterMessage(status); DOM.getElementById("addFileData").setAttribute("name", justFileName); DOM.getElementById("session").setAttribute("value", "{ \"sessionid\":\"" + RusselApi.sessionId + "\" }"); if (justFileName.indexOf(".") != -1 && justFileName.substring(justFileName.lastIndexOf(".") + 1) .toLowerCase().equals("zip")) { if (!Browser.isBadIE()) { File file = BlobUtils.getFile("addFileData"); String filename = file.getName(); if (filename.substring(filename.lastIndexOf(".") + 1).equalsIgnoreCase("zip") && Window .confirm("Do you wish to disaggregate the zip " + filename + " package?")) { Zip.grabEntries(file, new AsyncCallback<Vector<ZipRecord>>() { @Override public void onFailure(Throwable caught) { } @Override public void onSuccess(Vector<ZipRecord> zipRecords) { for (int x = 0; x < zipRecords.size(); x++) { FileHandler.pendingZipUploads.add(zipRecords.get(x)); } doPendingUploads0(); } }); } } } RootPanel.get(idPrefix + "-objectDescription").add(new Image("images/orbit/loading.gif")); DOM.getElementById(idPrefix + "-objectTitle").setInnerText(justFileName); DOM.getElementById(idPrefix + "-objectDescription").setAttribute("style", "text-align:center"); } } }); formPanel.submit(); refreshInformation0(); }
From source file:com.google.appinventor.client.wizards.ComponentImportWizard.java
License:Open Source License
private FileUpload createFileUpload() { FileUpload upload = new FileUpload(); upload.setName(ServerLayout.UPLOAD_COMPONENT_ARCHIVE_FORM_ELEMENT); return upload; }
From source file:com.google.appinventor.client.wizards.ComponentUploadWizard.java
License:Open Source License
public ComponentUploadWizard() { super(MESSAGES.componentUploadWizardCaption(), true, false); final FileUpload uploadWiget = new FileUpload(); uploadWiget.setName(ServerLayout.UPLOAD_COMPONENT_ARCHIVE_FORM_ELEMENT); VerticalPanel panel = new VerticalPanel(); panel.setVerticalAlignment(VerticalPanel.ALIGN_MIDDLE); panel.add(uploadWiget);// www .ja va2 s. co m addPage(panel); setStylePrimaryName("ode-DialogBox"); initFinishCommand(new Command() { @Override public void execute() { if (!uploadWiget.getFilename().endsWith(COMPONENT_ARCHIVE_EXTENSION)) { Window.alert(MESSAGES.notComponentArchiveError()); return; } String url = GWT.getModuleBaseURL() + ServerLayout.UPLOAD_SERVLET + "/" + ServerLayout.UPLOAD_COMPONENT + "/" + trimLeadingPath(uploadWiget.getFilename()); Uploader.getInstance().upload(uploadWiget, url, new OdeAsyncCallback<UploadResponse>() { @Override public void onSuccess(UploadResponse uploadResponse) { Component component = Component.valueOf(uploadResponse.getInfo()); ErrorReporter.reportInfo("Uploaded successfully"); } }); } private String trimLeadingPath(String filename) { // Strip leading path off filename. // We need to support both Unix ('/') and Windows ('\\') separators. return filename.substring(Math.max(filename.lastIndexOf('/'), filename.lastIndexOf('\\')) + 1); } }); }
From source file:com.google.appinventor.client.wizards.FileUploadWizard.java
License:Open Source License
/** * Creates a new file upload wizard./* www . j a va 2s . co m*/ * * @param folderNode the upload destination folder * @param fileUploadedCallback callback to be executed after upload */ public FileUploadWizard(final FolderNode folderNode, final FileUploadedCallback fileUploadedCallback) { super(MESSAGES.fileUploadWizardCaption(), true, false); // Initialize UI final FileUpload upload = new FileUpload(); upload.setName(ServerLayout.UPLOAD_FILE_FORM_ELEMENT); setStylePrimaryName("ode-DialogBox"); VerticalPanel panel = new VerticalPanel(); panel.setVerticalAlignment(VerticalPanel.ALIGN_MIDDLE); panel.add(upload); addPage(panel); // Create finish command (upload a file) initFinishCommand(new Command() { @Override public void execute() { String uploadFilename = upload.getFilename(); if (!uploadFilename.isEmpty()) { final String filename = makeValidFilename(uploadFilename); if (!TextValidators.isValidCharFilename(filename)) { createErrorDialog(MESSAGES.malformedFilenameTitle(), MESSAGES.malformedFilename(), Error.NOFILESELECETED, folderNode, fileUploadedCallback); return; } else if (!TextValidators.isValidLengthFilename(filename)) { createErrorDialog(MESSAGES.filenameBadSizeTitle(), MESSAGES.filenameBadSize(), Error.FILENAMEBADSIZE, folderNode, fileUploadedCallback); return; } int nameLength = uploadFilename.length(); String fileEnd = uploadFilename.substring(nameLength - 4, nameLength); if (".aia".equals(fileEnd.toLowerCase())) { createErrorDialog(MESSAGES.aiaMediaAssetTitle(), MESSAGES.aiaMediaAsset(), Error.AIAMEDIAASSET, folderNode, fileUploadedCallback); return; } String fn = conflictingExistingFile(folderNode, filename); if (fn != null && !confirmOverwrite(folderNode, fn, filename)) { return; } else { String fileId = folderNode.getFileId() + "/" + filename; // We delete all the conflicting files. for (ProjectNode child : folderNode.getChildren()) { if (fileId.equalsIgnoreCase(child.getFileId()) && !fileId.equals(child.getFileId())) { final ProjectNode node = child; String filesToClose[] = { node.getFileId() }; Ode ode = Ode.getInstance(); ode.getEditorManager().closeFileEditors(node.getProjectId(), filesToClose); ode.getProjectService().deleteFile(ode.getSessionId(), node.getProjectId(), node.getFileId(), new OdeAsyncCallback<Long>( // message on failure MESSAGES.deleteFileError()) { @Override public void onSuccess(Long date) { Ode.getInstance().getProjectManager().getProject(node) .deleteNode(node); Ode.getInstance().updateModificationDate(node.getProjectId(), date); } }); } } } ErrorReporter.reportInfo(MESSAGES.fileUploadingMessage(filename)); // Use the folderNode's project id and file id in the upload URL so that the file is // uploaded into that project and that folder in our back-end storage. String uploadUrl = GWT.getModuleBaseURL() + ServerLayout.UPLOAD_SERVLET + "/" + ServerLayout.UPLOAD_FILE + "/" + folderNode.getProjectId() + "/" + folderNode.getFileId() + "/" + filename; Uploader.getInstance().upload(upload, uploadUrl, new OdeAsyncCallback<UploadResponse>(MESSAGES.fileUploadError()) { @Override public void onSuccess(UploadResponse uploadResponse) { switch (uploadResponse.getStatus()) { case SUCCESS: ErrorReporter.hide(); onUploadSuccess(folderNode, filename, uploadResponse.getModificationDate(), fileUploadedCallback); break; case FILE_TOO_LARGE: // The user can resolve the problem by // uploading a smaller file. ErrorReporter.reportInfo(MESSAGES.fileTooLargeError()); break; default: ErrorReporter.reportError(MESSAGES.fileUploadError()); break; } } }); } else { createErrorDialog(MESSAGES.noFileSelectedTitle(), MESSAGES.noFileSelected(), Error.NOFILESELECETED, folderNode, fileUploadedCallback); } } }); }
From source file:com.google.appinventor.client.wizards.KeystoreUploadWizard.java
License:Open Source License
/** * Creates a new keystore upload wizard. *//*from w ww . j av a 2s. c om*/ public KeystoreUploadWizard(final Command callbackAfterUpload) { super(MESSAGES.keystoreUploadWizardCaption(), true, false); // Initialize UI final FileUpload upload = new FileUpload(); upload.setName(ServerLayout.UPLOAD_USERFILE_FORM_ELEMENT); setStylePrimaryName("ode-DialogBox"); VerticalPanel panel = new VerticalPanel(); panel.setVerticalAlignment(VerticalPanel.ALIGN_MIDDLE); panel.add(upload); addPage(panel); // Create finish command (upload a keystore) initFinishCommand(new Command() { @Override public void execute() { String filename = upload.getFilename(); if (filename.endsWith(KEYSTORE_EXTENSION)) { String uploadUrl = GWT.getModuleBaseURL() + ServerLayout.UPLOAD_SERVLET + "/" + ServerLayout.UPLOAD_USERFILE + "/" + StorageUtil.ANDROID_KEYSTORE_FILENAME; Uploader.getInstance().upload(upload, uploadUrl, new OdeAsyncCallback<UploadResponse>( // failure message MESSAGES.keystoreUploadError()) { @Override public void onSuccess(UploadResponse uploadResponse) { switch (uploadResponse.getStatus()) { case SUCCESS: if (callbackAfterUpload != null) { callbackAfterUpload.execute(); } break; default: ErrorReporter.reportError(MESSAGES.keystoreUploadError()); break; } } }); } else { Window.alert(MESSAGES.notKeystoreError()); center(); } } }); }
From source file:com.google.appinventor.client.wizards.ProjectUploadWizard.java
License:Open Source License
/** * Creates a new project upload wizard.//from w w w .j a v a 2s.c om */ public ProjectUploadWizard() { super(MESSAGES.projectUploadWizardCaption(), true, false); // Initialize UI final FileUpload upload = new FileUpload(); upload.setName(ServerLayout.UPLOAD_PROJECT_ARCHIVE_FORM_ELEMENT); setStylePrimaryName("ode-DialogBox"); VerticalPanel panel = new VerticalPanel(); panel.setVerticalAlignment(VerticalPanel.ALIGN_MIDDLE); panel.add(upload); addPage(panel); // Create finish command (upload a project archive) initFinishCommand(new Command() { @Override public void execute() { String filename = upload.getFilename(); if (filename.endsWith(PROJECT_ARCHIVE_EXTENSION)) { // Strip extension and leading path off filename. We need to support both Unix ('/') and // Windows ('\\') path separators. File.pathSeparator is not available in GWT. filename = filename.substring(0, filename.length() - PROJECT_ARCHIVE_EXTENSION.length()) .substring(Math.max(filename.lastIndexOf('/'), filename.lastIndexOf('\\')) + 1); // Make sure the project name is legal and unique. if (!TextValidators.checkNewProjectName(filename)) { return; } String uploadUrl = GWT.getModuleBaseURL() + ServerLayout.UPLOAD_SERVLET + "/" + ServerLayout.UPLOAD_PROJECT + "/" + filename; Uploader.getInstance().upload(upload, uploadUrl, new OdeAsyncCallback<UploadResponse>( // failure message MESSAGES.projectUploadError()) { @Override public void onSuccess(UploadResponse uploadResponse) { switch (uploadResponse.getStatus()) { case SUCCESS: String info = uploadResponse.getInfo(); UserProject userProject = UserProject.valueOf(info); Ode ode = Ode.getInstance(); Project uploadedProject = ode.getProjectManager().addProject(userProject); ode.openYoungAndroidProjectInDesigner(uploadedProject); break; case NOT_PROJECT_ARCHIVE: // This may be a "severe" error; but in the // interest of reducing the number of red errors, the // line has been changed to report info not an error. // This error is triggered when the user attempts to // upload a zip file that is not a project. ErrorReporter.reportInfo(MESSAGES.notProjectArchiveError()); break; default: ErrorReporter.reportError(MESSAGES.projectUploadError()); break; } } }); } else { Window.alert(MESSAGES.notProjectArchiveError()); center(); } } }); }
From source file:com.google.gwt.examples.FormPanelExample.java
License:Apache License
public void onModuleLoad() { // Create a FormPanel and point it at a service. final FormPanel form = new FormPanel(); form.setAction("/myFormHandler"); // Because we're going to add a FileUpload widget, we'll need to set the // form to use the POST method, and multipart MIME encoding. form.setEncoding(FormPanel.ENCODING_MULTIPART); form.setMethod(FormPanel.METHOD_POST); // Create a panel to hold all of the form widgets. VerticalPanel panel = new VerticalPanel(); form.setWidget(panel);/*w w w .ja v a2 s . c om*/ // Create a TextBox, giving it a name so that it will be submitted. final TextBox tb = new TextBox(); tb.setName("textBoxFormElement"); panel.add(tb); // Create a ListBox, giving it a name and some values to be associated with // its options. ListBox lb = new ListBox(); lb.setName("listBoxFormElement"); lb.addItem("foo", "fooValue"); lb.addItem("bar", "barValue"); lb.addItem("baz", "bazValue"); panel.add(lb); // Create a FileUpload widget. FileUpload upload = new FileUpload(); upload.setName("uploadFormElement"); panel.add(upload); // Add a 'submit' button. panel.add(new Button("Submit", new ClickHandler() { public void onClick(ClickEvent event) { form.submit(); } })); // Add an event handler to the form. form.addSubmitHandler(new FormPanel.SubmitHandler() { public void onSubmit(SubmitEvent event) { // This event is fired just before the form is submitted. We can take // this opportunity to perform validation. if (tb.getText().length() == 0) { Window.alert("The text box must not be empty"); event.cancel(); } } }); form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() { public void onSubmitComplete(SubmitCompleteEvent event) { // When the form submission is successfully completed, this event is // fired. Assuming the service returned a response of type text/html, // we can get the result text here (see the FormPanel documentation for // further explanation). Window.alert(event.getResults()); } }); RootPanel.get().add(form); }
From source file:com.google.livingstories.client.contentmanager.ImportManager.java
License:Apache License
private Widget createFileUploadForm() { fileUploadForm = new FormPanel(); fileUploadForm.setAction("/import"); fileUploadForm.setEncoding(FormPanel.ENCODING_MULTIPART); fileUploadForm.setMethod(FormPanel.METHOD_POST); VerticalPanel fileUploadPanel = new VerticalPanel(); fileUploadForm.setWidget(fileUploadPanel); FileUpload upload = new FileUpload(); upload.setName("data"); fileUploadPanel.add(upload);//from w ww .j av a 2s .c o m CheckBox override = new CheckBox( "Check this box if the previous import attempt resulted in " + "an error."); override.setName("override"); override.setFormValue("true"); fileUploadPanel.add(override); Button submit = new Button("Submit"); submit.addClickHandler(new ClickHandler() { public void onClick(ClickEvent e) { fileUploadForm.submit(); statusLabel.setHTML("Uploading..."); progress = 0; } }); fileUploadPanel.add(submit); fileUploadForm.addSubmitCompleteHandler(new SubmitCompleteHandler() { @Override public void onSubmitComplete(SubmitCompleteEvent e) { processResult(e.getResults()); } }); return fileUploadForm; }