Search in sources :

Example 11 with Command

use of com.google.gwt.user.client.Command in project rstudio by rstudio.

the class ChunkOptionsPopupPanel method init.

public void init(DocDisplay display, Position position) {
    display_ = display;
    position_ = position;
    chunkOptions_.clear();
    originalChunkOptions_.clear();
    useCustomFigureCheckbox_.setValue(false);
    figureDimensionsPanel_.setVisible(false);
    Command afterInit = new Command() {

        @Override
        public void execute() {
            updateOutputComboBox();
            boolean hasRelevantFigureSettings = has("fig.width") || has("fig.height");
            useCustomFigureCheckbox_.setValue(hasRelevantFigureSettings);
            if (hasRelevantFigureSettings)
                useCustomFigureCheckbox_.setVisible(true);
            figureDimensionsPanel_.setVisible(hasRelevantFigureSettings);
            if (has("fig.width"))
                figWidthBox_.setText(get("fig.width"));
            else
                figWidthBox_.setText("");
            if (has("fig.height"))
                figHeightBox_.setText(get("fig.height"));
            else
                figHeightBox_.setText("");
            if (has("warning"))
                showWarningsInOutputCb_.setValue(getBoolean("warning"));
            if (has("message"))
                showMessagesInOutputCb_.setValue(getBoolean("message"));
            if (has("engine.path")) {
                String enginePath = StringUtil.stringValue(get("engine.path"));
                enginePath = enginePath.replaceAll("\\\\\\\\", "\\\\");
                enginePathBox_.setValue(enginePath);
            }
            if (has("engine.opts")) {
                String engineOpts = StringUtil.stringValue(get("engine.opts"));
                engineOpts = engineOpts.replaceAll("\\\\\\\\", "\\\\");
                engineOptsBox_.setValue(engineOpts);
            }
            setVisible(true);
        }
    };
    initOptions(afterInit);
}
Also used : Command(com.google.gwt.user.client.Command) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand)

Example 12 with Command

use of com.google.gwt.user.client.Command in project rstudio by rstudio.

the class TextEditingTargetNotebook method executeChunk.

public void executeChunk(final Scope chunk) {
    // maximize the source pane if we haven't yet this session
    if (!maximizedPane_ && prefs_.hideConsoleOnChunkExecute().getValue()) {
        pSourceWindowManager_.get().maximizeSourcePaneIfNecessary();
        maximizedPane_ = true;
    }
    docUpdateSentinel_.withSavedDoc(new Command() {

        @Override
        public void execute() {
            // by creating a job that runs both chunks
            if (!isSetupChunkScope(chunk) && needsSetupChunkExecuted()) {
                List<ChunkExecUnit> chunks = new ArrayList<ChunkExecUnit>();
                chunks.add(new ChunkExecUnit(getSetupChunkScope(), NotebookQueueUnit.EXEC_MODE_BATCH));
                chunks.add(new ChunkExecUnit(chunk, NotebookQueueUnit.EXEC_MODE_SINGLE));
                queue_.executeChunks("Run Chunks", chunks);
            } else {
                queue_.executeChunk(new ChunkExecUnit(chunk, NotebookQueueUnit.EXEC_MODE_SINGLE));
            }
        }
    });
}
Also used : Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) List(java.util.List) ArrayList(java.util.ArrayList) ScopeList(org.rstudio.studio.client.workbench.views.source.editors.text.ScopeList)

Example 13 with Command

use of com.google.gwt.user.client.Command in project rstudio by rstudio.

the class Projects method createNewProject.

private void createNewProject(final NewProjectResult newProject, final boolean saveChanges) {
    // This gets a little crazy. We have several pieces of asynchronous logic
    // that each may or may not need to be executed, depending on the type
    // of project being created and on whether the previous pieces of logic
    // succeed. Plus we have this ProgressIndicator that needs to be fed
    // properly.
    final ProgressIndicator indicator = globalDisplay_.getProgressIndicator("Error Creating Project");
    // Here's the command queue that will hold the various operations.
    final SerializedCommandQueue createProjectCmds = new SerializedCommandQueue();
    // WARNING: When calling addCommand, BE SURE TO PASS FALSE as the second
    // argument, to delay running of the commands until they are all
    // scheduled.
    // First, attempt to update the default project location pref
    createProjectCmds.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(final Command continuation) {
            UIPrefs uiPrefs = pUIPrefs_.get();
            // update default project location pref if necessary
            if ((newProject.getNewDefaultProjectLocation() != null) || (newProject.getCreateGitRepo() != uiPrefs.newProjGitInit().getValue())) {
                indicator.onProgress("Saving defaults...");
                if (newProject.getNewDefaultProjectLocation() != null) {
                    uiPrefs.defaultProjectLocation().setGlobalValue(newProject.getNewDefaultProjectLocation());
                }
                if (newProject.getCreateGitRepo() != uiPrefs.newProjGitInit().getValue()) {
                    uiPrefs.newProjGitInit().setGlobalValue(newProject.getCreateGitRepo());
                }
                if (newProject.getUsePackrat() != uiPrefs.newProjUsePackrat().getValue()) {
                    uiPrefs.newProjUsePackrat().setGlobalValue(newProject.getUsePackrat());
                }
                // call the server -- in all cases continue on with
                // creating the project (swallow errors updating the pref)
                projServer_.setUiPrefs(session_.getSessionInfo().getUiPrefs(), new VoidServerRequestCallback(indicator) {

                    @Override
                    public void onResponseReceived(Void response) {
                        continuation.execute();
                    }

                    @Override
                    public void onError(ServerError error) {
                        super.onError(error);
                        continuation.execute();
                    }
                });
            } else {
                continuation.execute();
            }
        }
    }, false);
    // Next, if necessary, clone a repo
    if (newProject.getVcsCloneOptions() != null) {
        createProjectCmds.addCommand(new SerializedCommand() {

            @Override
            public void onExecute(final Command continuation) {
                VcsCloneOptions cloneOptions = newProject.getVcsCloneOptions();
                if (cloneOptions.getVcsName().equals((VCSConstants.GIT_ID)))
                    indicator.onProgress("Cloning Git repository...");
                else
                    indicator.onProgress("Checking out SVN repository...");
                gitServer_.vcsClone(cloneOptions, new ServerRequestCallback<ConsoleProcess>() {

                    @Override
                    public void onResponseReceived(ConsoleProcess proc) {
                        final ConsoleProgressDialog consoleProgressDialog = new ConsoleProgressDialog(proc, gitServer_);
                        consoleProgressDialog.showModal();
                        proc.addProcessExitHandler(new ProcessExitEvent.Handler() {

                            @Override
                            public void onProcessExit(ProcessExitEvent event) {
                                if (event.getExitCode() == 0) {
                                    consoleProgressDialog.hide();
                                    continuation.execute();
                                } else {
                                    indicator.onCompleted();
                                }
                            }
                        });
                    }

                    @Override
                    public void onError(ServerError error) {
                        Debug.logError(error);
                        indicator.onError(error.getUserMessage());
                    }
                });
            }
        }, false);
    }
    // Next, create the project itself -- depending on the type, this
    // could involve creating an R package, or Shiny application, and so on.
    createProjectCmds.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(final Command continuation) {
            // Validate the package name if we're creating a package
            if (newProject.getNewPackageOptions() != null) {
                final String packageName = newProject.getNewPackageOptions().getPackageName();
                if (!PACKAGE_NAME_PATTERN.test(packageName)) {
                    indicator.onError("Invalid package name '" + packageName + "': " + "package names must start with a letter, and contain " + "only letters and numbers.");
                    return;
                }
            }
            indicator.onProgress("Creating project...");
            if (newProject.getNewPackageOptions() == null) {
                projServer_.createProject(newProject.getProjectFile(), newProject.getNewPackageOptions(), newProject.getNewShinyAppOptions(), newProject.getProjectTemplateOptions(), new VoidServerRequestCallback(indicator) {

                    @Override
                    public void onSuccess() {
                        continuation.execute();
                    }
                });
            } else {
                String projectFile = newProject.getProjectFile();
                String packageDirectory = projectFile.substring(0, projectFile.lastIndexOf('/'));
                projServer_.packageSkeleton(newProject.getNewPackageOptions().getPackageName(), packageDirectory, newProject.getNewPackageOptions().getCodeFiles(), newProject.getNewPackageOptions().getUsingRcpp(), new ServerRequestCallback<RResult<Void>>() {

                    @Override
                    public void onResponseReceived(RResult<Void> response) {
                        if (response.failed())
                            indicator.onError(response.errorMessage());
                        else
                            continuation.execute();
                    }

                    @Override
                    public void onError(ServerError error) {
                        Debug.logError(error);
                        indicator.onError(error.getUserMessage());
                    }
                });
            }
        }
    }, false);
    // Next, initialize a git repo if requested
    if (newProject.getCreateGitRepo()) {
        createProjectCmds.addCommand(new SerializedCommand() {

            @Override
            public void onExecute(final Command continuation) {
                indicator.onProgress("Initializing git repository...");
                String projDir = FileSystemItem.createFile(newProject.getProjectFile()).getParentPathString();
                gitServer_.gitInitRepo(projDir, new VoidServerRequestCallback(indicator) {

                    @Override
                    public void onSuccess() {
                        continuation.execute();
                    }

                    @Override
                    public void onFailure() {
                        continuation.execute();
                    }
                });
            }
        }, false);
    }
    // Generate a new packrat project
    if (newProject.getUsePackrat()) {
        createProjectCmds.addCommand(new SerializedCommand() {

            @Override
            public void onExecute(final Command continuation) {
                indicator.onProgress("Initializing packrat project...");
                String projDir = FileSystemItem.createFile(newProject.getProjectFile()).getParentPathString();
                packratServer_.packratBootstrap(projDir, false, new VoidServerRequestCallback(indicator) {

                    @Override
                    public void onSuccess() {
                        continuation.execute();
                    }
                });
            }
        }, false);
    }
    if (newProject.getOpenInNewWindow()) {
        createProjectCmds.addCommand(new SerializedCommand() {

            @Override
            public void onExecute(final Command continuation) {
                FileSystemItem project = FileSystemItem.createFile(newProject.getProjectFile());
                if (Desktop.isDesktop()) {
                    Desktop.getFrame().openProjectInNewWindow(project.getPath());
                    continuation.execute();
                } else {
                    indicator.onProgress("Preparing to open project...");
                    serverOpenProjectInNewWindow(project, newProject.getRVersion(), continuation);
                }
            }
        }, false);
    }
    // If we get here, dismiss the progress indicator
    createProjectCmds.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(Command continuation) {
            indicator.onCompleted();
            if (!newProject.getOpenInNewWindow()) {
                applicationQuit_.performQuit(saveChanges, newProject.getProjectFile(), newProject.getRVersion());
            }
            continuation.execute();
        }
    }, false);
    // Now set it all in motion!
    createProjectCmds.run();
}
Also used : ConsoleProgressDialog(org.rstudio.studio.client.workbench.views.vcs.common.ConsoleProgressDialog) VcsCloneOptions(org.rstudio.studio.client.common.vcs.VcsCloneOptions) SerializedCommand(org.rstudio.core.client.SerializedCommand) SerializedCommandQueue(org.rstudio.core.client.SerializedCommandQueue) ServerError(org.rstudio.studio.client.server.ServerError) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) Command(com.google.gwt.user.client.Command) SerializedCommand(org.rstudio.core.client.SerializedCommand) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ConsoleProcess(org.rstudio.studio.client.common.console.ConsoleProcess) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) UIPrefs(org.rstudio.studio.client.workbench.prefs.model.UIPrefs) Void(org.rstudio.studio.client.server.Void) ProcessExitEvent(org.rstudio.studio.client.common.console.ProcessExitEvent) RResult(org.rstudio.studio.client.server.remote.RResult)

Example 14 with Command

use of com.google.gwt.user.client.Command in project rstudio by rstudio.

the class ProjectPreferencesPane method promptToRestart.

protected void promptToRestart() {
    globalDisplay_.showYesNoMessage(MessageDialog.QUESTION, "Confirm Restart RStudio", "You need to restart RStudio in order for this change to take " + "effect. Do you want to do this now?", new Operation() {

        @Override
        public void execute() {
            forceClosed(new Command() {

                @Override
                public void execute() {
                    SwitchToProjectEvent event = new SwitchToProjectEvent(session_.getSessionInfo().getActiveProjectFile());
                    eventBus_.fireEvent(event);
                }
            });
        }
    }, true);
}
Also used : Command(com.google.gwt.user.client.Command) SwitchToProjectEvent(org.rstudio.studio.client.projects.events.SwitchToProjectEvent) Operation(org.rstudio.core.client.widget.Operation)

Example 15 with Command

use of com.google.gwt.user.client.Command in project rstudio by rstudio.

the class CodeBrowserEditingTarget method initialize.

@Override
public void initialize(SourceDocument document, FileSystemContext fileContext, FileType type, Provider<String> defaultNameProvider) {
    doc_ = document;
    codeExecution_ = new EditingTargetCodeExecution(docDisplay_, getId());
    view_ = new CodeBrowserEditingTargetWidget(commands_, globalDisplay_, events_, server_, docDisplay_);
    TextEditingTarget.registerPrefs(releaseOnDismiss_, prefs_, docDisplay_, document);
    TextEditingTarget.syncFontSize(releaseOnDismiss_, events_, view_, fontSizeManager_);
    releaseOnDismiss_.add(prefs_.softWrapRFiles().addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        public void onValueChange(ValueChangeEvent<Boolean> evt) {
            view_.adaptToFileType(FileTypeRegistry.R);
        }
    }));
    // if we have contents then set them
    CodeBrowserContents contents = getContents();
    if (contents.getContext().length() > 0) {
        ensureContext(contents.getContext(), new Command() {

            @Override
            public void execute() {
            }
        });
    } else {
        docDisplay_.setCode("", false);
    }
}
Also used : ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) CodeBrowserContents(org.rstudio.studio.client.workbench.views.source.model.CodeBrowserContents) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) EditingTargetCodeExecution(org.rstudio.studio.client.workbench.views.source.editors.EditingTargetCodeExecution)

Aggregations

Command (com.google.gwt.user.client.Command)208 AppCommand (org.rstudio.core.client.command.AppCommand)39 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)38 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)21 JsArrayString (com.google.gwt.core.client.JsArrayString)16 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)16 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)16 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)12 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)11 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)11 ServerError (org.rstudio.studio.client.server.ServerError)11 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)9 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)9 MenuItem (com.google.gwt.user.client.ui.MenuItem)8 Handler (org.rstudio.core.client.command.Handler)8 TextEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)8 Timer (com.google.gwt.user.client.Timer)7 Widget (com.google.gwt.user.client.ui.Widget)7 EditingTarget (org.rstudio.studio.client.workbench.views.source.editors.EditingTarget)7