Search in sources :

Example 1 with DirectoryListing

use of org.rstudio.studio.client.workbench.views.files.model.DirectoryListing in project rstudio by rstudio.

the class NewPackagePage method validateAsync.

@Override
protected void validateAsync(final NewProjectResult input, final OperationWithInput<Boolean> onValidated) {
    // validate package name first
    String packageName = txtProjectName_.getText().trim();
    if (!isPackageNameValid(packageName)) {
        globalDisplay_.showMessage(MessageDialog.WARNING, "Error", "Invalid package name '" + packageName + "'. Package names " + "should start with a letter, and contain only letters and numbers.");
        onValidated.execute(false);
        return;
    }
    final FileSystemItem projFile = FileSystemItem.createFile(input.getProjectFile());
    final FileSystemItem projDir = projFile.getParentPath();
    server_.stat(projDir.getPath(), new ServerRequestCallback<FileSystemItem>() {

        @Override
        public void onResponseReceived(final FileSystemItem item) {
            // no file at this path -- safe for use
            if (!item.exists()) {
                onValidated.execute(true);
                return;
            }
            // if it was a file, bail
            if (!item.isDirectory()) {
                globalDisplay_.showMessage(MessageDialog.WARNING, "Error", "A file already exists at path '" + item.getPath() + "'");
                onValidated.execute(false);
                return;
            }
            // check if this directory is empty
            server_.listFiles(item, false, new ServerRequestCallback<DirectoryListing>() {

                @Override
                public void onResponseReceived(DirectoryListing listing) {
                    boolean ok = true;
                    JsArray<FileSystemItem> children = listing.getFiles();
                    for (FileSystemItem child : JsUtil.asIterable(children)) {
                        boolean canIgnore = child.getExtension().equals(".Rproj") || child.getName().startsWith(".");
                        if (canIgnore)
                            continue;
                        ok = false;
                        break;
                    }
                    if (!ok) {
                        globalDisplay_.showMessage(MessageDialog.WARNING, "Error", "Directory '" + item.getPath() + "' already exists and is not empty.");
                    }
                    onValidated.execute(ok);
                }

                @Override
                public void onError(ServerError error) {
                    Debug.logError(error);
                    onValidated.execute(true);
                }
            });
        }

        @Override
        public void onError(ServerError error) {
            Debug.logError(error);
            onValidated.execute(true);
        }
    });
}
Also used : DirectoryListing(org.rstudio.studio.client.workbench.views.files.model.DirectoryListing) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ServerError(org.rstudio.studio.client.server.ServerError) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback)

Example 2 with DirectoryListing

use of org.rstudio.studio.client.workbench.views.files.model.DirectoryListing in project rstudio by rstudio.

the class RemoteFileSystemContext method cd.

public void cd(String relativeOrAbsolutePath) {
    final String newPath = combine(workingDir_, relativeOrAbsolutePath);
    final FileSystemItem newPathEntry = FileSystemItem.createDir(newPath);
    final ArrayList<FileSystemItem> fsi = new ArrayList<FileSystemItem>();
    server_.listFiles(newPathEntry, // since this is used for the file dialog don't 
    false, // cause the call to reset the server monitoring state
    new ServerRequestCallback<DirectoryListing>() {

        @Override
        public void onError(ServerError error) {
            if (callbacks_ != null)
                callbacks_.onError(error.getUserMessage());
        }

        @Override
        public void onResponseReceived(final DirectoryListing response) {
            final JsArray<FileSystemItem> files = response.getFiles();
            for (int i = 0; i < files.length(); i++) fsi.add(files.get(i));
            workingDir_ = newPath;
            contents_ = fsi.toArray(new FileSystemItem[0]);
            if (callbacks_ != null)
                callbacks_.onNavigated();
        }
    });
}
Also used : DirectoryListing(org.rstudio.studio.client.workbench.views.files.model.DirectoryListing) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) JsArray(com.google.gwt.core.client.JsArray) ServerError(org.rstudio.studio.client.server.ServerError) ArrayList(java.util.ArrayList)

Aggregations

FileSystemItem (org.rstudio.core.client.files.FileSystemItem)2 ServerError (org.rstudio.studio.client.server.ServerError)2 DirectoryListing (org.rstudio.studio.client.workbench.views.files.model.DirectoryListing)2 JsArray (com.google.gwt.core.client.JsArray)1 ArrayList (java.util.ArrayList)1 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)1