Example usage for com.google.gwt.gears.client.desktop File getName

List of usage examples for com.google.gwt.gears.client.desktop File getName

Introduction

In this page you can find the example usage for com.google.gwt.gears.client.desktop File getName.

Prototype

public native String getName();

Source Link

Document

Gets the name of the file, excluding the path.

Usage

From source file:org.gss_project.gss.web.client.FileUploadGearsDialog.java

License:Open Source License

/**
 * Check whether the specified file name exists in the selected folder.
 *///  w w w  . j a v  a 2s  .  c om
private boolean canContinue(File file) {
    String fileName = getFilename(file.getName());
    if (getFileForName(fileName) == null)
        // For file creation, check to see if the file already exists.
        for (FileResource fileRes : files)
            if (!fileRes.isDeleted() && fileRes.getName().equals(fileName))
                return false;
    return true;
}

From source file:org.gss_project.gss.web.client.FileUploadGearsDialog.java

License:Open Source License

@Override
public void prepareAndSubmit() {
    GSS app = GSS.get();// www. j  a  va2s  .co m
    if (selectedFiles.size() == 0) {
        app.displayError("You must select a file!");
        hide();
        return;
    }
    for (File file : selectedFiles)
        if (!canContinue(file)) {
            app.displayError("The file name " + file.getName() + " already exists in this folder");
            hide();
            return;
        }
    submit.setEnabled(false);
    browse.setVisible(false);
    List<String> toUpdate = new ArrayList<String>();
    toRename = new HashMap<String, FileResource>();
    for (File file : selectedFiles) {
        String fname = getFilename(file.getName());
        if (getFileForName(fname) == null) {
            // We are going to create a file, so we check to see if there is a
            // trashed file with the same name.
            FileResource same = null;
            for (FileResource fres : folder.getFiles())
                if (fres.isDeleted() && fres.getName().equals(fname))
                    same = fres;
            // In that case add it to the list of files to rename.
            if (same != null)
                toRename.put(getBackupFilename(fname), same);
        } else
            // If we are updating a file add it to the list of files to update.
            toUpdate.add(fname);
    }

    if (!toUpdate.isEmpty()) {
        StringBuffer sb = new StringBuffer();
        for (String name : toUpdate)
            sb.append(name).append("<br/>");
        // We are going to update existing files, so show a confirmation dialog.
        ConfirmationDialog confirm = new ConfirmationDialog(
                "Are you sure " + "you want to update the following files?<br/><i>" + sb + "</i>", "Update") {

            @Override
            public void cancel() {
                hide();
            }

            @Override
            public void confirm() {
                confirmRename();
            }

        };
        confirm.center();
    } else
        confirmRename();
}