Search in sources :

Example 1 with FileDialogs

use of org.rstudio.studio.client.common.FileDialogs in project rstudio by rstudio.

the class RSConnectDeploy method onAddFileClick.

private void onAddFileClick() {
    FileDialogs dialogs = RStudioGinjector.INSTANCE.getFileDialogs();
    final FileSystemItem sourceDir = FileSystemItem.createDir(source_.getDeployDir());
    dialogs.openFile("Select File", RStudioGinjector.INSTANCE.getRemoteFileSystemContext(), sourceDir, new ProgressOperationWithInput<FileSystemItem>() {

        @Override
        public void execute(FileSystemItem input, ProgressIndicator indicator) {
            if (input != null) {
                String path = input.getPathRelativeTo(sourceDir);
                if (path == null) {
                    display_.showMessage(GlobalDisplay.MSG_INFO, "Cannot Add File", "Only files in the same folder as the " + "document (" + sourceDir + ") or one of its " + "sub-folders may be added.");
                    return;
                } else {
                    // see if the file is already in the list (we don't 
                    // want to duplicate an existing entry)
                    ArrayList<String> files = getFileList();
                    for (String file : files) {
                        if (file.equals(path)) {
                            indicator.onCompleted();
                            return;
                        }
                    }
                    addFileToList(path);
                    filesAddedManually_.add(path);
                }
            }
            indicator.onCompleted();
        }
    });
}
Also used : FileDialogs(org.rstudio.studio.client.common.FileDialogs) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ArrayList(java.util.ArrayList)

Example 2 with FileDialogs

use of org.rstudio.studio.client.common.FileDialogs in project rstudio by rstudio.

the class ProjectOpener method showOpenProjectDialog.

public void showOpenProjectDialog(FileSystemContext fsContext, ProjectsServerOperations server, String defaultLocation, int defaultType, boolean showNewSession, final ProgressOperationWithInput<OpenProjectParams> onCompleted) {
    initialize();
    // use the default dialog on desktop mode or single-session mode
    FileDialogs dialogs = RStudioGinjector.INSTANCE.getFileDialogs();
    if (Desktop.isDesktop() || !RStudioGinjector.INSTANCE.getSession().getSessionInfo().getMultiSession()) {
        dialogs.openFile("Open Project", fsContext, FileSystemItem.createDir(defaultLocation), "R Projects (*.Rproj)", true, new ProgressOperationWithInput<FileSystemItem>() {

            @Override
            public void execute(FileSystemItem input, final ProgressIndicator indicator) {
                final CommandWithArg<FileSystemItem> onProjectFileReady = new CommandWithArg<FileSystemItem>() {

                    @Override
                    public void execute(FileSystemItem item) {
                        onCompleted.execute(new OpenProjectParams(item, null, false), indicator);
                    }
                };
                // null return values here imply a cancellation
                if (input == null)
                    return;
                if (input.isDirectory()) {
                    final String rprojPath = input.completePath(input.getName() + ".Rproj");
                    final FileSystemItem rprojFile = FileSystemItem.createFile(rprojPath);
                    server_.createProjectFile(rprojFile.getPath(), new ServerRequestCallback<Boolean>() {

                        @Override
                        public void onResponseReceived(Boolean success) {
                            onProjectFileReady.execute(rprojFile);
                        }

                        @Override
                        public void onError(ServerError error) {
                            Debug.logError(error);
                            onProjectFileReady.execute(rprojFile);
                        }
                    });
                } else {
                    onProjectFileReady.execute(input);
                }
            }
        });
    } else {
        // in multi-session mode, we have a special dialog for opening projects
        WebFileDialogs webDialogs = (WebFileDialogs) dialogs;
        webDialogs.openProject(fsContext, FileSystemItem.createDir(defaultLocation), defaultType, showNewSession, onCompleted);
    }
}
Also used : OpenProjectParams(org.rstudio.studio.client.projects.model.OpenProjectParams) ServerError(org.rstudio.studio.client.server.ServerError) CommandWithArg(org.rstudio.core.client.CommandWithArg) WebFileDialogs(org.rstudio.studio.client.common.impl.WebFileDialogs) FileDialogs(org.rstudio.studio.client.common.FileDialogs) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) WebFileDialogs(org.rstudio.studio.client.common.impl.WebFileDialogs) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback)

Aggregations

FileSystemItem (org.rstudio.core.client.files.FileSystemItem)2 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)2 FileDialogs (org.rstudio.studio.client.common.FileDialogs)2 ArrayList (java.util.ArrayList)1 CommandWithArg (org.rstudio.core.client.CommandWithArg)1 WebFileDialogs (org.rstudio.studio.client.common.impl.WebFileDialogs)1 OpenProjectParams (org.rstudio.studio.client.projects.model.OpenProjectParams)1 ServerError (org.rstudio.studio.client.server.ServerError)1 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)1