Search in sources :

Example 91 with ServerError

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

the class Source method onInsertSource.

public void onInsertSource(final InsertSourceEvent event) {
    if (activeEditor_ != null && activeEditor_ instanceof TextEditingTarget && commands_.executeCode().isEnabled()) {
        TextEditingTarget textEditor = (TextEditingTarget) activeEditor_;
        textEditor.insertCode(event.getCode(), event.isBlock());
    } else {
        newDoc(FileTypeRegistry.R, new ResultCallback<EditingTarget, ServerError>() {

            public void onSuccess(EditingTarget arg) {
                ((TextEditingTarget) arg).insertCode(event.getCode(), event.isBlock());
            }
        });
    }
}
Also used : ServerError(org.rstudio.studio.client.server.ServerError) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) EditingTarget(org.rstudio.studio.client.workbench.views.source.editors.EditingTarget) DataEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget) CodeBrowserEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)

Example 92 with ServerError

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

the class Source method openFileFromServer.

private void openFileFromServer(final FileSystemItem file, final TextFileType fileType, final ResultCallback<EditingTarget, ServerError> resultCallback) {
    final Command dismissProgress = globalDisplay_.showProgress("Opening file...");
    server_.openDocument(file.getPath(), fileType.getTypeId(), uiPrefs_.defaultEncoding().getValue(), new ServerRequestCallback<SourceDocument>() {

        @Override
        public void onError(ServerError error) {
            dismissProgress.execute();
            pMruList_.get().remove(file.getPath());
            Debug.logError(error);
            if (resultCallback != null)
                resultCallback.onFailure(error);
        }

        @Override
        public void onResponseReceived(SourceDocument document) {
            dismissProgress.execute();
            pMruList_.get().add(document.getPath());
            EditingTarget target = addTab(document, OPEN_INTERACTIVE);
            if (resultCallback != null)
                resultCallback.onSuccess(target);
        }
    });
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) ServerError(org.rstudio.studio.client.server.ServerError) SourceDocument(org.rstudio.studio.client.workbench.views.source.model.SourceDocument) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) EditingTarget(org.rstudio.studio.client.workbench.views.source.editors.EditingTarget) DataEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget) CodeBrowserEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)

Example 93 with ServerError

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

the class Source method onNewSweaveDoc.

@Handler
public void onNewSweaveDoc() {
    // set concordance value if we need to
    String concordance = new String();
    if (uiPrefs_.alwaysEnableRnwConcordance().getValue()) {
        RnwWeave activeWeave = rnwWeaveRegistry_.findTypeIgnoreCase(uiPrefs_.defaultSweaveEngine().getValue());
        if (activeWeave.getInjectConcordance())
            concordance = "\\SweaveOpts{concordance=TRUE}\n";
    }
    final String concordanceValue = concordance;
    // show progress
    final ProgressIndicator indicator = new GlobalProgressDelayer(globalDisplay_, 500, "Creating new document...").getIndicator();
    // get the template
    server_.getSourceTemplate("", "sweave.Rnw", new ServerRequestCallback<String>() {

        @Override
        public void onResponseReceived(String templateContents) {
            indicator.onCompleted();
            // add in concordance if necessary
            final boolean hasConcordance = concordanceValue.length() > 0;
            if (hasConcordance) {
                String beginDoc = "\\begin{document}\n";
                templateContents = templateContents.replace(beginDoc, beginDoc + concordanceValue);
            }
            newDoc(FileTypeRegistry.SWEAVE, templateContents, new ResultCallback<EditingTarget, ServerError>() {

                @Override
                public void onSuccess(EditingTarget target) {
                    int startRow = 4 + (hasConcordance ? 1 : 0);
                    target.setCursorPosition(Position.create(startRow, 0));
                }
            });
        }

        @Override
        public void onError(ServerError error) {
            indicator.onError(error.getUserMessage());
        }
    });
}
Also used : RnwWeave(org.rstudio.studio.client.common.rnw.RnwWeave) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ServerError(org.rstudio.studio.client.server.ServerError) GlobalProgressDelayer(org.rstudio.studio.client.common.GlobalProgressDelayer) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) EditingTarget(org.rstudio.studio.client.workbench.views.source.editors.EditingTarget) DataEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget) CodeBrowserEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget) JSONString(com.google.gwt.json.client.JSONString) JsArrayString(com.google.gwt.core.client.JsArrayString) NativePreviewHandler(com.google.gwt.user.client.Event.NativePreviewHandler) FileTypeChangedHandler(org.rstudio.studio.client.workbench.views.source.editors.text.events.FileTypeChangedHandler) Handler(org.rstudio.core.client.command.Handler) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) SelectionHandler(com.google.gwt.event.logical.shared.SelectionHandler) CloseHandler(com.google.gwt.event.logical.shared.CloseHandler) ViewDataHandler(org.rstudio.studio.client.workbench.views.data.events.ViewDataHandler) SourceOnSaveChangedHandler(org.rstudio.studio.client.workbench.views.source.editors.text.events.SourceOnSaveChangedHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) OpenSourceFileHandler(org.rstudio.studio.client.common.filetypes.events.OpenSourceFileHandler)

Example 94 with ServerError

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

the class Source method newSourceDocWithTemplate.

private void newSourceDocWithTemplate(final TextFileType fileType, String name, String template, final Position cursorPosition, final CommandWithArg<EditingTarget> onSuccess, final TransformerCommand<String> contentTransformer) {
    final ProgressIndicator indicator = new GlobalProgressDelayer(globalDisplay_, 500, "Creating new document...").getIndicator();
    server_.getSourceTemplate(name, template, new ServerRequestCallback<String>() {

        @Override
        public void onResponseReceived(String templateContents) {
            indicator.onCompleted();
            if (contentTransformer != null)
                templateContents = contentTransformer.transform(templateContents);
            newDoc(fileType, templateContents, new ResultCallback<EditingTarget, ServerError>() {

                @Override
                public void onSuccess(EditingTarget target) {
                    if (cursorPosition != null)
                        target.setCursorPosition(cursorPosition);
                    if (onSuccess != null)
                        onSuccess.execute(target);
                }
            });
        }

        @Override
        public void onError(ServerError error) {
            indicator.onError(error.getUserMessage());
        }
    });
}
Also used : ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ServerError(org.rstudio.studio.client.server.ServerError) GlobalProgressDelayer(org.rstudio.studio.client.common.GlobalProgressDelayer) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) EditingTarget(org.rstudio.studio.client.workbench.views.source.editors.EditingTarget) DataEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget) CodeBrowserEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget) JSONString(com.google.gwt.json.client.JSONString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 95 with ServerError

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

the class Source method onNewDocumentWithCode.

public void onNewDocumentWithCode(final NewDocumentWithCodeEvent event) {
    // determine the type
    final EditableFileType docType;
    if (event.getType().equals(NewDocumentWithCodeEvent.R_SCRIPT))
        docType = FileTypeRegistry.R;
    else
        docType = FileTypeRegistry.RMARKDOWN;
    // command to create and run the new doc
    Command newDocCommand = new Command() {

        @Override
        public void execute() {
            newDoc(docType, new ResultCallback<EditingTarget, ServerError>() {

                public void onSuccess(EditingTarget arg) {
                    TextEditingTarget editingTarget = (TextEditingTarget) arg;
                    editingTarget.insertCode(event.getCode(), false);
                    if (event.getCursorPosition() != null) {
                        editingTarget.navigateToPosition(event.getCursorPosition(), false);
                    }
                    if (event.getExecute()) {
                        if (docType.equals(FileTypeRegistry.R)) {
                            commands_.executeToCurrentLine().execute();
                            commands_.activateSource().execute();
                        } else {
                            commands_.executePreviousChunks().execute();
                        }
                    }
                }
            });
        }
    };
    // do it
    if (docType.equals(FileTypeRegistry.R)) {
        newDocCommand.execute();
    } else {
        dependencyManager_.withRMarkdown("R Notebook", "Create R Notebook", newDocCommand);
    }
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) ServerError(org.rstudio.studio.client.server.ServerError) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) EditingTarget(org.rstudio.studio.client.workbench.views.source.editors.EditingTarget) DataEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget) CodeBrowserEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) EditableFileType(org.rstudio.studio.client.common.filetypes.EditableFileType)

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