Search in sources :

Example 1 with OpenProjectParams

use of org.rstudio.studio.client.projects.model.OpenProjectParams 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

CommandWithArg (org.rstudio.core.client.CommandWithArg)1 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)1 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)1 FileDialogs (org.rstudio.studio.client.common.FileDialogs)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