Search in sources :

Example 61 with ServerError

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

the class BreakpointManager method clearAllBreakpoints.

private void clearAllBreakpoints() {
    Set<FileFunction> functions = new TreeSet<FileFunction>();
    for (Breakpoint breakpoint : breakpoints_) {
        breakpoint.setState(Breakpoint.STATE_REMOVING);
        if (breakpoint.getType() == Breakpoint.TYPE_FUNCTION)
            functions.add(new FileFunction(breakpoint));
    }
    // set previously
    for (FileFunction function : functions) {
        server_.setFunctionBreakpoints(function.functionName, function.fileName, function.packageName, new ArrayList<String>(), new ServerRequestCallback<Void>() {

            @Override
            public void onError(ServerError error) {
            // There's a possibility here that the breakpoints were
            // not successfully cleared, so we may be in a temporarily
            // confusing state, but no error message will be less 
            // confusing. 
            }
        });
    }
    server_.removeAllBreakpoints(new VoidServerRequestCallback());
    notifyBreakpointsSaved(new ArrayList<Breakpoint>(breakpoints_), false);
    breakpoints_.clear();
    onBreakpointAddOrRemove();
}
Also used : Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint) TreeSet(java.util.TreeSet) ServerError(org.rstudio.studio.client.server.ServerError) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) Void(org.rstudio.studio.client.server.Void)

Example 62 with ServerError

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

the class BreakpointManager method prepareAndSetFunctionBreakpoints.

private void prepareAndSetFunctionBreakpoints(final FileFunction function) {
    // look over the list of breakpoints in this function and see if any are
    // marked inactive, or if they need their steps refreshed (necessary
    // when a function has had steps added or removed in the editor)
    final ArrayList<Breakpoint> inactiveBreakpoints = new ArrayList<Breakpoint>();
    int[] inactiveLines = new int[] {};
    int numLines = 0;
    for (Breakpoint breakpoint : breakpoints_) {
        if (function.containsBreakpoint(breakpoint) && (breakpoint.getState() != Breakpoint.STATE_ACTIVE || breakpoint.needsUpdatedSteps())) {
            inactiveBreakpoints.add(breakpoint);
            inactiveLines[numLines++] = breakpoint.getLineNumber();
        }
    }
    // corresponding steps from the function 
    if (inactiveBreakpoints.size() > 0) {
        server_.getFunctionSteps(function.functionName, function.fileName, function.packageName, inactiveLines, new ServerRequestCallback<JsArray<FunctionSteps>>() {

            @Override
            public void onResponseReceived(JsArray<FunctionSteps> response) {
                // ask the server to set the breakpoint
                if (response.length() > 0) {
                    processFunctionSteps(inactiveBreakpoints, response);
                    setFunctionBreakpoints(function);
                } else // no results: discard the breakpoints
                {
                    discardUnsettableBreakpoints(inactiveBreakpoints);
                }
            }

            @Override
            public void onError(ServerError error) {
                discardUnsettableBreakpoints(inactiveBreakpoints);
            }
        });
    } else {
        setFunctionBreakpoints(function);
    }
}
Also used : Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint) FunctionSteps(org.rstudio.studio.client.common.debugging.model.FunctionSteps) JsArray(com.google.gwt.core.client.JsArray) ServerError(org.rstudio.studio.client.server.ServerError) ArrayList(java.util.ArrayList) Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint)

Example 63 with ServerError

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

the class BreakpointManager method setBreakpoint.

public Breakpoint setBreakpoint(final String path, final String functionName, int lineNumber, final boolean immediately) {
    // create the new breakpoint and arguments for the server call
    final Breakpoint breakpoint = addBreakpoint(Breakpoint.create(currentBreakpointId_++, path, functionName, lineNumber, immediately ? Breakpoint.STATE_PROCESSING : Breakpoint.STATE_INACTIVE, Breakpoint.TYPE_FUNCTION));
    notifyServer(breakpoint, true, false);
    // expectations. Process it when the function is no longer executing.
    if (activeFunctions_.contains(new FileFunction(breakpoint))) {
        breakpoint.setPendingDebugCompletion(true);
        markInactiveBreakpoint(breakpoint);
    } else {
        server_.getFunctionState(functionName, path, lineNumber, new ServerRequestCallback<FunctionState>() {

            @Override
            public void onResponseReceived(FunctionState state) {
                if (state.isPackageFunction()) {
                    breakpoint.markAsPackageBreakpoint(state.getPackageName());
                }
                // stop processing now
                if (!immediately)
                    return;
                // the breakpoint now
                if (state.getSyncState()) {
                    prepareAndSetFunctionBreakpoints(new FileFunction(breakpoint));
                } else // otherwise, save an inactive breakpoint--we'll revisit the
                // marker the next time the file is sourced or the package is
                // rebuilt
                {
                    markInactiveBreakpoint(breakpoint);
                }
            }

            @Override
            public void onError(ServerError error) {
                // if we can't figure out whether the function is in sync, 
                // leave it inactive for now
                markInactiveBreakpoint(breakpoint);
            }
        });
    }
    breakpointStateDirty_ = true;
    return breakpoint;
}
Also used : Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint) ServerError(org.rstudio.studio.client.server.ServerError) FunctionState(org.rstudio.studio.client.common.debugging.model.FunctionState)

Example 64 with ServerError

use of org.rstudio.studio.client.server.ServerError 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 65 with ServerError

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

ServerError (org.rstudio.studio.client.server.ServerError)109 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)26 JsArrayString (com.google.gwt.core.client.JsArrayString)22 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)20 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)18 Void (org.rstudio.studio.client.server.Void)16 ArrayList (java.util.ArrayList)13 JsArray (com.google.gwt.core.client.JsArray)12 Command (com.google.gwt.user.client.Command)11 GlobalProgressDelayer (org.rstudio.studio.client.common.GlobalProgressDelayer)10 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)9 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)9 Operation (org.rstudio.core.client.widget.Operation)8 Handler (org.rstudio.core.client.command.Handler)7 TextEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)7 JSONString (com.google.gwt.json.client.JSONString)6 EditingTarget (org.rstudio.studio.client.workbench.views.source.editors.EditingTarget)6 CodeBrowserEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)6 DataEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget)6 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)6