Search in sources :

Example 16 with ServerError

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

the class TextEditingTargetRMarkdownHelper method createDraftFromTemplate.

public void createDraftFromTemplate(final RmdChosenTemplate template) {
    final String target = template.getDirectory() + "/" + template.getFileName();
    final String targetFile = target + (template.createDir() ? "" : ".Rmd");
    fileServer_.stat(targetFile, new ServerRequestCallback<FileSystemItem>() {

        @Override
        public void onResponseReceived(final FileSystemItem fsi) {
            // the file doesn't exist--proceed
            if (!fsi.exists()) {
                createDraftFromTemplate(template, target);
                return;
            }
            // the file exists--offer to clean it up and continue.
            globalDisplay_.showYesNoMessage(GlobalDisplay.MSG_QUESTION, "Overwrite " + (template.createDir() ? "Directory" : "File"), targetFile + " exists. Overwrite it?", false, new Operation() {

                @Override
                public void execute() {
                    cleanAndCreateTemplate(template, target, fsi);
                }
            }, null, null, "Overwrite", "Cancel", false);
        }

        @Override
        public void onError(ServerError error) {
            // presumably the file doesn't exist, which is what we want.
            createDraftFromTemplate(template, target);
        }
    });
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ServerError(org.rstudio.studio.client.server.ServerError) JsArrayString(com.google.gwt.core.client.JsArrayString) Operation(org.rstudio.core.client.widget.Operation)

Example 17 with ServerError

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

the class TextEditingTargetRMarkdownHelper method replaceOutputFormatOptions.

public void replaceOutputFormatOptions(final String yaml, final String format, final RmdFrontMatterOutputOptions options, final OperationWithInput<String> onCompleted) {
    server_.convertToYAML(options, new ServerRequestCallback<RmdYamlResult>() {

        @Override
        public void onResponseReceived(RmdYamlResult result) {
            boolean isDefault = options.getOptionList().length() == 0;
            YamlTree yamlTree = new YamlTree(yaml);
            YamlTree optionTree = new YamlTree(result.getYaml());
            // add the output key if needed
            if (!yamlTree.containsKey(RmdFrontMatter.OUTPUT_KEY)) {
                yamlTree.addYamlValue(null, RmdFrontMatter.OUTPUT_KEY, RmdOutputFormat.OUTPUT_HTML_DOCUMENT);
            }
            String treeFormat = yamlTree.getKeyValue(RmdFrontMatter.OUTPUT_KEY);
            if (treeFormat.equals(format)) {
                if (isDefault) {
                // 1-a: if all options are still at their defaults, leave
                // untouched
                } else {
                    // 1-b: not all options are at defaults; replace the simple
                    // format with an option list
                    yamlTree.setKeyValue(RmdFrontMatter.OUTPUT_KEY, "");
                    yamlTree.addYamlValue(RmdFrontMatter.OUTPUT_KEY, format, "");
                    yamlTree.setKeyValue(format, optionTree);
                }
            } else if (treeFormat.length() > 0) {
                // changing it
                if (isDefault) {
                    // case 2-a: change one simple format to another 
                    yamlTree.setKeyValue(RmdFrontMatter.OUTPUT_KEY, format);
                } else {
                    // case 2-b: change a simple format to a complex one
                    yamlTree.setKeyValue(RmdFrontMatter.OUTPUT_KEY, "");
                    yamlTree.addYamlValue(RmdFrontMatter.OUTPUT_KEY, format, "");
                    yamlTree.setKeyValue(format, optionTree);
                }
            } else {
                // case 3: the output format is already not simple
                treeFormat = yamlTree.getKeyValue(format);
                if (treeFormat.equals(RmdFrontMatter.DEFAULT_FORMAT)) {
                    if (isDefault) {
                    // case 3-a: still at default settings
                    } else {
                        // case 3-b: default to complex
                        yamlTree.setKeyValue(format, optionTree);
                    }
                } else {
                    if (isDefault) {
                        // case 3-c: complex to default
                        if (yamlTree.getChildKeys(RmdFrontMatter.OUTPUT_KEY).size() == 1) {
                            // case 3-c-i: only one format, and has default settings
                            yamlTree.clearChildren(RmdFrontMatter.OUTPUT_KEY);
                            yamlTree.setKeyValue(RmdFrontMatter.OUTPUT_KEY, format);
                        } else {
                            // case 3-c-i: multiple formats, this one's becoming
                            // the default
                            yamlTree.clearChildren(format);
                            yamlTree.setKeyValue(format, RmdFrontMatter.DEFAULT_FORMAT);
                        }
                    } else {
                        // case 3-d: complex to complex
                        if (!yamlTree.containsKey(format)) {
                            yamlTree.addYamlValue(RmdFrontMatter.OUTPUT_KEY, format, "");
                        }
                        yamlTree.setKeyValue(format, optionTree);
                    }
                }
            }
            yamlTree.reorder(Arrays.asList(format));
            onCompleted.execute(yamlTree.toString());
        }

        @Override
        public void onError(ServerError error) {
            // if we fail, return the unmodified YAML
            onCompleted.execute(yaml);
        }
    });
}
Also used : RmdYamlResult(org.rstudio.studio.client.rmarkdown.model.RmdYamlResult) ServerError(org.rstudio.studio.client.server.ServerError) YamlTree(org.rstudio.studio.client.rmarkdown.model.YamlTree) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 18 with ServerError

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

the class TextEditingTargetCompilePdfHelper method checkCompilers.

public void checkCompilers(final WarningBarDisplay display, TextFileType fileType) {
    // for all tex files we need to parse magic comments and validate
    // any explict latex proram directive
    ArrayList<TexMagicComment> magicComments = null;
    if (fileType.canCompilePDF()) {
        magicComments = TexMagicComment.parseComments(docDisplay_.getCode());
        String latexProgramDirective = detectLatexProgramDirective(magicComments);
        if (latexProgramDirective != null) {
            if (latexProgramRegistry_.findTypeIgnoreCase(latexProgramDirective) == null) {
                // show warning and bail 
                display.showWarningBar("Unknown LaTeX program type '" + latexProgramDirective + "' specified (valid types are " + latexProgramRegistry_.getPrintableTypeNames() + ")");
                return;
            }
        }
    }
    // for Rnw we first determine the RnwWeave type
    RnwWeave rnwWeave = null;
    RnwWeaveDirective rnwWeaveDirective = null;
    if (fileType.isRnw()) {
        rnwWeaveDirective = detectRnwWeaveDirective(magicComments);
        if (rnwWeaveDirective != null) {
            rnwWeave = rnwWeaveDirective.getRnwWeave();
            if (rnwWeave == null) {
                // show warning and bail 
                display.showWarningBar("Unknown Rnw weave method '" + rnwWeaveDirective.getName() + "' specified (valid types are " + rnwWeaveRegistry_.getPrintableTypeNames() + ")");
                return;
            }
        } else {
            rnwWeave = rnwWeaveRegistry_.findTypeIgnoreCase(prefs_.defaultSweaveEngine().getValue());
        }
    }
    final SessionInfo sessionInfo = session_.getSessionInfo();
    TexCapabilities texCap = sessionInfo.getTexCapabilities();
    final boolean checkForTeX = fileType.canCompilePDF() && !texCap.isTexInstalled();
    final boolean checkForRnwWeave = (rnwWeave != null) && !texCap.isRnwWeaveAvailable(rnwWeave);
    if (checkForTeX || checkForRnwWeave) {
        // alias variables to finals
        final boolean hasRnwWeaveDirective = rnwWeaveDirective != null;
        final RnwWeave fRnwWeave = rnwWeave;
        server_.getTexCapabilities(new ServerRequestCallback<TexCapabilities>() {

            @Override
            public void onResponseReceived(TexCapabilities response) {
                if (checkForTeX && !response.isTexInstalled()) {
                    String warning;
                    if (Desktop.isDesktop())
                        warning = "No TeX installation detected. Please install " + "TeX before compiling.";
                    else
                        warning = "This server does not have TeX installed. You " + "may not be able to compile.";
                    display.showWarningBar(warning);
                } else if (checkForRnwWeave && !response.isRnwWeaveAvailable(fRnwWeave)) {
                    String forContext = "";
                    if (hasRnwWeaveDirective)
                        forContext = "this file";
                    else if (sessionInfo.getActiveProjectFile() != null)
                        forContext = "Rnw files for this project";
                    else
                        forContext = "Rnw files";
                    display.showWarningBar(fRnwWeave.getName() + " is configured to weave " + forContext + " " + "however the " + fRnwWeave.getPackageName() + " package is not installed.");
                } else {
                    display.hideWarningBar();
                }
            }

            @Override
            public void onError(ServerError error) {
                Debug.logError(error);
            }
        });
    } else {
        display.hideWarningBar();
    }
}
Also used : RnwWeave(org.rstudio.studio.client.common.rnw.RnwWeave) RnwWeaveDirective(org.rstudio.studio.client.common.rnw.RnwWeaveDirective) ServerError(org.rstudio.studio.client.server.ServerError) TexCapabilities(org.rstudio.studio.client.workbench.model.TexCapabilities) TexMagicComment(org.rstudio.core.client.tex.TexMagicComment) SessionInfo(org.rstudio.studio.client.workbench.model.SessionInfo)

Example 19 with ServerError

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

the class SVNReviewPresenter method updateDiff.

private void updateDiff() {
    view_.hideSizeWarning();
    final ArrayList<StatusAndPath> paths = view_.getChangelistTable().getSelectedItems();
    if (paths.size() != 1) {
        clearDiff();
        return;
    }
    final StatusAndPath item = paths.get(0);
    if (!item.getPath().equals(currentFilename_)) {
        clearDiff();
        currentFilename_ = item.getPath();
    }
    // bail if this is an undiffable status
    if (undiffableStatuses_.contains(item.getStatus()))
        return;
    diffInvalidation_.invalidate();
    final Token token = diffInvalidation_.getInvalidationToken();
    server_.svnDiffFile(item.getPath(), view_.getContextLines().getValue(), overrideSizeWarning_, new SimpleRequestCallback<DiffResult>("Diff Error") {

        @Override
        public void onResponseReceived(DiffResult diffResult) {
            if (token.isInvalid())
                return;
            String response = diffResult.getDecodedValue();
            // Use lastResponse_ to prevent unnecessary flicker
            if (response.equals(currentResponse_))
                return;
            currentResponse_ = response;
            currentEncoding_ = diffResult.getSourceEncoding();
            SVNDiffParser parser = new SVNDiffParser(response);
            parser.nextFilePair();
            ArrayList<ChunkOrLine> allLines = new ArrayList<ChunkOrLine>();
            activeChunks_.clear();
            for (DiffChunk chunk; null != (chunk = parser.nextChunk()); ) {
                if (!chunk.shouldIgnore()) {
                    activeChunks_.add(chunk);
                    allLines.add(new ChunkOrLine(chunk));
                }
                for (Line line : chunk.getLines()) allLines.add(new ChunkOrLine(line));
            }
            view_.getLineTableDisplay().setShowActions(!"?".equals(item.getStatus()));
            view_.setData(allLines);
        }

        @Override
        public void onError(ServerError error) {
            JSONNumber size = error.getClientInfo().isNumber();
            if (size != null)
                view_.showSizeWarning((long) size.doubleValue());
            else
                super.onError(error);
        }
    });
}
Also used : SVNDiffParser(org.rstudio.studio.client.workbench.views.vcs.svn.SVNDiffParser) StatusAndPath(org.rstudio.studio.client.common.vcs.StatusAndPath) ServerError(org.rstudio.studio.client.server.ServerError) ArrayList(java.util.ArrayList) Token(org.rstudio.core.client.Invalidation.Token) JSONNumber(com.google.gwt.json.client.JSONNumber) DiffResult(org.rstudio.studio.client.common.vcs.DiffResult)

Example 20 with ServerError

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

the class SetupChunkOptionsPopupPanel method initOptions.

@Override
protected void initOptions(final Command afterInit) {
    String chunkText = getChunkText();
    server_.extractChunkOptions(chunkText, new ServerRequestCallback<JsObject>() {

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

        @Override
        public void onResponseReceived(JsObject object) {
            JsArrayString keys = object.keys();
            for (String key : JsUtil.asIterable(keys)) chunkOptions_.put(key, object.getAsString(key));
            afterInit.execute();
        }
    });
}
Also used : JsObject(org.rstudio.core.client.js.JsObject) ServerError(org.rstudio.studio.client.server.ServerError) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString)

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