Example usage for com.google.gwt.user.client.ui FileUpload FileUpload

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

Introduction

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

Prototype

public FileUpload() 

Source Link

Document

Constructs a new file upload widget.

Usage

From source file:br.com.pegasus.solutions.smartgwt.lib.client.upload.FileUploader.java

License:Apache License

public FileUploader(String textLabelUpload, String labelWidth, String submitBtnName, String iconSubmitBtn,
        String progressDescription) {
    this.form = new FormPanel();
    this.form.setMethod("post");
    this.form.addStyleName("gwtFormPanel");
    this.form.setEncoding("multipart/form-data");

    this.progressbar = FM.buildProgressBar(500);
    this.submitBtnName = submitBtnName;
    this.iconSubmitBtn = iconSubmitBtn;
    this.progressDescription = progressDescription;
    buildUploadButton();//from   w  w w.  ja v a2 s  .c om

    VLayout panel = new VLayout();
    panel.setHeight(20);
    this.fileUpload = new FileUpload();
    this.fileUpload.setName("upload");

    com.google.gwt.user.client.ui.Label labelUpload = new com.google.gwt.user.client.ui.Label(
            textLabelUpload + ":");
    if (labelWidth != null) {
        labelUpload.setWidth(labelWidth);
    } else {
        labelUpload.setWidth(this.labelWidth);
    }
    HLayout line1 = new HLayout();
    line1.addMember(labelUpload);
    line1.addMember(this.fileUpload);

    panel.addMember(line1);

    addEvents();
    this.form.setHeight(formHeight);
    this.form.setWidth(formWidth);
    this.form.add(panel);
}

From source file:com.ait.toolkit.clientio.uploader.client.Uploader.java

License:Apache License

private FileUpload createFileUpload() {
    fileUpload = new FileUpload();
    fileUpload.getElement().getStyle().setDisplay(Style.Display.NONE);

    if (fileTypes != null) {
        // Convert the format that the SWFUpload/Flash parameter expects to the W3C DOM standard
        // See: http://dev.w3.org/html5/spec/states-of-the-type-attribute.html#attr-input-accept
        fileUpload.getElement().setAttribute("accept",
                this.fileTypes.replaceAll("\\;", ",").replaceAll("\\*\\.", "."));

        // TODO: Need to consider validation of this in the file queued handler as well, as the browsers don't
        // appear to consistently support the "accept" attribute
    }//from   w  w w  .j  a  va  2  s.  c om

    final AbsolutePanel panel = this;

    fileUpload.addChangeHandler(new ChangeHandler() {
        public void onChange(ChangeEvent event) {

            JsArray selectedFiles = nativeGetSelectedFiles(fileUpload.getElement());

            // Every time a file is selected replace the FileUpload component running in the DOM so that
            // the user can continue to attempt uploading the same file multiple times (otherwise the
            // "ChangeHandler" never fires)
            panel.remove(fileUpload);
            panel.add(createFileUpload());

            addFilesToQueue(selectedFiles);

        }
    });
    return fileUpload;
}

From source file:com.audata.client.widgets.UploadPanel.java

License:Open Source License

public UploadPanel() {
    VerticalPanel main = new VerticalPanel();

    this.file = new FileUpload();
    this.file.setName("document");

    this.recid = new Hidden();
    this.recid.setName("recid");

    Hidden method = new Hidden();
    method.setName("method");
    method.setValue("put");

    main.add(this.recid);
    main.add(method);/* ww w.  j av  a2s.c  om*/
    main.add(this.file);
    this.add(main);
}

From source file:com.codenvy.ide.client.wizard.project.imports.ImportFileViewImpl.java

License:Apache License

/** {@inheritDoc} */
@Override//w w w  .j a  v  a2s .  c  o m
public void showDialog() {
    uploadForm.setEncoding(FormPanel.ENCODING_MULTIPART);
    uploadForm.setMethod(FormPanel.METHOD_POST);

    VerticalPanel panel = new VerticalPanel();
    uploadForm.setWidget(panel);

    file = new FileUpload();
    file.setName("ImportFile");
    file.setHeight("26px");
    file.setWidth("100%");
    file.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent changeEvent) {
            if (!file.getFilename().endsWith(".dbs")) {
                delegate.onFileNameChangedWithInvalidFormat();
            } else {
                delegate.onFileNameChanged();
            }
        }
    });
    panel.add(file);
    this.center();
    this.show();
}

From source file:com.codenvy.ide.ext.wso2.client.upload.ImportFileViewImpl.java

License:Open Source License

/** {@inheritDoc} */
@Override//w ww.ja v  a2s.  c  om
public void showDialog() {
    uploadForm.setEncoding(ENCODING_MULTIPART);
    uploadForm.setMethod(METHOD_POST);

    file = new FileUpload();
    file.setName("file");
    file.setHeight("26px");
    file.setWidth("100%");
    file.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent changeEvent) {
            if (!file.getFilename().endsWith(".xml")) {
                delegate.onFileNameChangedWithInvalidFormat();
            } else {
                delegate.onFileNameChanged();
            }
        }
    });

    uploadForm.setWidget(file);

    show();
}

From source file:com.dawg6.web.dhcalc.client.SavePanel.java

License:Open Source License

public SavePanel() {

    CaptionPanel captionPanel = new CaptionPanel("Save/Load");
    initWidget(captionPanel);//from   w  ww.  j a  va 2 s.  c o  m

    FlexTable flexTable_3 = new FlexTable();
    flexTable_3.setCellPadding(2);
    captionPanel.setContentWidget(flexTable_3);

    tabPanel = new TabPanel();
    flexTable_3.setWidget(0, 0, tabPanel);

    browserPanel = new FlexTable();
    browserPanel.setCellPadding(2);

    if (Storage.isLocalStorageSupported()) {
        tabPanel.add(browserPanel, "Browser Storage", false);
    }

    storageList = new ListBox();
    browserPanel.setWidget(0, 0, storageList);
    storageList.setWidth("100%");
    storageList.setVisibleItemCount(5);

    nameField = new TextBox();
    nameField.setVisibleLength(30);
    nameField.setText("Enter a Name");
    browserPanel.setWidget(1, 0, nameField);

    Button btnNewButton = new Button("New button");
    browserPanel.setWidget(1, 1, btnNewButton);
    btnNewButton.setText("Add");

    btnNewButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            addLocalStorage();
        }
    });

    HorizontalPanel horizontalPanel = new HorizontalPanel();
    horizontalPanel.setSpacing(5);
    horizontalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    browserPanel.setWidget(2, 0, horizontalPanel);

    Button button_6 = new Button("New button");
    button_6.setText("Save");
    horizontalPanel.add(button_6);

    button_6.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            saveLocalStorage();
        }
    });

    Button button_5 = new Button("New button");
    horizontalPanel.add(button_5);
    button_5.setText("Restore");

    button_5.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            restoreLocalStorage();
        }
    });

    Button button_2 = new Button("New button");
    horizontalPanel.add(button_2);
    button_2.setText("Delete");

    button_2.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            deleteLocalStorage();
        }
    });

    Button btnNewButton_1 = new Button("New button");
    horizontalPanel.add(btnNewButton_1);
    btnNewButton_1.setText("Rename");

    btnNewButton_1.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            renameLocalStorage();
        }
    });

    browserPanel.getFlexCellFormatter().setColSpan(0, 0, 1);
    browserPanel.getFlexCellFormatter().setColSpan(2, 0, 1);
    browserPanel.getFlexCellFormatter().setColSpan(0, 0, 2);
    browserPanel.getFlexCellFormatter().setColSpan(2, 0, 2);
    browserPanel.getCellFormatter().setHorizontalAlignment(2, 0, HasHorizontalAlignment.ALIGN_CENTER);

    filePanel = new FlexTable();
    filePanel.setCellPadding(2);
    tabPanel.add(filePanel, "Local File", false);

    HorizontalPanel horizontalPanel_1 = new HorizontalPanel();
    filePanel.setWidget(0, 0, horizontalPanel_1);

    loadPanel = new FormPanel();
    loadPanel.setMethod(FormPanel.METHOD_POST);
    loadPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
    loadPanel.setAction("loadData");
    horizontalPanel_1.add(loadPanel);

    HorizontalPanel horizontalPanel_2 = new HorizontalPanel();
    loadPanel.setWidget(horizontalPanel_2);
    horizontalPanel_2.setSize("100%", "100%");

    fileUpload = new FileUpload();
    fileUpload.setName("file");
    horizontalPanel_2.add(fileUpload);

    clientKey = new Hidden("client");
    horizontalPanel_2.add(clientKey);
    filePanel.getFlexCellFormatter().setColSpan(0, 0, 1);

    Button button = new Button("Save Data...");
    filePanel.setWidget(1, 0, button);
    button.setText("Save File");

    Button button_1 = new Button("Load Data...");
    filePanel.setWidget(1, 1, button_1);
    button_1.setText("Load File");
    filePanel.getFlexCellFormatter().setColSpan(0, 0, 2);
    filePanel.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER);
    filePanel.getCellFormatter().setHorizontalAlignment(1, 1, HasHorizontalAlignment.ALIGN_CENTER);

    button_1.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            loadFile();

        }
    });

    button.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            saveFile();

        }
    });

    textPanel = new FlexTable();
    textPanel.setCellPadding(2);
    tabPanel.add(textPanel, "Copy/Paste", false);

    textArea = new TextArea();
    textArea.setText(
            "Paste previously saved form data here and click \"Restore.\" Or press \"Current\" to paste current Form data.");
    textArea.setVisibleLines(5);
    textPanel.setWidget(0, 0, textArea);
    textArea.setSize("100%", "");

    Button button_3 = new Button("Save Data...");
    button_3.setText("Current");
    textPanel.setWidget(1, 0, button_3);

    textArea.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            textArea.selectAll();
        }
    });

    nameField.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            nameField.selectAll();
        }
    });

    button_3.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {

            if (listener != null) {

                FormData data = listener.getFormData();

                JSONObject obj = JsonUtil.toJSONObject(data);
                textArea.setText(JsonUtil.formatJsonText(obj.toString()));
                textArea.selectAll();
            }

        }
    });

    Button button_4 = new Button("Load Data...");
    button_4.setText("Restore");

    button_4.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            if (listener != null) {
                String text = textArea.getText();

                FormData data = JsonUtil.parseFormData(text);

                listener.setFormData(data);
                textArea.setText("");
            }

        }
    });

    textPanel.setWidget(1, 1, button_4);
    textPanel.getFlexCellFormatter().setColSpan(0, 0, 2);
    textPanel.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER);
    textPanel.getCellFormatter().setHorizontalAlignment(1, 1, HasHorizontalAlignment.ALIGN_CENTER);

    flexTable_3.getFlexCellFormatter().setColSpan(0, 0, 1);

    storageList.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            int i = storageList.getSelectedIndex();

            if (i >= 0) {
                String name = storageList.getItemText(i);

                if (name != null)
                    nameField.setText(name);
            }

        }
    });
}

From source file:com.dimdim.conference.ui.resources.client.SelectOnlyFileDialog.java

License:Open Source License

protected Widget getContent() {
    VerticalPanel contentPanel = new VerticalPanel();
    contentPanel.setStyleName("powerpoint-info-text");

    //Label comment1 = new Label(ResourceGlobals.getResourceGlobals().getSelectFileComment1().replaceAll("file",this.docType));
    Label comment1 = new Label(ResourceGlobals.getResourceGlobals().getSelectFileComment1());
    comment1.setStyleName("change-photo-picture-caption");
    comment1.addStyleName("common-text");
    comment1.addStyleName("common-4px-top-bottom-spacing");
    comment1.setWordWrap(true);//from w  ww . j  av  a  2 s . c o  m
    //      comment1.setWidth("200px");
    //      comment1.setWidth("250px");

    contentPanel.add(comment1);
    contentPanel.add(new HTML(" "));

    this.selectFileForm = new FormPanel();
    this.selectFileForm.setAction(this.commandURLFactory.getPhotoUploadURL());
    this.selectFileForm.setEncoding(FormPanel.ENCODING_MULTIPART);
    this.selectFileForm.setMethod(FormPanel.METHOD_POST);

    this.existingFileField = new FileUpload();
    this.existingFileField.setName("photo");
    this.selectFileForm.add(this.existingFileField);
    this.existingFileField.setStyleName("photo-file-upload-field");

    contentPanel.add(this.selectFileForm);

    contentPanel.add(new HTML(" "));
    this.errorMessage.setStyleName("common-text");
    contentPanel.add(this.errorMessage);

    return contentPanel;
}

From source file:com.dimdim.conference.ui.user.client.ChangePictureDialog.java

License:Open Source License

protected Widget getContent() {
    VerticalPanel contentPanel = new VerticalPanel();
    contentPanel.setStyleName("change-photo-content-panel");
    String defaultPhotoUrl = UserGlobals.getUserGlobals().getDefaultPhotoUrl();
    String currentPhotoUrl = this.me.getPhotoUrl();

    //Window.alert("inside chage picture");
    this.defaultPhotoButton = new RadioButton("PhotoSelection");
    this.defaultPhotoButton.addClickListener(this);
    this.defaultPhotoButton.setStyleName("change-photo-radio-button");
    this.customPhotoButton = new RadioButton("PhotoSelection");
    this.customPhotoButton.addClickListener(this);
    this.customPhotoButton.setStyleName("change-photo-radio-button");

    //   Custom Photo caption

    Label comment1 = new Label(UserGlobals.getUserGlobals().getChangePictureComment1());
    comment1.setStyleName("change-photo-picture-caption");
    comment1.addStyleName("common-text");
    contentPanel.add(comment1);// w  w w .  j  a v  a 2  s  .co m

    Label comment2 = new Label(UserGlobals.getUserGlobals().getChangePictureComment2());
    comment2.setStyleName("change-photo-picture-caption");
    comment2.addStyleName("common-text");
    contentPanel.add(comment2);

    HorizontalPanel customPhotoCaption = new HorizontalPanel();
    customPhotoCaption.setStyleName("change-photo-picture-caption");
    customPhotoCaption.add(this.customPhotoButton);
    Label label2 = new Label(UIStrings.getChangePhotoLabel());
    label2.setStyleName("common-text");
    label2.addStyleName("change-photo-label");
    customPhotoCaption.add(label2);

    //      HorizontalPanel uploadCaption = new HorizontalPanel();
    //      uploadCaption.setStyleName("change-photo-picture-caption");
    //      this.uploadLink = new Label("Upload");
    //      this.uploadLink.addClickListener(this);
    //      this.uploadLink.setStyleName("common-text");
    //      this.uploadLink.addStyleName("change-photo-upload-label");
    //      this.uploadLink.addStyleName("common-anchor");
    //      uploadCaption.add(this.uploadLink);

    //   Create a form panel for the photo file upload.

    this.photoUploadForm = new FormPanel();
    this.photoUploadForm.setAction(this.commandURLFactory.getPhotoUploadURL());
    this.photoUploadForm.setEncoding(FormPanel.ENCODING_MULTIPART);
    this.photoUploadForm.setMethod(FormPanel.METHOD_POST);

    this.photoUploadField = new FileUpload();
    this.photoUploadField.setName("photo");
    this.photoUploadForm.add(this.photoUploadField);
    this.photoUploadField.setStyleName("photo-file-upload-field");

    contentPanel.add(customPhotoCaption);
    contentPanel.add(this.photoUploadForm);
    //      contentPanel.add(uploadCaption);

    //   Default Photo Caption

    HorizontalPanel defaultPhotoCaption = new HorizontalPanel();
    defaultPhotoCaption.setStyleName("change-photo-picture-caption");
    defaultPhotoCaption.add(this.defaultPhotoButton);
    Label label1 = new Label(UIStrings.getUseDefaultPhotoLabel());
    label1.setStyleName("common-text");
    label1.addStyleName("change-photo-label");
    defaultPhotoCaption.add(label1);
    if (UserGlobals.getUserGlobals().isPhotoUrlDefault(currentPhotoUrl)) {
        this.defaultPhotoButton.setChecked(true);
        this.customPhotoButton.setChecked(false);
    } else {
        this.defaultPhotoButton.setChecked(false);
        this.customPhotoButton.setChecked(true);
    }
    contentPanel.add(defaultPhotoCaption);

    //   Photo Panel

    if (currentPhotoUrl == null || currentPhotoUrl.length() == 0) {
        currentPhotoUrl = defaultPhotoUrl;
    }
    Image photoImage = new Image(currentPhotoUrl);
    photoImage.setStyleName("change-photo-picture");
    contentPanel.add(photoImage);
    contentPanel.setCellVerticalAlignment(photoImage, VerticalPanel.ALIGN_MIDDLE);
    contentPanel.setCellHorizontalAlignment(photoImage, HorizontalPanel.ALIGN_LEFT);

    //      this.photoUploadField.setVisible(false);
    //      this.uploadLink.setVisible(false);

    return contentPanel;
}

From source file:com.dingziran.effective.client.content.widgets.CwFileUpload.java

License:Apache License

/**
 * Constructor.//from ww w.  j  av a  2  s .c o m
 *
 * @param constants the constants
 */
public CwFileUpload(CwConstants constants) {
    super(constants.cwFileUploadName(), constants.cwFileUploadDescription());
    this.constants = constants;
    view = new ContentWidgetView(hasMargins(), hasScrollableContent());
    view.setName(getName());
    view.setDescription(getDescription());
    setWidget(view);
    // Create a vertical panel to align the content
    VerticalPanel vPanel = new VerticalPanel();

    // Add a label
    vPanel.add(new HTML(constants.cwFileUploadSelectFile()));

    // Add a file upload widget
    final FileUpload fileUpload = new FileUpload();
    fileUpload.ensureDebugId("cwFileUpload");
    vPanel.add(fileUpload);
    final String msg1 = constants.cwFileUploadNoFileError();
    final String msg2 = constants.cwFileUploadSuccessful();

    // Add a button to upload the file
    Button uploadButton = new Button(constants.cwFileUploadButton());
    uploadButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            String filename = fileUpload.getFilename();
            if (filename.length() == 0) {
                Window.alert(msg1);
            } else {
                Window.alert(msg2);
            }
        }
    });
    vPanel.add(new HTML("<br>"));
    vPanel.add(uploadButton);

    view.setExample(vPanel);
}

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 ww w .  ja v a  2s .c  om*/
    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);
}