Search in sources :

Example 16 with ServerRequestCallback

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

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

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

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

the class Presentation method onClearPresentationCache.

@Handler
void onClearPresentationCache() {
    globalDisplay_.showYesNoMessage(MessageDialog.INFO, "Clear Knitr Cache", "Clearing the Knitr cache will discard previously cached " + "output and re-run all of the R code chunks within the " + "presentation.\n\n" + "Are you sure you want to clear the cache now?", false, new ProgressOperation() {

        @Override
        public void execute(final ProgressIndicator indicator) {
            indicator.onProgress("Clearing Knitr Cache...");
            server_.clearPresentationCache(new ServerRequestCallback<Void>() {

                @Override
                public void onResponseReceived(Void response) {
                    indicator.onCompleted();
                    refreshPresentation();
                }

                @Override
                public void onError(ServerError error) {
                    indicator.onCompleted();
                    globalDisplay_.showErrorMessage("Error Clearing Cache", getErrorMessage(error));
                }
            });
        }
    }, new ProgressOperation() {

        @Override
        public void execute(ProgressIndicator indicator) {
            indicator.onCompleted();
        }
    }, true);
}
Also used : ProgressOperation(org.rstudio.core.client.widget.ProgressOperation) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ServerError(org.rstudio.studio.client.server.ServerError) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) Void(org.rstudio.studio.client.server.Void) Handler(org.rstudio.core.client.command.Handler)

Example 20 with ServerRequestCallback

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

the class ViewerPane method createMainToolbar.

@Override
protected Toolbar createMainToolbar() {
    toolbar_ = new Toolbar();
    // add html widget buttons
    toolbar_.addLeftWidget(commands_.viewerBack().createToolbarButton());
    toolbar_.addLeftWidget(commands_.viewerForward().createToolbarButton());
    toolbar_.addLeftSeparator();
    toolbar_.addLeftWidget(commands_.viewerZoom().createToolbarButton());
    // export commands
    exportButtonSeparator_ = toolbar_.addLeftSeparator();
    ToolbarPopupMenu exportMenu = new ToolbarPopupMenu();
    exportMenu.addItem(commands_.viewerSaveAsImage().createMenuItem(false));
    exportMenu.addItem(commands_.viewerCopyToClipboard().createMenuItem(false));
    exportMenu.addSeparator();
    exportMenu.addItem(commands_.viewerSaveAsWebPage().createMenuItem(false));
    exportButton_ = new ToolbarButton("Export", new ImageResource2x(StandardIcons.INSTANCE.export_menu2x()), exportMenu);
    toolbar_.addLeftWidget(exportButton_);
    exportButton_.setVisible(false);
    exportButtonSeparator_.setVisible(false);
    toolbar_.addLeftSeparator();
    toolbar_.addLeftWidget(commands_.viewerClear().createToolbarButton());
    toolbar_.addLeftSeparator();
    toolbar_.addLeftWidget(commands_.viewerClearAll().createToolbarButton());
    toolbar_.addLeftSeparator();
    toolbar_.addLeftWidget(commands_.viewerPopout().createToolbarButton());
    toolbar_.addLeftSeparator();
    toolbar_.addLeftWidget(commands_.viewerStop().createToolbarButton());
    // add publish button 
    publishButton_ = new RSConnectPublishButton(RSConnect.CONTENT_TYPE_DOCUMENT, true, null);
    toolbar_.addRightWidget(publishButton_);
    toolbar_.addRightSeparator();
    toolbar_.addRightWidget(commands_.viewerRefresh().createToolbarButton());
    // create an HTML generator 
    publishButton_.setPublishHtmlSource(new PublishHtmlSource() {

        @Override
        public void generatePublishHtml(final CommandWithArg<String> onCompleted) {
            server_.viewerCreateRPubsHtml(getTitle(), "", new ServerRequestCallback<String>() {

                @Override
                public void onResponseReceived(String htmlFile) {
                    onCompleted.execute(htmlFile);
                }

                @Override
                public void onError(ServerError error) {
                    globalDisplay_.showErrorMessage("Could Not Publish", error.getMessage());
                }
            });
        }

        @Override
        public String getTitle() {
            String title = frame_.getTitle();
            if (StringUtil.isNullOrEmpty(title))
                title = "Viewer Content";
            return title;
        }
    });
    return toolbar_;
}
Also used : ToolbarButton(org.rstudio.core.client.widget.ToolbarButton) ToolbarPopupMenu(org.rstudio.core.client.widget.ToolbarPopupMenu) RSConnectPublishButton(org.rstudio.studio.client.rsconnect.ui.RSConnectPublishButton) PublishHtmlSource(org.rstudio.studio.client.rsconnect.model.PublishHtmlSource) ServerError(org.rstudio.studio.client.server.ServerError) ImageResource2x(org.rstudio.core.client.resources.ImageResource2x) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) Toolbar(org.rstudio.core.client.widget.Toolbar)

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