List of usage examples for com.google.gwt.user.client.ui FileUpload FileUpload
public FileUpload()
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);//from w w w . j ava2s .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.gwt.client.pagebuilder.PageAssembler.java
License:Apache License
/** preserves event handlers on element to be wrapped */ public static Widget elementToWidget(Element e, String typ) { Widget result = null;/*from www. j a v a 2 s. com*/ if (e != null) { int eventsSunk = DOM.getEventsSunk(e); EventListener el = DOM.getEventListener(e); if (typ == TEXT) result = TextBox.wrap(e); else if (typ == TEXT_AREA) result = TextArea.wrap(e); else if (typ == PASSWORD) result = PasswordTextBox.wrap(e); else if (typ == LABEL) result = Label.wrap(e); else if (typ == A) result = Anchor.wrap(e); else if (typ == IMAGE) result = Image.wrap(e); else if (typ == SELECT) result = ListBox.wrap(e); else if (typ == HIDDEN) result = Hidden.wrap(e); else if (typ == FILE) result = FileUpload.wrap(e); else if (typ == FORM) result = FormPanel.wrap(e, true); else if (typ == FRAME) result = Frame.wrap(e); else if (typ == SUBMIT) result = SubmitButton.wrap(e); else if (typ == BUTTON) result = Button.wrap(e); else if (typ == CHECK_BOX) result = SimpleCheckBox.wrap(e); DOM.sinkEvents(e, eventsSunk); DOM.setEventListener(e, el); } else { if (typ == TEXT) result = new TextBox(); else if (typ == TEXT_AREA) result = new TextArea(); else if (typ == PASSWORD) result = new PasswordTextBox(); else if (typ == LABEL) result = new Label(); else if (typ == A) result = new Anchor(); else if (typ == SELECT) result = new ListBox(); else if (typ == IMAGE) result = new Image(); else if (typ == HIDDEN) result = new Hidden(); else if (typ == FILE) result = new FileUpload(); else if (typ == FORM) result = new FormPanel(); else if (typ == FRAME) result = new Frame(); else if (typ == SUBMIT) result = new SubmitButton(); else if (typ == BUTTON) result = new Button(); else if (typ == CHECK_BOX) result = SimpleCheckBox.wrap(e); } return result; }
From source file:com.eduworks.gwt.client.pagebuilder.PageAssembler.java
License:Apache License
/** preserves event handlers on element to be wrapped */ public static Widget elementToWidget(String elementName, String typ) { Widget result = null;/* w w w.ja v a 2s. c o m*/ Element e = DOM.getElementById(elementName); if (e != null) { int eventsSunk = DOM.getEventsSunk(e); EventListener el = DOM.getEventListener(e); if (typ == TEXT) result = TextBox.wrap(e); else if (typ == TEXT_AREA) result = TextArea.wrap(e); else if (typ == PASSWORD) result = PasswordTextBox.wrap(e); else if (typ == LABEL) result = Label.wrap(e); else if (typ == A) result = Anchor.wrap(e); else if (typ == SELECT) result = ListBox.wrap(e); else if (typ == IMAGE) result = Image.wrap(e); else if (typ == HIDDEN) result = Hidden.wrap(e); else if (typ == FILE) result = FileUpload.wrap(e); else if (typ == FORM) result = FormPanel.wrap(e, true); else if (typ == FRAME) result = Frame.wrap(e); else if (typ == SUBMIT) result = SubmitButton.wrap(e); else if (typ == BUTTON) result = Button.wrap(e); else if (typ == CHECK_BOX) result = SimpleCheckBox.wrap(e); DOM.sinkEvents(e, eventsSunk); DOM.setEventListener(e, el); } else { if (typ == TEXT) result = new TextBox(); else if (typ == TEXT_AREA) result = new TextArea(); else if (typ == PASSWORD) result = new PasswordTextBox(); else if (typ == LABEL) result = new Label(); else if (typ == A) result = new Anchor(); else if (typ == IMAGE) result = new Image(); else if (typ == SELECT) result = new ListBox(); else if (typ == HIDDEN) result = new Hidden(); else if (typ == FILE) result = new FileUpload(); else if (typ == FORM) result = new FormPanel(); else if (typ == FRAME) result = new Frame(); else if (typ == SUBMIT) result = new SubmitButton(); else if (typ == BUTTON) result = new Button(); else if (typ == CHECK_BOX) result = SimpleCheckBox.wrap(e); } return result; }
From source file:com.google.appinventor.client.explorer.youngandroid.GalleryPage.java
License:Open Source License
/** * Helper method called by constructor to initialize image upload components *///from w w w .j a v a 2 s . co m private void initImageComponents() { imageUploadBox = new FlowPanel(); imageUploadBox.addStyleName("app-image-uploadbox"); imageUploadBox.addStyleName("gallery-editbox"); imageUploadBoxInner = new FlowPanel(); imageUploadPrompt = new Label("Upload your project image!"); imageUploadPrompt.addStyleName("gallery-editprompt"); updateAppImage(gallery.getCloudImageURL(app.getGalleryAppId()), imageUploadBoxInner); image.addStyleName("status-updating"); imageUploadPrompt.addStyleName("app-image-uploadprompt"); imageUploadBoxInner.add(imageUploadPrompt); upload = new FileUpload(); upload.addStyleName("app-image-upload"); upload.getElement().setAttribute("accept", "image/*"); // Set the correct handler for servlet side capture upload.setName(ServerLayout.UPLOAD_FILE_FORM_ELEMENT); upload.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { uploadImage(); } }); imageUploadBoxInner.add(upload); imageUploadBox.add(imageUploadBoxInner); wrapper = new FocusPanel(); wrapper.add(imageUploadBox); wrapper.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { // The correct way to trigger click event on FileUpload upload.getElement().<InputElement>cast().click(); } }); appHeader.add(wrapper); }
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);/*from ww w . j a va 2 s .com*/ 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./*from w w w.j a v a2 s . c om*/ * * @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. *//* w w w .j a va 2 s. c o m*/ 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.// w ww . jav a 2 s.c o m */ 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 va2 s.c o m*/ // 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); }