Search in sources :

Example 86 with ServerError

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

the class DataEditingTarget method updateData.

public void updateData(final DataItem data) {
    final Widget originalWidget = progressPanel_.getWidget();
    clearDisplay();
    final String oldCacheKey = getCacheKey();
    HashMap<String, String> props = new HashMap<String, String>();
    data.fillProperties(props);
    server_.modifyDocumentProperties(doc_.getId(), props, new SimpleRequestCallback<Void>("Error") {

        @Override
        public void onResponseReceived(Void response) {
            server_.removeCachedData(oldCacheKey, new ServerRequestCallback<Void>() {

                @Override
                public void onError(ServerError error) {
                    Debug.logError(error);
                }
            });
            data.fillProperties(doc_.getProperties());
            reloadDisplay();
        }

        @Override
        public void onError(ServerError error) {
            super.onError(error);
            progressPanel_.setWidget(originalWidget);
        }
    });
}
Also used : HashMap(java.util.HashMap) ServerError(org.rstudio.studio.client.server.ServerError) Widget(com.google.gwt.user.client.ui.Widget) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) Void(org.rstudio.studio.client.server.Void)

Example 87 with ServerError

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

the class ProfilerEditingTarget method onActivate.

public void onActivate() {
    activeProfilerEditingTarger_ = this;
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

        public void execute() {
            commands_.gotoProfileSource().setEnabled(hasValidPath_);
        }
    });
    final Operation activateOperation = new Operation() {

        @Override
        public void execute() {
            if (!htmlPathInitialized_) {
                htmlPathInitialized_ = true;
                htmlPath_ = getContents().getHtmlPath();
                htmlLocalPath_ = getContents().getHtmlLocalPath();
                isUserSaved_ = getContents().isUserSaved();
                if (htmlPath_ == null) {
                    presenter_.buildHtmlPath(new OperationWithInput<ProfileOperationResponse>() {

                        @Override
                        public void execute(ProfileOperationResponse response) {
                            htmlPath_ = response.getHtmlPath();
                            htmlLocalPath_ = response.getHtmlLocalPath();
                            persistDocumentProperty("htmlPath", htmlPath_);
                            persistDocumentProperty("htmlLocalPath", htmlLocalPath_);
                            view_.showProfilePage(htmlPath_);
                            pSourceWindowManager_.get().maximizeSourcePaneIfNecessary();
                        }
                    }, new Operation() {

                        @Override
                        public void execute() {
                            server_.clearProfile(getPath(), new ServerRequestCallback<JavaScriptObject>() {

                                @Override
                                public void onResponseReceived(JavaScriptObject response) {
                                    commands_.closeSourceDoc().execute();
                                }

                                @Override
                                public void onError(ServerError error) {
                                    Debug.logError(error);
                                    commands_.closeSourceDoc().execute();
                                }
                            });
                        }
                    }, getPath());
                } else {
                    view_.showProfilePage(htmlPath_);
                    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                        public void execute() {
                            pSourceWindowManager_.get().maximizeSourcePaneIfNecessary();
                        }
                    });
                }
            }
        }
    };
    if (getId() != null && !SourceWindowManager.isMainSourceWindow()) {
        sourceServer_.getSourceDocument(getId(), new ServerRequestCallback<SourceDocument>() {

            @Override
            public void onResponseReceived(SourceDocument document) {
                doc_ = document;
                activateOperation.execute();
            }

            @Override
            public void onError(ServerError error) {
                Debug.logError(error);
            }
        });
    } else {
        activateOperation.execute();
    }
    // This shouldn't happen though.
    if (commandHandlerReg_ != null) {
        Debug.log("Warning: onActivate called twice without intervening onDeactivate");
        commandHandlerReg_.removeHandler();
        commandHandlerReg_ = null;
    }
    commandHandlerReg_ = commandBinder.bind(commands_, this);
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ServerError(org.rstudio.studio.client.server.ServerError) SourceDocument(org.rstudio.studio.client.workbench.views.source.model.SourceDocument) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) ProfileOperationResponse(org.rstudio.studio.client.workbench.views.source.editors.profiler.model.ProfileOperationResponse) Operation(org.rstudio.core.client.widget.Operation)

Example 88 with ServerError

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

the class Source method openNotebook.

private void openNotebook(final FileSystemItem rmdFile, final SourceDocumentResult doc, final ResultCallback<EditingTarget, ServerError> resultCallback) {
    if (!StringUtil.isNullOrEmpty(doc.getDocPath())) {
        // this happens if we created the R Markdown file, or if the R Markdown
        // file on disk matched the one inside the notebook
        openFileFromServer(rmdFile, FileTypeRegistry.RMARKDOWN, resultCallback);
    } else if (!StringUtil.isNullOrEmpty(doc.getDocId())) {
        // this happens when we have to open an untitled buffer for the the
        // notebook (usually because the of a conflict between the Rmd on disk
        // and the one in the .nb.html file)
        server_.getSourceDocument(doc.getDocId(), new ServerRequestCallback<SourceDocument>() {

            @Override
            public void onResponseReceived(SourceDocument doc) {
                // create the editor
                EditingTarget target = addTab(doc, OPEN_INTERACTIVE);
                // show a warning bar 
                if (target instanceof TextEditingTarget) {
                    ((TextEditingTarget) target).showWarningMessage("This notebook has the same name as an R Markdown " + "file, but doesn't match it.");
                }
                resultCallback.onSuccess(target);
            }

            @Override
            public void onError(ServerError error) {
                globalDisplay_.showErrorMessage("Notebook Open Failed", "This notebook could not be opened. " + "If the error persists, try removing the " + "accompanying R Markdown file. \n\n" + error.getMessage());
                resultCallback.onFailure(error);
            }
        });
    }
}
Also used : 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) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback)

Example 89 with ServerError

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

the class Source method onShowProfiler.

public void onShowProfiler(OpenProfileEvent event) {
    String profilePath = event.getFilePath();
    String htmlPath = event.getHtmlPath();
    String htmlLocalPath = event.getHtmlLocalPath();
    // first try to activate existing
    for (int idx = 0; idx < editors_.size(); idx++) {
        String path = editors_.get(idx).getPath();
        if (path != null && profilePath.equals(path)) {
            ensureVisible(false);
            view_.selectTab(idx);
            return;
        }
    }
    // create new profiler 
    ensureVisible(true);
    if (event.getDocId() != null) {
        server_.getSourceDocument(event.getDocId(), new ServerRequestCallback<SourceDocument>() {

            @Override
            public void onResponseReceived(SourceDocument response) {
                addTab(response, OPEN_INTERACTIVE);
            }

            @Override
            public void onError(ServerError error) {
                Debug.logError(error);
                globalDisplay_.showErrorMessage("Source Document Error", error.getUserMessage());
            }
        });
    } else {
        server_.newDocument(FileTypeRegistry.PROFILER.getTypeId(), null, (JsObject) ProfilerContents.create(profilePath, htmlPath, htmlLocalPath, event.getCreateProfile()).cast(), new SimpleRequestCallback<SourceDocument>("Show Profiler") {

            @Override
            public void onResponseReceived(SourceDocument response) {
                addTab(response, OPEN_INTERACTIVE);
            }

            @Override
            public void onError(ServerError error) {
                Debug.logError(error);
                globalDisplay_.showErrorMessage("Source Document Error", error.getUserMessage());
            }
        });
    }
}
Also used : ServerError(org.rstudio.studio.client.server.ServerError) SourceDocument(org.rstudio.studio.client.workbench.views.source.model.SourceDocument) JSONString(com.google.gwt.json.client.JSONString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 90 with ServerError

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

the class SourceWindowManager method assignSourceDocWindowId.

private void assignSourceDocWindowId(String docId, String windowId, final Command onComplete) {
    // assign locally
    JsArray<SourceDocument> docs = getSourceDocs();
    for (int i = 0; i < docs.length(); i++) {
        SourceDocument doc = docs.get(i);
        if (doc.getId() == docId) {
            // it 
            if (doc.getSourceWindowId() == windowId)
                return;
            doc.assignSourceWindowId(windowId);
            break;
        }
    }
    // create the new property map
    HashMap<String, String> props = new HashMap<String, String>();
    props.put(SOURCE_WINDOW_ID, windowId);
    // update the doc window ID on the server
    server_.modifyDocumentProperties(docId, props, new ServerRequestCallback<Void>() {

        @Override
        public void onResponseReceived(Void v) {
            if (onComplete != null)
                onComplete.execute();
        }

        @Override
        public void onError(ServerError error) {
            display_.showErrorMessage("Can't Move Doc", "The document could not be " + "moved to a different window: \n" + error.getMessage());
        }
    });
}
Also used : HashMap(java.util.HashMap) ServerError(org.rstudio.studio.client.server.ServerError) SourceDocument(org.rstudio.studio.client.workbench.views.source.model.SourceDocument) JsArrayString(com.google.gwt.core.client.JsArrayString) Void(org.rstudio.studio.client.server.Void)

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