Search in sources :

Example 31 with Operation

use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.

the class RSConnectDeploy method initialize.

@Inject
public void initialize(RSConnectServerOperations server, RSAccountConnector connector, GlobalDisplay display, UIPrefs prefs) {
    server_ = server;
    connector_ = connector;
    display_ = display;
    prefs_ = prefs;
    accountList_ = new RSConnectAccountList(server_, display_, false, !asStatic_);
    appName_ = new AppNameTextbox(this);
    // when the account list finishes populating, select the account from the
    // previous deployment if we have one
    accountList_.setOnRefreshCompleted(new Operation() {

        @Override
        public void execute() {
            if (fromPrevious_ != null) {
                // when re-deploying, select the account used the last time 
                // around
                accountList_.selectAccount(fromPrevious_.getAccount());
            } else {
                // when doing a first-time publish, select the account the user
                // prefers (currently this just tracks the last account used)
                RSConnectAccount preferred = prefs_.preferredPublishAccount().getGlobalValue();
                if (preferred != null) {
                    accountList_.selectAccount(preferred);
                }
                // validate the app name now that we have an account selected
                appName_.validateAppName();
            }
        }
    });
    // when the user selects a different account, show the appropriate UI
    addAccountChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent arg0) {
            if (fromPrevious_ != null) {
                boolean existing = accountList_.getSelectedAccount().equals(fromPrevious_.getAccount());
                appInfoPanel_.setVisible(existing);
                newAppPanel_.setVisible(!existing);
                // validate name if necessary
                if (existing && onDeployEnabled_ != null)
                    onDeployEnabled_.execute();
                else if (!existing)
                    appName_.validateAppName();
            } else {
                // re-validate app name as different accounts have different 
                // name restrictions
                appName_.validateAppName();
            }
        }
    });
}
Also used : RSConnectAccount(org.rstudio.studio.client.rsconnect.model.RSConnectAccount) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) ProgressOperation(org.rstudio.core.client.widget.ProgressOperation) Operation(org.rstudio.core.client.widget.Operation) Inject(com.google.inject.Inject)

Example 32 with Operation

use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.

the class PublishingPreferencesPane method onDisconnect.

private void onDisconnect() {
    final RSConnectAccount account = accountList_.getSelectedAccount();
    if (account == null) {
        display_.showErrorMessage("Error Disconnecting Account", "Please select an account to disconnect.");
        return;
    }
    display_.showYesNoMessage(GlobalDisplay.MSG_QUESTION, "Confirm Remove Account", "Are you sure you want to disconnect the '" + account.getName() + "' account on '" + account.getServer() + "'" + "? This won't delete the account on the server.", false, new Operation() {

        @Override
        public void execute() {
            onConfirmDisconnect(account);
        }
    }, null, null, "Disconnect Account", "Cancel", false);
}
Also used : RSConnectAccount(org.rstudio.studio.client.rsconnect.model.RSConnectAccount) Operation(org.rstudio.core.client.widget.Operation)

Example 33 with Operation

use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.

the class DataImport method onColumnMenuShow.

private Operation onColumnMenuShow(final DataImportPreviewResponse response) {
    final Operation completeAndPreview = new Operation() {

        @Override
        public void execute() {
            previewDataImport();
        }
    };
    return new Operation() {

        @Override
        public void execute() {
            final DataImportDataActiveColumn column = gridViewer_.getActiveColumn();
            columnTypesMenu_.setOnChange(new OperationWithInput<String>() {

                @Override
                public void execute(final String input) {
                    columnTypesMenu_.hide();
                    if (input == "guess") {
                        importOptions_.setColumnType(column.getName(), null);
                        completeAndPreview.execute();
                    } else if (input == "date") {
                        if (dataImportMode_ == DataImportModes.Text) {
                            promptForParseString("Date Format", "%m/%d/%Y", completeAndPreview, column.getName(), input);
                        } else {
                            importOptions_.setColumnType(column.getName(), input);
                            completeAndPreview.execute();
                        }
                    } else if (input == "time") {
                        promptForParseString("Time Format", "%H:%M", completeAndPreview, column.getName(), input);
                    } else if (input == "dateTime") {
                        promptForParseString("Date and Time Format", "%m/%d/%Y %H:%M", completeAndPreview, column.getName(), input);
                    } else if (input == "factor") {
                        promptForFactorString("Factors", completeAndPreview, column.getName(), input);
                    } else {
                        importOptions_.setColumnType(column.getName(), input);
                        completeAndPreview.execute();
                    }
                }
            }, new OperationWithInput<String>() {

                @Override
                public void execute(String input) {
                    if (input == "include") {
                        importOptions_.setOnlyColumn(column.getName(), false);
                        if (importOptions_.getColumnType(column.getName()) == "skip") {
                            importOptions_.setColumnType(column.getName(), null);
                        }
                    }
                    if (input == "only") {
                        importOptions_.setOnlyColumn(column.getName(), true);
                        if (importOptions_.getColumnType(column.getName()) == "skip") {
                            importOptions_.setColumnType(column.getName(), null);
                        }
                    }
                    if (input == "skip") {
                        importOptions_.setOnlyColumn(column.getName(), false);
                        importOptions_.setColumnType(column.getName(), "skip");
                    }
                    columnTypesMenu_.hide();
                    previewDataImport();
                }
            });
            columnTypesMenu_.setPopupPosition(gridViewer_.getAbsoluteLeft() + column.getLeft(), gridViewer_.getAbsoluteTop() + column.getTop());
            columnTypesMenu_.setSize(column.getWidth() + "px", "");
            if (zIndex_ != null) {
                columnTypesMenu_.getElement().getStyle().setZIndex(zIndex_);
            }
            boolean columnOnly = importOptions_.getColumnOnly(column.getName());
            String columnType = importOptions_.getColumnType(column.getName());
            columnTypesMenu_.resetSelected();
            columnTypesMenu_.setSelected(columnType != null ? columnType : "guess");
            if (columnOnly) {
                columnTypesMenu_.setSelected("only");
            }
            columnTypesMenu_.setVisibleColumns(response.getSupportedColumnTypes());
            if (someColumnsHaveNoName(lastSuccessfulResponse_)) {
                columnTypesMenu_.setError("All columns must have names in order to " + "perform column operations.");
                columnTypesMenu_.setWidth("200px");
            }
            columnTypesMenu_.show();
        }
    };
}
Also used : Operation(org.rstudio.core.client.widget.Operation)

Example 34 with Operation

use of org.rstudio.core.client.widget.Operation 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 35 with Operation

use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.

the class DataImport method setGridViewerData.

private void setGridViewerData(DataImportPreviewResponse response) {
    gridViewer_.setOption("nullsAsNAs", "true");
    gridViewer_.setOption("ordering", "false");
    gridViewer_.setOption("rowNumbers", "false");
    gridViewer_.setData(response);
    if (response.getSupportedColumnTypes() != null && response.getSupportedColumnTypes().length > 0) {
        gridViewer_.setColumnDefinitionsUIVisible(true, onColumnMenuShow(response), new Operation() {

            @Override
            public void execute() {
                columnTypesMenu_.hide();
            }
        });
    }
}
Also used : Operation(org.rstudio.core.client.widget.Operation)

Aggregations

Operation (org.rstudio.core.client.widget.Operation)47 ServerError (org.rstudio.studio.client.server.ServerError)8 Command (com.google.gwt.user.client.Command)7 ArrayList (java.util.ArrayList)6 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)5 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)5 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)4 SimpleRequestCallback (org.rstudio.studio.client.common.SimpleRequestCallback)4 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)4 JsArrayString (com.google.gwt.core.client.JsArrayString)3 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)3 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)3 ProgressOperation (org.rstudio.core.client.widget.ProgressOperation)3 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)2 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)2 Timer (com.google.gwt.user.client.Timer)2 HTML (com.google.gwt.user.client.ui.HTML)2 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)2 WindowEx (org.rstudio.core.client.dom.WindowEx)2 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)2