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.ned.server.nedadminconsole.client.dialogs.NedAddNewLanguageDialog.java

License:Open Source License

public NedAddNewLanguageDialog(NedLanguageWidget nedLanguageWidget) {

    this.parent = nedLanguageWidget;

    VerticalPanel verticalPanelMain = new VerticalPanel();

    setWidget(verticalPanelMain);/*from ww  w  . j a v a  2 s.  c o  m*/
    setHTML(NedRes.instance().userDlgAddNewLanguage());

    uploadForm = new FormPanel();
    uploadForm.setMethod(FormPanel.METHOD_POST);
    uploadForm.setAction("NedFileUploadServlet"); //TODO correct upload servlet
    uploadForm.setEncoding(FormPanel.ENCODING_MULTIPART);
    verticalPanelMain.add(uploadForm);

    Grid grid = new Grid(4, 2);
    uploadForm.setWidget(grid);
    grid.setSize("100%", "100%");

    Label labelName = new Label(NedRes.instance().langName());
    grid.setWidget(0, 0, labelName);

    TextBox textBoxName = new TextBox();
    textBoxName.setName("languageName");
    grid.setWidget(0, 1, textBoxName);

    Label labelLocale = new Label(NedRes.instance().langLocaleString());
    grid.setWidget(1, 0, labelLocale);

    TextBox textBoxLocale = new TextBox();
    textBoxLocale.setName("languageLocale");
    grid.setWidget(1, 1, textBoxLocale);

    Label labelTranslationFile = new Label(NedRes.instance().langTranslationFile());
    grid.setWidget(2, 0, labelTranslationFile);

    HorizontalPanel horizontalPanelUpload = new HorizontalPanel();
    grid.setWidget(2, 1, horizontalPanelUpload);

    fileUpload = new FileUpload();
    horizontalPanelUpload.add(fileUpload);
    fileUpload.setName("fileUpload");

    HorizontalPanel horizontalPanel = new HorizontalPanel();
    grid.setWidget(3, 1, horizontalPanel);
    grid.getCellFormatter().setWidth(3, 1, "");
    horizontalPanel.setWidth("100%");

    Button buttonUpload = new Button(NedRes.instance().add());
    buttonUpload.addClickHandler(new ClickUploadHandler());
    horizontalPanel.add(buttonUpload);
    buttonUpload.setWidth("90%");
    horizontalPanel.setCellWidth(buttonUpload, "50%");

    Button buttonCancel = new Button(NedRes.instance().cancel());
    buttonCancel.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            hide();
        }
    });
    horizontalPanel.add(buttonCancel);
    buttonCancel.setWidth("90%");
    horizontalPanel.setCellWidth(buttonCancel, "50%");

    setPopupPosition(200, 200);

    uploadForm.addSubmitHandler(new SubmitHandlerUploadFile());

    uploadForm.addSubmitCompleteHandler(new SubmitCompleteHandlerUploadFile());
    center();

}

From source file:org.ned.server.nedadminconsole.client.dialogs.NedUploadDialog.java

License:Open Source License

public NedUploadDialog(String libId, NedDataModel model) {
    setSize("395px", "147px");

    this.model = model;
    setHTML(NedRes.instance().uploadDlgUploadFile());

    VerticalPanel verticalPanel = new VerticalPanel();
    verticalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    verticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    setWidget(verticalPanel);//  ww  w .  j av a2  s.  c  o  m
    verticalPanel.setSize("386px", "100px");

    uploadForm = new FormPanel();
    uploadForm.setAction("NedFileUploadServlet");
    uploadForm.setEncoding(FormPanel.ENCODING_MULTIPART);
    uploadForm.setMethod(FormPanel.METHOD_POST);
    verticalPanel.add(uploadForm);
    uploadForm.setSize("100%", "100%");

    VerticalPanel verticalPanel_1 = new VerticalPanel();
    uploadForm.setWidget(verticalPanel_1);
    verticalPanel_1.setSize("100%", "77px");

    horizontalPanel_2 = new HorizontalPanel();
    verticalPanel_1.add(horizontalPanel_2);
    horizontalPanel_2.setWidth("100%");

    fileUpload = new FileUpload();
    horizontalPanel_2.add(fileUpload);
    horizontalPanel_2.setCellWidth(fileUpload, "100%");
    fileUpload.setName("fileUpload");
    verticalPanel_1.setCellHorizontalAlignment(fileUpload, HasHorizontalAlignment.ALIGN_CENTER);
    verticalPanel_1.setCellVerticalAlignment(fileUpload, HasVerticalAlignment.ALIGN_MIDDLE);
    fileUpload.setSize("100%", "30px");

    hiddenLibId = new Hidden("libId");
    horizontalPanel_2.add(hiddenLibId);
    hiddenLibId.setValue(libId);

    hiddenContentId = new Hidden("contentId");
    horizontalPanel_2.add(hiddenContentId);
    hiddenContentId.setValue(model.getCurrentObject().id);

    HorizontalPanel horizontalPanel = new HorizontalPanel();
    verticalPanel_1.add(horizontalPanel);
    horizontalPanel.setWidth("100%");
    verticalPanel_1.setCellHorizontalAlignment(horizontalPanel, HasHorizontalAlignment.ALIGN_CENTER);

    Button uploadBtn = new Button(NedRes.instance().uploadDlgUpload());
    horizontalPanel.add(uploadBtn);
    uploadBtn.setWidth("90%");
    horizontalPanel.setCellWidth(uploadBtn, "50%");
    horizontalPanel.setCellHorizontalAlignment(uploadBtn, HasHorizontalAlignment.ALIGN_CENTER);
    horizontalPanel.setCellVerticalAlignment(uploadBtn, HasVerticalAlignment.ALIGN_MIDDLE);
    uploadBtn.addClickHandler(new UploadFileClickHandler());
    verticalPanel.setCellVerticalAlignment(uploadBtn, HasVerticalAlignment.ALIGN_MIDDLE);
    verticalPanel.setCellHorizontalAlignment(uploadBtn, HasHorizontalAlignment.ALIGN_CENTER);

    closeBtn = new Button(NedRes.instance().close());
    horizontalPanel.add(closeBtn);
    closeBtn.setWidth("90%");
    horizontalPanel.setCellWidth(closeBtn, "50%");
    horizontalPanel.setCellVerticalAlignment(closeBtn, HasVerticalAlignment.ALIGN_MIDDLE);
    horizontalPanel.setCellHorizontalAlignment(closeBtn, HasHorizontalAlignment.ALIGN_CENTER);
    closeBtn.addClickHandler(new CloseClickHandler());

    setPopupPosition(200, 200);

    uploadForm.addSubmitHandler(new SubmitHandlerUploadFile());

    uploadForm.addSubmitCompleteHandler(new SubmitCompleteHandlerUploadFile());

    center();
}

From source file:org.onesocialweb.gwt.client.ui.widget.SingleUploader.java

License:Apache License

public SingleUploader() {

    addStyleName("uploader");

    // 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 the form
    form.setWidget(contents);/* www .  j av  a  2s .c  o m*/
    add(form);

    // add the fileupload and hidden fields
    contents.add(upload);
    add(fileLabel);
    add(progress);
    fileLabel.setVisible(false);
    progress.setVisible(true);

    upload.setName("fileId");

    upload.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {

            // check if we have a file
            if (upload.getFilename() != null && upload.getFilename().length() > 0) {

                // TODO check for valid extensions

                // change state to is uploading
                setIsUploading(true);

                // prepare for posting
                String token = getToken();
                signature.setName("signature");
                signature.setValue(token);

                jid.setName("jid");
                jid.setValue(OswServiceFactory.getService().getUserFullJID());

                requestId.setName("requestId");
                requestId.setValue("123456");

                form.setAction(OswClient.getInstance().getPreference("upload_endpoint") + "?"
                        + "requestId=123456&jid=" + URL.encode(OswServiceFactory.getService().getUserFullJID())
                        + "&signature=" + token);

                // and fire in the hole
                form.submit();

                // get basic file information
                filename = upload.getFilename();
                fileLabel.setText(filename);

                // hide upload selector and show progressbar
                upload.setVisible(false);
                progress.setVisible(true);
                fileLabel.setVisible(true);
            }
        }
    });

    form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {
        public void onSubmitComplete(SubmitCompleteEvent event) {
            // we are going to use the xmpp channel to monitor progress
            // instead

        }
    });
}

From source file:org.opencms.ade.sitemap.client.alias.CmsImportView.java

License:Open Source License

/**
 * Initializes the form used for submitting the alias CSV file to the server.<p>
 *//*  ww w . jav a  2  s .  c o  m*/
protected void initializeForm() {

    String target = CmsSitemapView.getInstance().getController().getData().getAliasImportUrl();
    m_formPanel.setAction(target);
    m_formPanel.setMethod(FormPanel.METHOD_POST);
    m_formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
    Hidden siteRootField = new Hidden(I_CmsAliasConstants.PARAM_SITEROOT);
    siteRootField.setValue(CmsCoreProvider.get().getSiteRoot());
    m_formPanelContents.add(siteRootField);
    m_formPanelContents.add(m_separatorField);
    m_formPanel.addSubmitCompleteHandler(new SubmitCompleteHandler() {

        public void onSubmitComplete(SubmitCompleteEvent event) {

            final String formPostResults = event.getResults();
            final I_CmsSitemapServiceAsync service = CmsSitemapView.getInstance().getController().getService();
            CmsRpcAction<List<CmsAliasImportResult>> action = new CmsRpcAction<List<CmsAliasImportResult>>() {

                @Override
                public void execute() {

                    start(200, false);
                    service.getAliasImportResult(formPostResults.trim(), this);
                }

                @Override
                public void onResponse(List<CmsAliasImportResult> result) {

                    stop(false);
                    handleImportResults(result);
                    Timer resizeTimer = new Timer() {

                        @Override
                        public void run() {

                            m_scrollPanel.onResizeDescendant();
                        }
                    };
                    resizeTimer.schedule(100);
                }
            };
            action.execute();
        }
    });
}

From source file:org.opencms.ade.upload.client.ui.CmsUploadDialogImpl.java

License:Open Source License

/**
 * Creates a form that contains the file input fields and the target folder.<p>
 * /* ww  w .j  a  va2 s . com*/
 * @return the form
 */
private FormPanel createForm() {

    // create a form using the POST method and multipart MIME encoding
    FormPanel form = new FormPanel();
    form.setAction(getUploadUri());
    form.setEncoding(FormPanel.ENCODING_MULTIPART);
    form.setMethod(FormPanel.METHOD_POST);
    // create a panel that contains the file input fields and the target folder
    FlowPanel inputFieldsPanel = new FlowPanel();
    int count = 0;
    for (CmsFileInput input : m_inputsToUpload.values()) {
        String filename = input.getFiles()[0].getFileName();
        String fieldName = "file_" + count++;
        input.setName(fieldName);
        if (getFilesToUpload().containsKey(filename)) {
            inputFieldsPanel.add(input);
        }
        addHiddenField(inputFieldsPanel, fieldName + I_CmsUploadConstants.UPLOAD_FILENAME_ENCODED_SUFFIX,
                URL.encode(filename));
    }
    for (String filename : getFilesToUnzip(false)) {
        addHiddenField(inputFieldsPanel, I_CmsUploadConstants.UPLOAD_UNZIP_FILES_FIELD_NAME,
                URL.encode(filename));
    }
    addHiddenField(inputFieldsPanel, I_CmsUploadConstants.UPLOAD_TARGET_FOLDER_FIELD_NAME, getTargetFolder());
    form.setWidget(inputFieldsPanel);
    return form;
}

From source file:org.opencms.gwt.client.ui.input.upload.impl.CmsUploaderDefault.java

License:Open Source License

/**
 * Creates a form to submit the upload files.<p>
 *
 * @param uploadUri the upload URI// w w w  .  j  a v a  2  s  .c  o m
 * @param targetFolder the target folder
 * @param isRootPath if the target folder is given as a root path
 * @param filesToUpload the files to upload
 * @param filesToUnzip the files to unzip
 * @return the created form panel
 */
private FormPanel createForm(String uploadUri, String targetFolder, boolean isRootPath,
        List<CmsFileInfo> filesToUpload, List<String> filesToUnzip) {

    // create a form using the POST method and multipart MIME encoding
    FormPanel form = new FormPanel();
    form.setAction(uploadUri);
    form.setEncoding(FormPanel.ENCODING_MULTIPART);
    form.setMethod(FormPanel.METHOD_POST);
    // create a panel that contains the file input fields and the target folder
    FlowPanel inputFieldsPanel = new FlowPanel();
    int count = 0;
    for (CmsFileInfo info : filesToUpload) {
        InputElement input = info.getInputElement();
        String fieldName = "file_" + count++;
        input.setName(fieldName);
        inputFieldsPanel.getElement().appendChild(input);
        addHiddenField(inputFieldsPanel, fieldName + I_CmsUploadConstants.UPLOAD_FILENAME_ENCODED_SUFFIX,
                URL.encode(info.getOverrideFileName()));
    }
    for (String filename : filesToUnzip) {
        addHiddenField(inputFieldsPanel, I_CmsUploadConstants.UPLOAD_UNZIP_FILES_FIELD_NAME,
                URL.encode(filename));
    }
    addHiddenField(inputFieldsPanel, I_CmsUploadConstants.UPLOAD_TARGET_FOLDER_FIELD_NAME, targetFolder);
    addHiddenField(inputFieldsPanel, I_CmsUploadConstants.UPLOAD_IS_ROOT_PATH_FIELD_NAME, "" + isRootPath);
    form.setWidget(inputFieldsPanel);
    return form;
}

From source file:org.opencms.ugc.client.CmsUgcWrapper.java

License:Open Source License

/**
 * Wraps an existing form element with this widget.<p>
 *
 * @param element the form element to wrap
 * @param formSessionId the form session  id
 *//*  ww w .j a  va 2  s . c o m*/
public CmsUgcWrapper(Element element, String formSessionId) {

    super(element, true);
    setEncoding(FormPanel.ENCODING_MULTIPART);
    onAttach();
}

From source file:org.openelis.ui.widget.fileupload.FileLoad.java

License:Open Source License

public FileLoad() {
    form = new FormPanel();
    form.setEncoding(FormPanel.ENCODING_MULTIPART);
    form.setMethod(FormPanel.METHOD_POST);

    upload = new FileLoadButton();

    // Submit form to server once user has chosen a file
    upload.addChangeHandler(new ChangeHandler() {
        @Override/*from ww  w  .  j  a  v  a 2  s.c om*/
        public void onChange(ChangeEvent event) {
            form.submit();
        }
    });
    upload.setName("file");

    // Hidden fields in form to define service and method to call on upload
    service = new Hidden("service");
    method = new Hidden("method");

    panel = new AbsolutePanel();
    panel.add(upload);
    panel.add(service);
    panel.add(method);
    form.add(panel);
    initWidget(form);
}

From source file:org.openremote.modeler.client.widget.buildingmodeler.LutronImportWizard.java

License:Open Source License

public LutronImportWizard(final DeviceDTO deviceDTO, final EventBus eventBus) {
    this.eventBus = eventBus;
    this.deviceDTO = deviceDTO;

    uiBinder.createAndBindUi(this);
    importButton.setEnabled(false);/* w  w w. j av a 2s .  c o  m*/
    mainLayout.setSize("50em", "20em");
    center();

    final CheckboxCellHeader selectionHeader = new CheckboxCellHeader(new CheckboxCell());
    selectionHeader.setChangeValue(new ChangeValue() {
        @Override
        public void changedValue(int columnIndex, Boolean value) {
            if (value) {
                for (OutputImportConfig oic : table.getVisibleItems()) {
                    selectionModel.setSelected(oic, true);
                }
            } else {
                selectionModel.clear();
            }
        }
    });

    TextColumn<OutputImportConfig> areaNameColumn = new TextColumn<OutputImportConfig>() {
        @Override
        public String getValue(OutputImportConfig outputConfig) {
            return outputConfig.getAreaName();
        }
    };
    TextColumn<OutputImportConfig> roomNameColumn = new TextColumn<OutputImportConfig>() {
        @Override
        public String getValue(OutputImportConfig outputConfig) {
            return outputConfig.getRoomName();
        }
    };
    TextColumn<OutputImportConfig> outputNameColumn = new TextColumn<OutputImportConfig>() {
        @Override
        public String getValue(OutputImportConfig outputConfig) {
            return outputConfig.getOutputName();
        }
    };
    TextColumn<OutputImportConfig> outputTypeColumn = new TextColumn<OutputImportConfig>() {
        @Override
        public String getValue(OutputImportConfig outputConfig) {
            return outputConfig.getType().toString();
        }
    };

    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            // Have import button only enabled if user has selected items to import
            importButton.setEnabled(!selectionModel.getSelectedSet().isEmpty());

            // And manage the select all/deselect all header based on individual selection
            if (selectionModel.getSelectedSet().isEmpty()) {
                selectionHeader.setValue(false);
            }
            if (selectionModel.getSelectedSet().size() == table.getVisibleItemCount()) {
                selectionHeader.setValue(true);
            }
        }
    });

    table.setSelectionModel(selectionModel,
            DefaultSelectionEventManager.<OutputImportConfig>createCheckboxManager());

    // Add the columns.
    Column<OutputImportConfig, Boolean> checkColumn = new Column<OutputImportConfig, Boolean>(
            new CheckboxCell(false, false)) {
        @Override
        public Boolean getValue(OutputImportConfig object) {
            return selectionModel.isSelected(object);
        }
    };
    table.addColumn(checkColumn, selectionHeader);
    table.addColumn(areaNameColumn, "Area");
    table.addColumn(roomNameColumn, "Room");
    table.addColumn(outputNameColumn, "Output");
    table.addColumn(outputTypeColumn, "Type");
    table.setRowCount(0); // No rows for now, otherwise loading indicator is displayed

    errorMessageLabel.setText("");

    uploadForm.setEncoding(FormPanel.ENCODING_MULTIPART);
    uploadForm.setMethod(FormPanel.METHOD_POST);
    uploadForm.setAction(GWT.getModuleBaseURL() + "fileUploadController.htm?method=importLutron");

    uploadForm.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {

        @Override
        public void onSubmitComplete(SubmitCompleteEvent event) {
            table.setRowCount(0); // No rows for now, otherwise loading indicator is displayed

            LutronImportResultOverlay importResult = LutronImportResultOverlay
                    .fromJSONString(event.getResults());
            if (importResult.getErrorMessage() != null) {
                reportError(importResult.getErrorMessage());
                return;
            }

            ProjectOverlay projectOverlay = importResult.getProject();
            if (projectOverlay.getAreas() == null) {
                reportError("File does not contain any information");
                return;
            }

            List<OutputImportConfig> outputs = new ArrayList<OutputImportConfig>();
            ArrayOverlay<AreaOverlay> areas = projectOverlay.getAreas();
            for (int i = 0; i < areas.length(); i++) {
                AreaOverlay areaOverlay = areas.get(i);
                if (areaOverlay.getRooms() != null) {
                    for (int j = 0; j < areaOverlay.getRooms().length(); j++) {
                        RoomOverlay roomOverlay = areaOverlay.getRooms().get(j);
                        if (roomOverlay.getOutputs() != null) {
                            for (int k = 0; k < roomOverlay.getOutputs().length(); k++) {
                                OutputOverlay outputOverlay = roomOverlay.getOutputs().get(k);
                                outputs.add(new OutputImportConfig(outputOverlay.getName(),
                                        OutputType.valueOf(outputOverlay.getType()), outputOverlay.getAddress(),
                                        roomOverlay.getName(), areaOverlay.getName()));
                            }
                        }
                    }
                }
            }
            table.setRowData(outputs);
        }
    });
}

From source file:org.openxdata.sharedlib.client.view.OpenFileDialog.java

/**
 * Sets up the widgets./*from   w w  w.  ja v a  2 s.  c  om*/
 * 
 * @param url the url to post to.
 */
public void initWidgets(String url) {
    actionUrl = url;
    form.setAction(actionUrl);
    form.setEncoding(FormPanel.ENCODING_MULTIPART);
    form.setMethod(FormPanel.METHOD_POST);

    VerticalPanel verticalPanel = new VerticalPanel();
    verticalPanel.setSpacing(20);
    form.add(verticalPanel);

    fileUpload = new FileUpload();
    fileUpload.setName("filecontents");
    verticalPanel.add(fileUpload);

    HorizontalPanel horizontalPanel = new HorizontalPanel();
    horizontalPanel.setWidth("100%");
    horizontalPanel.setHeight("100%");
    horizontalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);

    Button button = new Button(constants.open(), new ClickHandler() {
        public void onClick(ClickEvent event) {
            String action = actionUrl;
            if (action.contains("?"))
                action += "&";
            else
                action += "?";
            action += "pathname=" + fileUpload.getFilename();
            //action += "&time="+ new java.util.Date().getTime();

            form.setAction(action);
            form.submit();
            //hide();

            FormUtil.dlg.setText(constants.processingMsg());
            FormUtil.dlg.center();
        }
    });

    horizontalPanel.add(button);
    horizontalPanel.setCellHorizontalAlignment(button, HasHorizontalAlignment.ALIGN_LEFT);

    button = new Button(constants.cancel(), new ClickHandler() {
        public void onClick(ClickEvent event) {
            hide();
            FormUtil.dlg.hide();
        }
    });

    horizontalPanel.add(button);
    horizontalPanel.setCellHorizontalAlignment(button, HasHorizontalAlignment.ALIGN_RIGHT);

    verticalPanel.add(horizontalPanel);

    setWidget(form);

    form.addSubmitCompleteHandler(new SubmitCompleteHandler() {
        public void onSubmitComplete(FormPanel.SubmitCompleteEvent event) {
            eventListener.onSetFileContents(event.getResults());
            hide();
            FormUtil.dlg.hide();
        }
    });

    setText(constants.openFile());
}