Search in sources :

Example 11 with ServerRequestCallback

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

the class Ignore method showDialog.

private void showDialog(final String initialPath, String ignores, final Strategy strategy) {
    final Display display = pDisplay_.get();
    final ProgressIndicator indicator = display.progressIndicator();
    display.setDialogCaption(strategy.getDialogCaption());
    display.setIgnoresCaption(strategy.getIgnoresCaption());
    display.setHelpLinkName(strategy.getHelpLinkName());
    display.setCurrentPath(initialPath);
    display.setIgnored(ignores);
    display.scrollToBottom();
    display.addPathChangedHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            display.setIgnored("");
            indicator.onProgress("Getting ignored files for path...");
            strategy.getIgnores(display.getCurrentPath(), new ServerRequestCallback<ProcessResult>() {

                @Override
                public void onResponseReceived(final ProcessResult result) {
                    indicator.clearProgress();
                    if (checkForProcessError(strategy.getDialogCaption(), result))
                        return;
                    display.setIgnored(result.getOutput());
                    display.focusIgnored();
                }

                @Override
                public void onError(ServerError error) {
                    indicator.onError(error.getUserMessage());
                }
            });
        }
    });
    display.saveButton().addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            indicator.onProgress("Setting ignored files for path...");
            strategy.setIgnores(display.getCurrentPath(), display.getIgnored(), new ServerRequestCallback<ProcessResult>() {

                @Override
                public void onResponseReceived(ProcessResult result) {
                    indicator.onCompleted();
                    checkForProcessError(strategy.getDialogCaption(), result);
                }

                @Override
                public void onError(ServerError error) {
                    indicator.onError(error.getUserMessage());
                }
            });
        }
    });
    display.showModal();
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ServerError(org.rstudio.studio.client.server.ServerError) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ProcessResult(org.rstudio.studio.client.common.vcs.ProcessResult) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) GlobalDisplay(org.rstudio.studio.client.common.GlobalDisplay)

Example 12 with ServerRequestCallback

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

the class NewRSConnectAuthPage method pollForAuthCompleted.

private void pollForAuthCompleted() {
    Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

        @Override
        public boolean execute() {
            // don't keep polling once auth is complete or window is closed
            if (!waitingForAuth_.getValue())
                return false;
            // returned for some reason, just wait for it to finish
            if (runningAuthCompleteCheck_)
                return true;
            runningAuthCompleteCheck_ = true;
            server_.getUserFromToken(result_.getServerInfo().getUrl(), result_.getPreAuthToken(), new ServerRequestCallback<RSConnectAuthUser>() {

                @Override
                public void onResponseReceived(RSConnectAuthUser user) {
                    runningAuthCompleteCheck_ = false;
                    // just wait and try again
                    if (!user.isValidUser())
                        return;
                    // user is valid--cache account info and close the
                    // window
                    result_.setAuthUser(user);
                    waitingForAuth_.setValue(false, true);
                    if (Desktop.isDesktop()) {
                        // on the desktop, we can close the window by name
                        Desktop.getFrame().closeNamedWindow(AUTH_WINDOW_NAME);
                    }
                    onUserAuthVerified();
                }

                @Override
                public void onError(ServerError error) {
                    // ignore this error
                    runningAuthCompleteCheck_ = false;
                }
            });
            return true;
        }
    }, 1000);
}
Also used : RSConnectAuthUser(org.rstudio.studio.client.rsconnect.model.RSConnectAuthUser) ServerError(org.rstudio.studio.client.server.ServerError) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback)

Example 13 with ServerRequestCallback

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

the class RSConnectDeploy method setPreviousInfo.

private void setPreviousInfo() {
    // content as currently deployed
    if (fromPrevious_ != null) {
        appProgressName_.setText(fromPrevious_.getName());
        appExistingName_.setText(fromPrevious_.getDisplayName());
        appProgressPanel_.setVisible(true);
        appInfoPanel_.setVisible(true);
        final ServerRequestCallback<JsArray<RSConnectApplicationInfo>> onAppsReceived = new ServerRequestCallback<JsArray<RSConnectApplicationInfo>>() {

            @Override
            public void onResponseReceived(JsArray<RSConnectApplicationInfo> infos) {
                // hide server progress
                appProgressPanel_.setVisible(false);
                // find an app with the same account, server, and name;
                // when found, populate the UI with app details
                boolean found = false;
                if (infos != null) {
                    for (int i = 0; i < infos.length(); i++) {
                        RSConnectApplicationInfo info = infos.get(i);
                        if (info.getName() == fromPrevious_.getName()) {
                            showAppInfo(info);
                            found = true;
                            break;
                        }
                    }
                }
                if (!found) {
                    forgetPreviousDeployment();
                }
            }

            @Override
            public void onError(ServerError error) {
                // it's okay if we fail here, since the application info
                // display is purely informative
                appProgressPanel_.setVisible(false);
                showAppInfo(null);
            }
        };
        if (!StringUtil.isNullOrEmpty(fromPrevious_.getAppId())) {
            // we know this app's ID, so get its details directly
            server_.getRSConnectApp(fromPrevious_.getAppId(), fromPrevious_.getAccountName(), fromPrevious_.getServer(), new ServerRequestCallback<RSConnectApplicationInfo>() {

                @Override
                public void onResponseReceived(RSConnectApplicationInfo info) {
                    // create a single-entry array with the app ID 
                    JsArray<RSConnectApplicationInfo> infos = JsArray.createArray().cast();
                    if (info != null)
                        infos.push(info);
                    onAppsReceived.onResponseReceived(infos);
                }

                @Override
                public void onError(ServerError error) {
                    onAppsReceived.onError(error);
                }
            });
        } else {
            // we don't know the app ID, get the apps by name
            server_.getRSConnectAppList(fromPrevious_.getAccountName(), fromPrevious_.getServer(), onAppsReceived);
        }
    }
}
Also used : RSConnectApplicationInfo(org.rstudio.studio.client.rsconnect.model.RSConnectApplicationInfo) JsArray(com.google.gwt.core.client.JsArray) ServerError(org.rstudio.studio.client.server.ServerError) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback)

Example 14 with ServerRequestCallback

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

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

the class ProfilerPresenter method onStartProfiler.

@Handler
public void onStartProfiler() {
    dependencyManager_.withProfvis(profilerDependecyUserAction_, new Command() {

        @Override
        public void execute() {
            ProfileOperationRequest request = ProfileOperationRequest.create("");
            server_.startProfiling(request, new ServerRequestCallback<ProfileOperationResponse>() {

                @Override
                public void onResponseReceived(ProfileOperationResponse response) {
                    if (response.getErrorMessage() != null) {
                        globalDisplay_.showErrorMessage("Profiler Error", response.getErrorMessage());
                        return;
                    }
                    pSourceWindowManager_.get().ensureVisibleSourcePaneIfNecessary();
                    response_ = response;
                    sourceServer_.newDocument(FileTypeRegistry.PROFILER.getTypeId(), null, (JsObject) ProfilerContents.create(response.getFileName(), null, null, true).cast(), new SimpleRequestCallback<SourceDocument>("Show Profiler") {

                        @Override
                        public void onResponseReceived(SourceDocument response) {
                            currentDocId_ = response.getId();
                        }

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

                @Override
                public void onError(ServerError error) {
                    Debug.logError(error);
                    globalDisplay_.showErrorMessage("Failed to Stop Profiler", error.getMessage());
                }
            });
        }
    });
}
Also used : Command(com.google.gwt.user.client.Command) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) 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) ProfileOperationRequest(org.rstudio.studio.client.workbench.views.source.editors.profiler.model.ProfileOperationRequest) Handler(org.rstudio.core.client.command.Handler)

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