Search in sources :

Example 6 with ServerRequestCallback

use of org.rstudio.studio.client.server.ServerRequestCallback in project rstudio by rstudio.

the class ProfilerEditingTarget method saveNewFile.

private void saveNewFile(final String suggestedPath) {
    FileSystemItem fsi;
    if (suggestedPath != null)
        fsi = FileSystemItem.createFile(suggestedPath).getParentPath();
    else
        fsi = workbenchContext_.getDefaultFileDialogDir();
    fileDialogs_.saveFile("Save File - " + getName().getValue(), fileContext_, fsi, fileType_.getDefaultExtension(), false, new ProgressOperationWithInput<FileSystemItem>() {

        public void execute(final FileSystemItem saveItem, final ProgressIndicator indicator) {
            if (saveItem == null)
                return;
            workbenchContext_.setDefaultFileDialogDir(saveItem.getParentPath());
            final String toPath = saveItem.getPath();
            server_.copyProfile(htmlLocalPath_, toPath, new ServerRequestCallback<JavaScriptObject>() {

                @Override
                public void onResponseReceived(JavaScriptObject response) {
                    savePropertiesWithPath(saveItem.getPath());
                    persistDocumentProperty("isUserSaved", "saved");
                    isUserSaved_ = true;
                    indicator.onCompleted();
                }

                @Override
                public void onError(ServerError error) {
                    Debug.logError(error);
                    indicator.onCompleted();
                    globalDisplay_.showErrorMessage("Failed to Save Profile", error.getMessage());
                }
            });
        }
    });
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ServerError(org.rstudio.studio.client.server.ServerError) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback)

Example 7 with ServerRequestCallback

use of org.rstudio.studio.client.server.ServerRequestCallback in project rstudio by rstudio.

the class GeneralPreferencesPane method initialize.

@Override
protected void initialize(RPrefs rPrefs) {
    // general prefs
    final GeneralPrefs generalPrefs = rPrefs.getGeneralPrefs();
    showServerHomePage_.setEnabled(true);
    reuseSessionsForProjectLinks_.setEnabled(true);
    saveWorkspace_.setEnabled(true);
    loadRData_.setEnabled(true);
    dirChooser_.setEnabled(true);
    showServerHomePage_.setValue(generalPrefs.getShowUserHomePage());
    reuseSessionsForProjectLinks_.setValue(generalPrefs.getReuseSessionsForProjectLinks());
    int saveWorkspaceIndex;
    switch(generalPrefs.getSaveAction()) {
        case SaveAction.NOSAVE:
            saveWorkspaceIndex = 1;
            break;
        case SaveAction.SAVE:
            saveWorkspaceIndex = 0;
            break;
        case SaveAction.SAVEASK:
        default:
            saveWorkspaceIndex = 2;
            break;
    }
    saveWorkspace_.getListBox().setSelectedIndex(saveWorkspaceIndex);
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

        @Override
        public void execute() {
            server_.getTerminalShells(new ServerRequestCallback<JsArray<TerminalShellInfo>>() {

                @Override
                public void onResponseReceived(JsArray<TerminalShellInfo> shells) {
                    int currentShell = generalPrefs.getDefaultTerminalShellValue();
                    int currentShellIndex = 0;
                    GeneralPreferencesPane.this.terminalShell_.getListBox().clear();
                    for (int i = 0; i < shells.length(); i++) {
                        TerminalShellInfo info = shells.get(i);
                        GeneralPreferencesPane.this.terminalShell_.addChoice(info.getShellName(), Integer.toString(info.getShellType()));
                        if (info.getShellType() == currentShell)
                            currentShellIndex = i;
                    }
                    if (GeneralPreferencesPane.this.terminalShell_.getListBox().getItemCount() > 0) {
                        GeneralPreferencesPane.this.terminalShell_.setEnabled((true));
                        GeneralPreferencesPane.this.terminalShell_.getListBox().setSelectedIndex(currentShellIndex);
                    }
                }

                @Override
                public void onError(ServerError error) {
                }
            });
        }
    });
    loadRData_.setValue(generalPrefs.getLoadRData());
    dirChooser_.setText(generalPrefs.getInitialWorkingDirectory());
    // history prefs
    HistoryPrefs historyPrefs = rPrefs.getHistoryPrefs();
    alwaysSaveHistory_.setEnabled(true);
    removeHistoryDuplicates_.setEnabled(true);
    alwaysSaveHistory_.setValue(historyPrefs.getAlwaysSave());
    removeHistoryDuplicates_.setValue(historyPrefs.getRemoveDuplicates());
    rProfileOnResume_.setValue(generalPrefs.getRprofileOnResume());
    rProfileOnResume_.setEnabled(true);
    showLastDotValue_.setValue(generalPrefs.getShowLastDotValue());
    showLastDotValue_.setEnabled(true);
    if (rServerRVersion_ != null)
        rServerRVersion_.setRVersion(generalPrefs.getDefaultRVersion());
    if (rememberRVersionForProjects_ != null) {
        rememberRVersionForProjects_.setValue(generalPrefs.getRestoreProjectRVersion());
    }
    // projects prefs
    ProjectsPrefs projectsPrefs = rPrefs.getProjectsPrefs();
    restoreLastProject_.setEnabled(true);
    restoreLastProject_.setValue(projectsPrefs.getRestoreLastProject());
}
Also used : GeneralPrefs(org.rstudio.studio.client.workbench.prefs.model.GeneralPrefs) TerminalShellInfo(org.rstudio.studio.client.workbench.views.terminal.TerminalShellInfo) JsArray(com.google.gwt.core.client.JsArray) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) ServerError(org.rstudio.studio.client.server.ServerError) ProjectsPrefs(org.rstudio.studio.client.workbench.prefs.model.ProjectsPrefs) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) HistoryPrefs(org.rstudio.studio.client.workbench.prefs.model.HistoryPrefs)

Example 8 with ServerRequestCallback

use of org.rstudio.studio.client.server.ServerRequestCallback in project rstudio by rstudio.

the class RemoteServerAuth method schedulePeriodicCredentialsUpdate.

public void schedulePeriodicCredentialsUpdate() {
    // create the callback
    periodicUpdateTimer_ = new Timer() {

        @Override
        public void run() {
            updateCredentials(new ServerRequestCallback<Integer>() {

                @Override
                public void onResponseReceived(Integer response) {
                    switch(response) {
                        case CREDENTIALS_UPDATE_SUCCESS:
                            // credentials)
                            break;
                        case CREDENTIALS_UPDATE_FAILURE:
                            // we are not authorized, blow the client away
                            remoteServer_.handleUnauthorizedError();
                            break;
                        case CREDENTIALS_UPDATE_UNSUPPORTED:
                            // not supported by the back end so cancel the timer
                            periodicUpdateTimer_.cancel();
                            break;
                    }
                }

                @Override
                public void onError(ServerError serverError) {
                    // if method is not supported then cancel the timer
                    Debug.logError(serverError);
                }
            });
        }
    };
    // schedule for every 5 minutes
    final int kMinutes = 5;
    int milliseconds = kMinutes * 60 * 1000;
    periodicUpdateTimer_.scheduleRepeating(milliseconds);
}
Also used : Timer(com.google.gwt.user.client.Timer) ServerError(org.rstudio.studio.client.server.ServerError) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback)

Example 9 with ServerRequestCallback

use of org.rstudio.studio.client.server.ServerRequestCallback 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)

Example 10 with ServerRequestCallback

use of org.rstudio.studio.client.server.ServerRequestCallback 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)

Aggregations

ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)21 ServerError (org.rstudio.studio.client.server.ServerError)20 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)5 Void (org.rstudio.studio.client.server.Void)5 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)4 Operation (org.rstudio.core.client.widget.Operation)4 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)4 JsArray (com.google.gwt.core.client.JsArray)3 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)3 SourceDocument (org.rstudio.studio.client.workbench.views.source.model.SourceDocument)3 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)2 Command (com.google.gwt.user.client.Command)2 Timer (com.google.gwt.user.client.Timer)2 Handler (org.rstudio.core.client.command.Handler)2 ProfileOperationResponse (org.rstudio.studio.client.workbench.views.source.editors.profiler.model.ProfileOperationResponse)2 JsArrayString (com.google.gwt.core.client.JsArrayString)1 Element (com.google.gwt.dom.client.Element)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1