Search in sources :

Example 36 with Operation

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

the class DataImportOptionsUiCsv method initEvents.

void initEvents() {
    ValueChangeHandler<String> valueChangeHandler = new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> arg0) {
            updateEnabled();
            triggerChange();
        }
    };
    ChangeHandler changeHandler = new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent arg0) {
            updateEnabled();
            triggerChange();
        }
    };
    ChangeHandler delimChangeHandler = new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent arg0) {
            if (delimiterListBox_.getSelectedValue() == "other") {
                globalDisplay_.promptForTextWithOption("Other Delimiter", "Please enter a single character delimiter.", "", false, "", false, new ProgressOperationWithInput<PromptWithOptionResult>() {

                    private void dismissAndUpdate(ProgressIndicator indicator, int newSelectIndex) {
                        lastDelimiterListBoxIndex_ = newSelectIndex;
                        delimiterListBox_.setSelectedIndex(newSelectIndex);
                        indicator.onCompleted();
                        updateEnabled();
                        triggerChange();
                    }

                    @Override
                    public void execute(PromptWithOptionResult result, ProgressIndicator indicator) {
                        String otherDelimiter = result.input;
                        if (otherDelimiter.length() != 1) {
                            globalDisplay_.showErrorMessage("Incorrect Delimiter", "The specified delimiter is not valid.");
                        } else {
                            for (int idxDelimiter = 0; idxDelimiter < delimiterListBox_.getItemCount(); idxDelimiter++) {
                                if (delimiterListBox_.getValue(idxDelimiter) == otherDelimiter) {
                                    dismissAndUpdate(indicator, idxDelimiter);
                                    return;
                                }
                            }
                            int selectedIndex = delimiterListBox_.getSelectedIndex();
                            delimiterListBox_.insertItem("Character " + otherDelimiter, otherDelimiter, selectedIndex - 1);
                            dismissAndUpdate(indicator, selectedIndex - 1);
                        }
                    }
                }, new Operation() {

                    @Override
                    public void execute() {
                        delimiterListBox_.setSelectedIndex(lastDelimiterListBoxIndex_);
                        updateEnabled();
                        triggerChange();
                    }
                });
            } else {
                lastDelimiterListBoxIndex_ = delimiterListBox_.getSelectedIndex();
                updateEnabled();
                triggerChange();
            }
        }
    };
    ValueChangeHandler<Boolean> booleanValueChangeHandler = new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> arg0) {
            updateEnabled();
            triggerChange();
        }
    };
    nameTextBox_.addValueChangeHandler(valueChangeHandler);
    delimiterListBox_.addChangeHandler(delimChangeHandler);
    quotesListBox_.addChangeHandler(changeHandler);
    escapeListBox_.addChangeHandler(changeHandler);
    columnNamesCheckBox_.addValueChangeHandler(booleanValueChangeHandler);
    trimSpacesCheckBox_.addValueChangeHandler(booleanValueChangeHandler);
    openDataViewerCheckBox_.addValueChangeHandler(booleanValueChangeHandler);
    naListBox_.addChangeHandler(changeHandler);
    commentListBox_.addChangeHandler(changeHandler);
    skipTextBox_.addValueChangeHandler(valueChangeHandler);
    localeButton_.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            new DataImportOptionsUiCsvLocale(new OperationWithInput<DataImportOptionsCsvLocale>() {

                @Override
                public void execute(final DataImportOptionsCsvLocale result) {
                    localeInfo_ = result;
                    updateEnabled();
                    triggerChange();
                }
            }, localeInfo_).showModal();
        }
    });
}
Also used : ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) Operation(org.rstudio.core.client.widget.Operation) PromptWithOptionResult(org.rstudio.core.client.MessageDisplay.PromptWithOptionResult) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator)

Example 37 with Operation

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

the class EnvironmentObjects method fillEntryContents.

@Override
public void fillEntryContents(final RObjectEntry entry, final int idx, boolean drawProgress) {
    entry.expanded = false;
    entry.isExpanding = true;
    if (drawProgress)
        redrawRowSafely(idx);
    observer_.fillObjectContents(entry.rObject, new Operation() {

        public void execute() {
            entry.expanded = true;
            entry.isExpanding = false;
            redrawRowSafely(idx);
        }
    });
}
Also used : Operation(org.rstudio.core.client.widget.Operation)

Example 38 with Operation

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

the class Packages method onInstallPackage.

void onInstallPackage() {
    withPackageInstallContext(new OperationWithInput<PackageInstallContext>() {

        @Override
        public void execute(final PackageInstallContext installContext) {
            if (installContext.isDefaultLibraryWriteable()) {
                continueInstallPackage(installContext);
            } else {
                globalDisplay_.showYesNoMessage(MessageDialog.QUESTION, "Create Package Library", "Would you like to create a personal library '" + installContext.getDefaultUserLibraryPath() + "' " + "to install packages into?", false, new // Yes operation
                Operation() {

                    @Override
                    public void execute() {
                        ProgressIndicator indicator = globalDisplay_.getProgressIndicator("Error Creating Library");
                        server_.initDefaultUserLibrary(new VoidServerRequestCallback(indicator) {

                            @Override
                            protected void onSuccess() {
                                // call this function back recursively
                                // so we can retrieve the updated 
                                // PackageInstallContext from the server
                                onInstallPackage();
                            }
                        });
                    }
                }, new // No operation
                Operation() {

                    @Override
                    public void execute() {
                        globalDisplay_.showMessage(MessageDialog.WARNING, "Install Packages", "Unable to install packages (default library '" + installContext.getDefaultLibraryPath() + "' is " + "not writeable)");
                    }
                }, true);
            }
        }
    });
}
Also used : ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) Operation(org.rstudio.core.client.widget.Operation) PackageInstallContext(org.rstudio.studio.client.workbench.views.packages.model.PackageInstallContext)

Example 39 with Operation

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

the class Packages method removePackage.

public void removePackage(final PackageInfo packageInfo) {
    withPackageInstallContext(new OperationWithInput<PackageInstallContext>() {

        @Override
        public void execute(final PackageInstallContext installContext) {
            final boolean usingDefaultLibrary = packageInfo.getLibrary().equals(installContext.getDefaultLibraryPath());
            StringBuilder message = new StringBuilder();
            message.append("Are you sure you wish to permanently uninstall the '");
            message.append(packageInfo.getName() + "' package");
            if (!usingDefaultLibrary) {
                message.append(" from library '");
                message.append(packageInfo.getLibrary());
                message.append("'");
            }
            message.append("? This action cannot be undone.");
            globalDisplay_.showYesNoMessage(MessageDialog.WARNING, "Uninstall Package ", message.toString(), new Operation() {

                @Override
                public void execute() {
                    StringBuilder command = new StringBuilder();
                    command.append("remove.packages(\"");
                    command.append(packageInfo.getName());
                    command.append("\"");
                    if (!usingDefaultLibrary) {
                        command.append(", lib=\"");
                        command.append(packageInfo.getLibrary());
                        command.append("\"");
                    }
                    command.append(")");
                    String cmd = command.toString();
                    events_.fireEvent(new SendToConsoleEvent(cmd, true));
                }
            }, true);
        }
    });
}
Also used : SendToConsoleEvent(org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent) Operation(org.rstudio.core.client.widget.Operation) PackageInstallContext(org.rstudio.studio.client.workbench.views.packages.model.PackageInstallContext)

Example 40 with Operation

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

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