Example usage for com.google.gwt.user.client.ui FormPanel ENCODING_MULTIPART

List of usage examples for com.google.gwt.user.client.ui FormPanel ENCODING_MULTIPART

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui FormPanel ENCODING_MULTIPART.

Prototype

String ENCODING_MULTIPART

To view the source code for com.google.gwt.user.client.ui FormPanel ENCODING_MULTIPART.

Click Source Link

Document

Used with #setEncoding(String) to specify that the form will be submitted using MIME encoding (necessary for FileUpload to work properly).

Usage

From source file:org.pepstock.jem.gwt.client.panels.jobs.input.LegacySubmitter.java

License:Open Source License

/**
 * Construct the UI without output information.<br>
 * Happens when the job is INPUT or ROUTING.
 * //from   ww  w  .  j  av  a  2 s .  c  o m
 * @param job
 */
public LegacySubmitter() {
    super(true);
    setGlassEnabled(true);

    // builds the form
    //pass action to the form to point to service handling file receiving operation
    form.setAction(GWT.getModuleBaseURL() + SERVICE_NAME);
    // set form to use the POST method, and multipart MIME encoding.
    form.setEncoding(FormPanel.ENCODING_MULTIPART);
    form.setMethod(FormPanel.METHOD_POST);

    form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {
        @Override
        public void onSubmitComplete(SubmitCompleteEvent event) {
            String preferredJclType = typesList.getValue(typesList.getSelectedIndex());
            CurrentUser.getInstance().setStringPreference(PreferencesKeys.JOB_SUBMIT_TYPE, preferredJclType);
            XmlResultViewer.showResult("JOB submitted", event.getResults());
            hide();
        }
    });

    // retrieve the data for building content panel
    fileUpload.setName(FILE_UPLOAD_FIELD);
    Services.QUEUES_MANAGER.getJclTypes(new GetJclTypesAsyncCallback());
    typesList.setName(TYPE_FIELD);

    // build the content panel
    content.setCellSpacing(10);
    content.setWidth(Sizes.HUNDRED_PERCENT);

    content.setHTML(0, 0, "Job JCL file:");
    content.setWidget(0, 1, fileUpload);

    content.setHTML(1, 0, "JCL type:");
    content.setWidget(1, 1, typesList);

    // add the content to form
    form.setWidget(content);

    // builds action buttons
    submitButton.addStyleName(Styles.INSTANCE.common().defaultActionButton());
    submitButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            submit();
        }
    });

    // builds the action button panel
    actionButtonPanel.setSpacing(10);
    actionButtonPanel.add(submitButton);

    // propose the switch only if supported by client browser
    if (Uploader.isAjaxUploadWithProgressEventsSupported()) {
        Button switchButton = new Button("Multi-file Submitter");
        switchButton.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                EventBus.INSTANCE.fireEventFromSource(
                        new org.pepstock.jem.gwt.client.events.SubmitterClosedEvent(true),
                        LegacySubmitter.this);
            }
        });
        actionButtonPanel.add(switchButton);
        actionButtonPanel.setCellWidth(switchButton, Sizes.HUNDRED_PERCENT);
        actionButtonPanel.setCellHorizontalAlignment(switchButton, HasHorizontalAlignment.ALIGN_RIGHT);
        actionButtonPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    }
}

From source file:org.rebioma.client.Uploader.java

License:Apache License

/**
 * Initialize widget components and layout elements. 
 * /*  w  w  w. j  a v  a  2 s  .c o m*/
 * @param type
 *   file input to use
 * @param form
 *   An existing form panel to use
 */
public Uploader(FileInputType type, FormPanel form) {
    thisInstance = this;
    this.fileInputType = type;

    if (form == null) {
        form = new FormFlowPanel();
    }
    uploadForm = form;
    uploadForm.setEncoding(FormPanel.ENCODING_MULTIPART);
    uploadForm.setMethod(FormPanel.METHOD_POST);
    uploadForm.setAction(servletPath);
    uploadForm.addSubmitHandler(onSubmitFormHandler);
    uploadForm.addSubmitCompleteHandler(onSubmitCompleteHandler);

    uploaderPanel = getUploaderPanel();
    uploaderPanel.add(uploadForm);
    uploaderPanel.setStyleName(STYLE_MAIN);

    setFileInput(fileInputType.getInstance());

    setStatusWidget(statusWidget);

    super.initWidget(uploaderPanel);
}

From source file:org.rstudio.studio.client.workbench.views.files.ui.FileUploadDialog.java

License:Open Source License

@Override
protected void setFormPanelEncodingAndMethod(FormPanel formPanel) {
    formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
    formPanel.setMethod(FormPanel.METHOD_POST);
}

From source file:org.uberfire.ext.plugin.client.widget.media.MediaLibraryWidget.java

License:Apache License

@PostConstruct
public void init() {
    fileUpload = createFileUpload();/*from  w  w w .j  a  va  2  s.  c o m*/

    initWidget(uiBinder.createAndBindUi(this));

    form.setEncoding(FormPanel.ENCODING_MULTIPART);
    form.setMethod(FormPanel.METHOD_POST);

    formEncoder.addUtf8Charset(form);

    form.addSubmitHandler(new AbstractForm.SubmitHandler() {
        @Override
        public void onSubmit(final AbstractForm.SubmitEvent event) {
            final String fileName = fileUpload.getFilename();
            if (isNullOrEmpty(fileName)) {
                event.cancel();
            }
        }

        private boolean isNullOrEmpty(final String fileName) {
            return fileName == null || "".equals(fileName);
        }
    });

    form.addSubmitCompleteHandler(new AbstractForm.SubmitCompleteHandler() {
        @Override
        public void onSubmitComplete(final AbstractForm.SubmitCompleteEvent event) {
            if ("OK".equalsIgnoreCase(event.getResults())) {
                Window.alert("Upload Success");
            } else if ("FAIL".equalsIgnoreCase(event.getResults())) {
                Window.alert("Upload Failed");
            } else if ("FAIL - ALREADY EXISTS".equalsIgnoreCase(event.getResults())) {
                Window.alert("File already exists");
            }
        }
    });
}

From source file:org.uberfire.ext.widgets.core.client.editors.defaulteditor.DefaultEditorFileUploadBase.java

License:Apache License

void initForm() {
    form.setEncoding(FormPanel.ENCODING_MULTIPART);
    form.setMethod(FormPanel.METHOD_POST);

    formEncoder.addUtf8Charset(form);

    // Validation is not performed in a SubmitHandler as it fails to be invoked with GWT-Bootstrap3. See:-
    // - https://issues.jboss.org/browse/GUVNOR-2302 and
    // - the underlying cause https://github.com/gwtbootstrap3/gwtbootstrap3/issues/375
    // Validation is now performed prior to the form being submitted.

    form.addSubmitCompleteHandler(new AbstractForm.SubmitCompleteHandler() {
        @Override//from  ww  w.  ja  v a2s. c  om
        public void onSubmitComplete(final AbstractForm.SubmitCompleteEvent event) {
            if ("OK".equalsIgnoreCase(event.getResults())) {
                Window.alert(CoreConstants.INSTANCE.UploadSuccess());
                executeCallback(successCallback);
            } else if ("FAIL".equalsIgnoreCase(event.getResults())) {
                Window.alert(CoreConstants.INSTANCE.UploadFail());
                executeCallback(errorCallback);
            }
        }
    });
}

From source file:org.utgenome.gwt.utgb.client.track.lib.ViewLoaderTrack.java

License:Apache License

public ViewLoaderTrack() {
    super("View Loader");
    // load view via HTTP
    HorizontalPanel hp = new HorizontalPanel();
    hp.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE);
    hp.add(new FormLabel("View Silk URL: "));
    urlBox.setWidth("400px");
    urlBox.addKeyPressHandler(new KeyPressHandler() {
        public void onKeyPress(KeyPressEvent e) {
            if (e.getCharCode() == KeyCodes.KEY_ENTER) {
                downloadView(urlBox.getText());
            }/*  w ww.  java  2s.c o  m*/
        }
    });
    Button loadButton = new Button("load");
    loadButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent e) {
            downloadView(urlBox.getText());
        }
    });
    hp.add(urlBox);
    hp.add(loadButton);
    // load view from a file
    final FormPanel fileUploadForm = new FormPanel();
    fileUploadForm.setAction(GWT.getModuleBaseURL() + "utgb-core/loadview");
    fileUploadForm.setEncoding(FormPanel.ENCODING_MULTIPART);
    fileUploadForm.setMethod(FormPanel.METHOD_POST);
    HorizontalPanel formButtonPanel = new HorizontalPanel();
    FileUpload fileBox = new FileUpload();
    fileBox.setName("file");
    fileBox.setWidth("300px");
    Button uploadButton = new Button("submit");
    uploadButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent e) {
            fileUploadForm.submit();
        }
    });
    formButtonPanel.add(new FormLabel("View Silk File:"));
    formButtonPanel.add(fileBox);
    formButtonPanel.add(uploadButton);
    fileUploadForm.add(formButtonPanel);
    DOM.setStyleAttribute(fileUploadForm.getElement(), "margin", "0");
    fileUploadForm.addSubmitCompleteHandler(new SubmitCompleteHandler() {
        public void onSubmitComplete(SubmitCompleteEvent e) {

            getFrame().setNowLoading();
            String viewXML = extractEmbeddedSilkInComment(e.getResults());
            setViewSilk(viewXML);
        }
    });
    // set panes
    panel.setStyleName("toolbox");
    panel.add(hp);
    panel.add(fileUploadForm);
}

From source file:org.waveprotocol.wave.client.wavepanel.impl.toolbar.attachment.AttachmentPopupWidget.java

License:Apache License

/**
 * Creates link info popup./*from w w  w  . j ava  2  s. c  o m*/
 */
public AttachmentPopupWidget() {
    initWidget(BINDER.createAndBindUi(this));
    // 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);

    // Add an event handler to the form.
    form.addSubmitHandler(new FormPanel.SubmitHandler() {
        @Override
        public void onSubmit(SubmitEvent event) {
            // No implementation.
        }
    });

    form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {
        @Override
        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).
            spinnerImg.setVisible(false);
            String results = event.getResults();
            if (results != null && results.contains("OK")) {
                status.setText("Done!");
                status.addStyleName(style.done());
                listener.onDone(waveRefStr, attachmentId.getId(), fileUpload.getFilename());
                hide();
            } else {
                status.setText("Error!");
                status.addStyleName(style.error());
            }
        }
    });

    uploadBtn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            String filename = fileUpload.getFilename();
            if (filename.length() == 0) {
                Window.alert("No file to upload!");
            } else {
                spinnerPanel.setVisible(true);
                formAttachmentId.setValue(attachmentId.getId());
                formWaveRef.setValue(waveRefStr);
                form.submit();
            }
        }
    });

    // Wrap in a popup.
    PopupChrome chrome = PopupChromeFactory.createPopupChrome();
    popup = PopupFactory.createPopup(null, new CenterPopupPositioner(), chrome, true);
    popup.add(this);
    popup.addPopupEventListener(this);
}

From source file:org.wte4j.ui.client.templates.upload.TemplateUploadFormPanel.java

License:Apache License

private void setMetaData() {
    formPanel.setAction(templateUploadRestURL);
    formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
    formPanel.setMethod(FormPanel.METHOD_POST);
}

From source file:org.xwiki.gwt.wysiwyg.client.widget.wizard.util.AbstractFileUploadWizardStep.java

License:Open Source License

/**
 * Creates a new file upload wizard step that uses the given service to get information about the uploaded files.
 * //  www. j a  v  a2s  .  co  m
 * @param wikiService the service used to access the uploaded attachments
 */
public AbstractFileUploadWizardStep(WikiServiceAsync wikiService) {
    this.wikiService = wikiService;

    setStepTitle(Strings.INSTANCE.fileUploadTitle());

    display().addStyleName("xUploadPanel");
    fileUploadForm.setEncoding(FormPanel.ENCODING_MULTIPART);
    fileUploadForm.setMethod(FormPanel.METHOD_POST);
    // set the url on submit time, just before upload

    Panel fileLabel = new FlowPanel();
    fileLabel.setStyleName("xInfoLabel");
    fileLabel.add(new InlineLabel(getFileLabel()));
    InlineLabel mandatoryLabel = new InlineLabel(Strings.INSTANCE.mandatory());
    mandatoryLabel.addStyleName("xMandatory");
    fileLabel.add(mandatoryLabel);
    fileUploadInput.setName(getFileUploadInputName());
    FlowPanel formPanel = new FlowPanel();

    formPanel.add(fileLabel);
    fileHelpLabel.setStyleName("xHelpLabel");
    fileHelpLabel.setVisible(false);
    formPanel.add(fileHelpLabel);

    fileErrorLabel.addStyleName("xErrorMsg");
    fileErrorLabel.setVisible(false);

    formPanel.add(fileErrorLabel);
    formPanel.add(fileUploadInput);

    fileUploadForm.setWidget(formPanel);

    display().add(fileUploadForm);
}

From source file:stroom.importexport.client.presenter.ImportConfigPresenter.java

License:Apache License

@Inject
public ImportConfigPresenter(final EventBus eventBus, final ImportConfigView view, final ImportProxy proxy,
        final ClientDispatchAsync dispatcher) {
    super(eventBus, view, proxy);
    this.dispatcher = dispatcher;

    view.getForm().setAction(dispatcher.getImportFileURL());
    view.getForm().setEncoding(FormPanel.ENCODING_MULTIPART);
    view.getForm().setMethod(FormPanel.METHOD_POST);
}