Java Code Examples for com.google.gwt.user.client.ui.FileUpload

The following examples show how to use com.google.gwt.user.client.ui.FileUpload. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: core   Source File: UploadStep.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected Widget asWidget(final Context context) {
    final FlowPanel panel = new FlowPanel();

    HTML description = new HTML(Console.CONSTANTS.common_label_chooseFile());
    description.getElement().setAttribute("style", "padding-bottom:15px;");
    panel.add(description);

    form = new FormPanel();

    // create a panel to hold all of the form widgets.
    VerticalPanel formPanel = new VerticalPanel();
    form.setWidget(formPanel);

    // create a FileUpload widgets.
    fileUpload = new FileUpload();
    fileUpload.setName("uploadFormElement");
    IdHelper.setId(fileUpload, id(), "file");
    formPanel.add(fileUpload);

    panel.add(form);
    return panel;
}
 
Example 2
private void loadJSONfile(FileUpload filePath, Boolean doUpdate) {
  String uploadFilename = filePath.getFilename();
  if (!uploadFilename.isEmpty()) {
    final String filename = makeValidFilename(uploadFilename);
    if (!TextValidators.isValidCharFilename(filename)) {
      Window.alert(MESSAGES.malformedFilename());
    } else if (!TextValidators.isValidLengthFilename(filename)) {
      Window.alert(MESSAGES.malformedFilename());
    } else if (!filename.endsWith(".json")){
      Window.alert(MESSAGES.malformedFilenameTitle());
    } else {
      loadJSONfileNative(filePath.getElement(), doUpdate);
    }
  }
}
 
Example 3
public void execute() {
	if (toolBarOption.addDocumentOption) {
		FileToUpload fileToUpload = new FileToUpload();
		fileToUpload.setFileUpload(new FileUpload());
		fileToUpload.setPath((String) Main.get().activeFolderTree.getActualPath());
		fileToUpload.setAction(UIFileUploadConstants.ACTION_INSERT);
		Main.get().fileUpload.addPendingFileToUpload(fileToUpload);
		Main.get().activeFolderTree.hideMenuPopup();
	}
}
 
Example 4
Source Project: core   Source File: PatchManager.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
public void upload(FileUpload fileUpload, boolean overrideConflict,
        AsyncCallback<UploadResponse> callback) {
    ModelNode patchOp = baseAddress();
    patchOp.get(OP).set("patch");
    patchOp.get("content").add().get("input-stream-index").set(0);
    if (overrideConflict) {
        patchOp.get("override-all").set(true);
    }
    dispatcher.execute(new UploadAction(fileUpload.getElement(), patchOp), callback);
}
 
Example 5
Source Project: core   Source File: SelectPatchStep.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected IsWidget body(final ApplyContext context) {
    FormPanel form = new FormPanel();
    FlowPanel panel = new FlowPanel();
    form.setWidget(panel);
    panel.add(new Label(Console.CONSTANTS.patch_manager_select_patch_body()));

    if (!context.standalone) {
        info = new HTML("");
        info.getElement().getStyle().setMarginTop(2, Style.Unit.EM);
        panel.add(info);
    }

    FlowPanel uploadPanel = new FlowPanel();
    uploadPanel.getElement().getStyle().setMarginTop(2, Style.Unit.EM);
    InlineLabel uploadLabel = new InlineLabel(Console.CONSTANTS.patch_manager_select_patch_upload());
    uploadLabel.getElement().getStyle().setMarginRight(1, Style.Unit.EM);
    uploadPanel.add(uploadLabel);
    context.fileUpload = new FileUpload();
    context.fileUpload.setName("patch_file");
    context.fileUpload.getElement().setId(asId(PREFIX, getClass(), "_Upload"));
    uploadPanel.add(context.fileUpload);
    panel.add(uploadPanel);

    errorMessages = new HTML(
            "<i class=\"icon-exclamation-sign\"></i> " + Console.CONSTANTS.patch_manager_select_file());
    errorMessages.addStyleName("error");
    errorMessages.setVisible(false);
    panel.add(errorMessages);

    return form;
}
 
Example 6
public UploadContent(final DispatchAsync dispatcher, final FileUpload fileUpload, final UploadBean upload,
        final boolean replace) {
    this.dispatcher = dispatcher;
    this.fileUpload = fileUpload;
    this.upload = upload;
    this.replace = replace;
}
 
Example 7
/**
 * Creates a new keystore upload wizard.
 */
public KeystoreUploadWizard(final Command callbackAfterUpload) {
  super(MESSAGES.keystoreUploadWizardCaption(), true, false);

  // Initialize UI
  final FileUpload upload = new FileUpload();
  upload.setName(ServerLayout.UPLOAD_USERFILE_FORM_ELEMENT);
  upload.getElement().setAttribute("accept", KEYSTORE_EXTENSION);
  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();
      }
    }
  });
}
 
Example 8
/**
 * Creates a new project upload wizard.
 */
public ProjectUploadWizard() {
  super(MESSAGES.projectUploadWizardCaption(), true, false);

  // Initialize UI
  final FileUpload upload = new FileUpload();
  upload.setName(ServerLayout.UPLOAD_PROJECT_ARCHIVE_FORM_ELEMENT);
  upload.getElement().setAttribute("accept", PROJECT_ARCHIVE_EXTENSION);
  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();
      }
    }
  });
}
 
Example 9
private FileUpload createFileUpload() {
  FileUpload upload = new FileUpload();
  upload.setName(ServerLayout.UPLOAD_COMPONENT_ARCHIVE_FORM_ELEMENT);
  upload.getElement().setAttribute("accept", COMPONENT_ARCHIVE_EXTENSION);
  return upload;
}
 
Example 10
public ComponentUploadWizard() {
  super(MESSAGES.componentUploadWizardCaption(), true, false);

  final FileUpload uploadWiget = new FileUpload();
  uploadWiget.getElement().setAttribute("accept", COMPONENT_ARCHIVE_EXTENSION);
  uploadWiget.setName(ServerLayout.UPLOAD_COMPONENT_ARCHIVE_FORM_ELEMENT);

  VerticalPanel panel = new VerticalPanel();
  panel.setVerticalAlignment(VerticalPanel.ALIGN_MIDDLE);
  panel.add(uploadWiget);

  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);
    }
  });
}
 
Example 11
public NotEmptyFileUploadValidator(FileUpload fileUpload) {
	this.fileUpload = fileUpload;
	this.setCustomMsgKey(null);
	this.preventsPropagationOfValidationChain();
}
 
Example 12
public void invokeActions(ValidationResult result) {
	if (fileUpload != null) {
		for (ValidationAction<FileUpload> action : getFailureActions())
			action.invoke(result, fileUpload);
	}
}
 
Example 13
public FileUpload getFileUpload() {
	return fileUpload;
}
 
Example 14
public void setFileUpload(FileUpload fileUpload) {
	this.fileUpload = fileUpload;
}