use of org.rstudio.studio.client.server.VoidServerRequestCallback 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();
}
use of org.rstudio.studio.client.server.VoidServerRequestCallback in project rstudio by rstudio.
the class HTMLPreviewPresenter method onSaveHtmlPreviewAs.
@Handler
public void onSaveHtmlPreviewAs() {
if (lastSuccessfulPreview_ != null) {
FileSystemItem defaultDir = savePreviewDir_ != null ? FileSystemItem.createDir(savePreviewDir_) : FileSystemItem.home();
final FileSystemItem sourceFile = FileSystemItem.createFile(lastSuccessfulPreview_.getHtmlFile());
FileSystemItem initialFilePath = FileSystemItem.createFile(defaultDir.completePath(sourceFile.getStem()));
fileDialogs_.saveFile("Save File As", fileSystemContext_, initialFilePath, sourceFile.getExtension(), false, new ProgressOperationWithInput<FileSystemItem>() {
@Override
public void execute(FileSystemItem targetFile, ProgressIndicator indicator) {
if (targetFile == null || sourceFile.equalTo(targetFile)) {
indicator.onCompleted();
return;
}
indicator.onProgress("Saving File...");
server_.copyFile(sourceFile, targetFile, true, new VoidServerRequestCallback(indicator));
savePreviewDir_ = targetFile.getParentPathString();
session_.persistClientState();
}
});
}
}
use of org.rstudio.studio.client.server.VoidServerRequestCallback in project rstudio by rstudio.
the class RmdOutput method notifyRmdOutputClosed.
// when the window is closed, remember our position within it
private void notifyRmdOutputClosed(JavaScriptObject closeParams) {
// save anchor location for presentations and scroll position for
// documents
RmdPreviewParams params = closeParams.cast();
cacheDocPosition(params.getResult(), params.getScrollPosition(), params.getAnchor());
// if this is a Shiny document, stop the associated process
if (params.isShinyDocument() && !restarting_) {
server_.terminateRenderRmd(true, new VoidServerRequestCallback());
}
shinyDoc_ = null;
}
use of org.rstudio.studio.client.server.VoidServerRequestCallback in project rstudio by rstudio.
the class Source method onGetEditorContext.
@Override
public void onGetEditorContext(GetEditorContextEvent event) {
GetEditorContextEvent.Data data = event.getData();
int type = data.getType();
if (type == GetEditorContextEvent.TYPE_ACTIVE_EDITOR) {
if (consoleEditorHadFocusLast() || activeEditor_ == null)
type = GetEditorContextEvent.TYPE_CONSOLE_EDITOR;
else
type = GetEditorContextEvent.TYPE_SOURCE_EDITOR;
}
if (type == GetEditorContextEvent.TYPE_CONSOLE_EDITOR) {
InputEditorDisplay editor = consoleEditorProvider_.getConsoleEditor();
if (editor != null && editor instanceof DocDisplay) {
getEditorContext("#console", "", (DocDisplay) editor);
return;
}
} else if (type == GetEditorContextEvent.TYPE_SOURCE_EDITOR) {
EditingTarget target = activeEditor_;
if (target != null && target instanceof TextEditingTarget) {
getEditorContext(target.getId(), target.getPath(), ((TextEditingTarget) target).getDocDisplay());
return;
}
}
// We need to ensure a 'getEditorContext' event is always
// returned as we have a 'wait-for' event on the server side
server_.getEditorContextCompleted(GetEditorContextEvent.SelectionData.create(), new VoidServerRequestCallback());
}
use of org.rstudio.studio.client.server.VoidServerRequestCallback in project rstudio by rstudio.
the class PresentationDispatcher method fireEventFromTutorialDirectory.
private void fireEventFromTutorialDirectory(final GwtEvent<?> event) {
SessionInfo sessionInfo = session_.getSessionInfo();
PresentationState state = sessionInfo.getPresentationState();
FileSystemItem projectDir = sessionInfo.getActiveProjectDir();
if (state.isTutorial() && (projectDir != null)) {
if (!workbenchContext_.getCurrentWorkingDir().equalTo(projectDir)) {
server_.setWorkingDirectory(projectDir.getPath(), new VoidServerRequestCallback() {
@Override
protected void onSuccess() {
eventBus_.fireEvent(event);
}
});
} else {
eventBus_.fireEvent(event);
}
} else {
eventBus_.fireEvent(event);
}
}
Aggregations