Search in sources :

Example 16 with Void

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

the class DataImport method previewDataImport.

private void previewDataImport() {
    Operation previewDataImportOperation = new Operation() {

        @Override
        public void execute() {
            DataImportOptions previewImportOptions = getOptions();
            if (dataImportFileChooser_.getText() == "") {
                gridViewer_.setData(null);
                return;
            }
            previewImportOptions.setMaxRows(maxRows_);
            progressIndicator_.onProgress("Retrieving preview data...", new Operation() {

                @Override
                public void execute() {
                    progressIndicator_.clearProgress();
                    cleanPreviewResources();
                    server_.previewDataImportAsyncAbort(new ServerRequestCallback<Void>() {

                        @Override
                        public void onResponseReceived(Void empty) {
                        }

                        @Override
                        public void onError(ServerError error) {
                            Debug.logError(error);
                            progressIndicator_.onError(error.getMessage());
                        }
                    });
                }
            });
            server_.previewDataImportAsync(previewImportOptions, maxCols_, maxFactors_, new ServerRequestCallback<DataImportPreviewResponse>() {

                @Override
                public void onResponseReceived(DataImportPreviewResponse response) {
                    if (response == null || response.getErrorMessage() != null) {
                        if (response != null) {
                            setGridViewerData(response);
                            response.setColumnDefinitions(lastSuccessfulResponse_);
                            progressIndicator_.onError(enhancePreviewErrorMessage(response.getErrorMessage()));
                        }
                        return;
                    }
                    // Set the column definitions to allow subsequent calls to assemble
                    // generate preview code based on data.
                    importOptions_.setBaseColumnDefinitions(response);
                    lastSuccessfulResponse_ = response;
                    dataImportOptionsUi_.setPreviewResponse(response);
                    if (response.getLocalFiles() != null) {
                        localFiles_ = response.getLocalFiles();
                    }
                    gridViewer_.setOption("status", "Previewing first " + toLocaleString(maxRows_) + " entries. " + (response.getParsingErrors() > 0 ? Integer.toString(response.getParsingErrors()) + " parsing errors." : ""));
                    assignColumnDefinitions(response, importOptions_.getColumnDefinitions());
                    setGridViewerData(response);
                    progressIndicator_.onCompleted();
                }

                @Override
                public void onError(ServerError error) {
                    Debug.logError(error);
                    cleanPreviewResources();
                    gridViewer_.setData(null);
                    progressIndicator_.onError(error.getMessage());
                }
            });
        }
    };
    assembleDataImport(previewDataImportOperation);
}
Also used : ServerError(org.rstudio.studio.client.server.ServerError) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) Operation(org.rstudio.core.client.widget.Operation) DataImportPreviewResponse(org.rstudio.studio.client.workbench.views.environment.dataimport.model.DataImportPreviewResponse) Void(org.rstudio.studio.client.server.Void)

Example 17 with Void

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

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

Example 19 with Void

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

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

the class TextEditingTarget method sourceActiveDocument.

private void sourceActiveDocument(final boolean echo) {
    docDisplay_.focus();
    // If the document being sourced is a Shiny file, run the app instead.
    if (fileType_.isR() && extendedType_.startsWith(SourceDocument.XT_SHINY_PREFIX)) {
        runShinyApp();
        return;
    }
    // if the document is an R Markdown notebook, run all its chunks instead
    if (fileType_.isRmd() && isRmdNotebook()) {
        onExecuteAllCode();
        return;
    }
    // If the document being sourced is a script then use that codepath
    if (fileType_.isScript()) {
        runScript();
        return;
    }
    // If the document is previewable
    if (fileType_.canPreviewFromR()) {
        previewFromR();
        return;
    }
    String code = docDisplay_.getCode();
    if (code != null && code.trim().length() > 0) {
        // R 2.14 prints a warning when sourcing a file with no trailing \n
        if (!code.endsWith("\n"))
            code = code + "\n";
        boolean sweave = fileType_.canCompilePDF() || fileType_.canKnitToHTML() || fileType_.isRpres();
        RnwWeave rnwWeave = compilePdfHelper_.getActiveRnwWeave();
        final boolean forceEcho = sweave && (rnwWeave != null) ? rnwWeave.forceEchoOnExec() : false;
        // NOTE: we always set echo to true for knitr because knitr doesn't
        // require print statements so if you don't echo to the console
        // then you don't see any of the output
        boolean saveWhenSourcing = fileType_.isCpp() || docDisplay_.hasBreakpoints() || (prefs_.saveBeforeSourcing().getValue() && (getPath() != null) && !sweave);
        if ((dirtyState_.getValue() || sweave) && !saveWhenSourcing) {
            server_.saveActiveDocument(code, sweave, compilePdfHelper_.getActiveRnwWeaveName(), new SimpleRequestCallback<Void>() {

                @Override
                public void onResponseReceived(Void response) {
                    consoleDispatcher_.executeSourceCommand("~/.active-rstudio-document", fileType_, "UTF-8", activeCodeIsAscii(), forceEcho ? true : echo, prefs_.focusConsoleAfterExec().getValue(), docDisplay_.hasBreakpoints());
                }
            });
        } else {
            Command sourceCommand = new Command() {

                @Override
                public void execute() {
                    if (docDisplay_.hasBreakpoints()) {
                        hideBreakpointWarningBar();
                    }
                    consoleDispatcher_.executeSourceCommand(getPath(), fileType_, docUpdateSentinel_.getEncoding(), activeCodeIsAscii(), forceEcho ? true : echo, prefs_.focusConsoleAfterExec().getValue(), docDisplay_.hasBreakpoints());
                }
            };
            if (saveWhenSourcing && (dirtyState_.getValue() || (getPath() == null)))
                saveThenExecute(null, sourceCommand);
            else
                sourceCommand.execute();
        }
    }
    // update pref if necessary
    if (prefs_.sourceWithEcho().getValue() != echo) {
        prefs_.sourceWithEcho().setGlobalValue(echo, true);
        prefs_.writeUIPrefs();
    }
}
Also used : RnwWeave(org.rstudio.studio.client.common.rnw.RnwWeave) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) JsArrayString(com.google.gwt.core.client.JsArrayString) Void(org.rstudio.studio.client.server.Void)

Aggregations

Void (org.rstudio.studio.client.server.Void)22 ServerError (org.rstudio.studio.client.server.ServerError)16 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)5 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)5 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)4 JsArrayString (com.google.gwt.core.client.JsArrayString)3 Command (com.google.gwt.user.client.Command)3 HashMap (java.util.HashMap)3 Operation (org.rstudio.core.client.widget.Operation)3 Breakpoint (org.rstudio.studio.client.common.debugging.model.Breakpoint)3 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)2 Timer (com.google.gwt.user.client.Timer)2 Handler (org.rstudio.core.client.command.Handler)2 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)2 Style (com.google.gwt.dom.client.Style)1 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)1 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)1