use of org.rstudio.studio.client.server.ServerRequestCallback in project rstudio by rstudio.
the class ProfilerEditingTarget method saveNewFile.
private void saveNewFile(final String suggestedPath) {
FileSystemItem fsi;
if (suggestedPath != null)
fsi = FileSystemItem.createFile(suggestedPath).getParentPath();
else
fsi = workbenchContext_.getDefaultFileDialogDir();
fileDialogs_.saveFile("Save File - " + getName().getValue(), fileContext_, fsi, fileType_.getDefaultExtension(), false, new ProgressOperationWithInput<FileSystemItem>() {
public void execute(final FileSystemItem saveItem, final ProgressIndicator indicator) {
if (saveItem == null)
return;
workbenchContext_.setDefaultFileDialogDir(saveItem.getParentPath());
final String toPath = saveItem.getPath();
server_.copyProfile(htmlLocalPath_, toPath, new ServerRequestCallback<JavaScriptObject>() {
@Override
public void onResponseReceived(JavaScriptObject response) {
savePropertiesWithPath(saveItem.getPath());
persistDocumentProperty("isUserSaved", "saved");
isUserSaved_ = true;
indicator.onCompleted();
}
@Override
public void onError(ServerError error) {
Debug.logError(error);
indicator.onCompleted();
globalDisplay_.showErrorMessage("Failed to Save Profile", error.getMessage());
}
});
}
});
}
use of org.rstudio.studio.client.server.ServerRequestCallback in project rstudio by rstudio.
the class GeneralPreferencesPane method initialize.
@Override
protected void initialize(RPrefs rPrefs) {
// general prefs
final GeneralPrefs generalPrefs = rPrefs.getGeneralPrefs();
showServerHomePage_.setEnabled(true);
reuseSessionsForProjectLinks_.setEnabled(true);
saveWorkspace_.setEnabled(true);
loadRData_.setEnabled(true);
dirChooser_.setEnabled(true);
showServerHomePage_.setValue(generalPrefs.getShowUserHomePage());
reuseSessionsForProjectLinks_.setValue(generalPrefs.getReuseSessionsForProjectLinks());
int saveWorkspaceIndex;
switch(generalPrefs.getSaveAction()) {
case SaveAction.NOSAVE:
saveWorkspaceIndex = 1;
break;
case SaveAction.SAVE:
saveWorkspaceIndex = 0;
break;
case SaveAction.SAVEASK:
default:
saveWorkspaceIndex = 2;
break;
}
saveWorkspace_.getListBox().setSelectedIndex(saveWorkspaceIndex);
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
server_.getTerminalShells(new ServerRequestCallback<JsArray<TerminalShellInfo>>() {
@Override
public void onResponseReceived(JsArray<TerminalShellInfo> shells) {
int currentShell = generalPrefs.getDefaultTerminalShellValue();
int currentShellIndex = 0;
GeneralPreferencesPane.this.terminalShell_.getListBox().clear();
for (int i = 0; i < shells.length(); i++) {
TerminalShellInfo info = shells.get(i);
GeneralPreferencesPane.this.terminalShell_.addChoice(info.getShellName(), Integer.toString(info.getShellType()));
if (info.getShellType() == currentShell)
currentShellIndex = i;
}
if (GeneralPreferencesPane.this.terminalShell_.getListBox().getItemCount() > 0) {
GeneralPreferencesPane.this.terminalShell_.setEnabled((true));
GeneralPreferencesPane.this.terminalShell_.getListBox().setSelectedIndex(currentShellIndex);
}
}
@Override
public void onError(ServerError error) {
}
});
}
});
loadRData_.setValue(generalPrefs.getLoadRData());
dirChooser_.setText(generalPrefs.getInitialWorkingDirectory());
// history prefs
HistoryPrefs historyPrefs = rPrefs.getHistoryPrefs();
alwaysSaveHistory_.setEnabled(true);
removeHistoryDuplicates_.setEnabled(true);
alwaysSaveHistory_.setValue(historyPrefs.getAlwaysSave());
removeHistoryDuplicates_.setValue(historyPrefs.getRemoveDuplicates());
rProfileOnResume_.setValue(generalPrefs.getRprofileOnResume());
rProfileOnResume_.setEnabled(true);
showLastDotValue_.setValue(generalPrefs.getShowLastDotValue());
showLastDotValue_.setEnabled(true);
if (rServerRVersion_ != null)
rServerRVersion_.setRVersion(generalPrefs.getDefaultRVersion());
if (rememberRVersionForProjects_ != null) {
rememberRVersionForProjects_.setValue(generalPrefs.getRestoreProjectRVersion());
}
// projects prefs
ProjectsPrefs projectsPrefs = rPrefs.getProjectsPrefs();
restoreLastProject_.setEnabled(true);
restoreLastProject_.setValue(projectsPrefs.getRestoreLastProject());
}
use of org.rstudio.studio.client.server.ServerRequestCallback in project rstudio by rstudio.
the class RemoteServerAuth method schedulePeriodicCredentialsUpdate.
public void schedulePeriodicCredentialsUpdate() {
// create the callback
periodicUpdateTimer_ = new Timer() {
@Override
public void run() {
updateCredentials(new ServerRequestCallback<Integer>() {
@Override
public void onResponseReceived(Integer response) {
switch(response) {
case CREDENTIALS_UPDATE_SUCCESS:
// credentials)
break;
case CREDENTIALS_UPDATE_FAILURE:
// we are not authorized, blow the client away
remoteServer_.handleUnauthorizedError();
break;
case CREDENTIALS_UPDATE_UNSUPPORTED:
// not supported by the back end so cancel the timer
periodicUpdateTimer_.cancel();
break;
}
}
@Override
public void onError(ServerError serverError) {
// if method is not supported then cancel the timer
Debug.logError(serverError);
}
});
}
};
// schedule for every 5 minutes
final int kMinutes = 5;
int milliseconds = kMinutes * 60 * 1000;
periodicUpdateTimer_.scheduleRepeating(milliseconds);
}
use of org.rstudio.studio.client.server.ServerRequestCallback in project rstudio by rstudio.
the class ProjectOpener method showOpenProjectDialog.
public void showOpenProjectDialog(FileSystemContext fsContext, ProjectsServerOperations server, String defaultLocation, int defaultType, boolean showNewSession, final ProgressOperationWithInput<OpenProjectParams> onCompleted) {
initialize();
// use the default dialog on desktop mode or single-session mode
FileDialogs dialogs = RStudioGinjector.INSTANCE.getFileDialogs();
if (Desktop.isDesktop() || !RStudioGinjector.INSTANCE.getSession().getSessionInfo().getMultiSession()) {
dialogs.openFile("Open Project", fsContext, FileSystemItem.createDir(defaultLocation), "R Projects (*.Rproj)", true, new ProgressOperationWithInput<FileSystemItem>() {
@Override
public void execute(FileSystemItem input, final ProgressIndicator indicator) {
final CommandWithArg<FileSystemItem> onProjectFileReady = new CommandWithArg<FileSystemItem>() {
@Override
public void execute(FileSystemItem item) {
onCompleted.execute(new OpenProjectParams(item, null, false), indicator);
}
};
// null return values here imply a cancellation
if (input == null)
return;
if (input.isDirectory()) {
final String rprojPath = input.completePath(input.getName() + ".Rproj");
final FileSystemItem rprojFile = FileSystemItem.createFile(rprojPath);
server_.createProjectFile(rprojFile.getPath(), new ServerRequestCallback<Boolean>() {
@Override
public void onResponseReceived(Boolean success) {
onProjectFileReady.execute(rprojFile);
}
@Override
public void onError(ServerError error) {
Debug.logError(error);
onProjectFileReady.execute(rprojFile);
}
});
} else {
onProjectFileReady.execute(input);
}
}
});
} else {
// in multi-session mode, we have a special dialog for opening projects
WebFileDialogs webDialogs = (WebFileDialogs) dialogs;
webDialogs.openProject(fsContext, FileSystemItem.createDir(defaultLocation), defaultType, showNewSession, onCompleted);
}
}
use of org.rstudio.studio.client.server.ServerRequestCallback in project rstudio by rstudio.
the class NewPackagePage method validateAsync.
@Override
protected void validateAsync(final NewProjectResult input, final OperationWithInput<Boolean> onValidated) {
// validate package name first
String packageName = txtProjectName_.getText().trim();
if (!isPackageNameValid(packageName)) {
globalDisplay_.showMessage(MessageDialog.WARNING, "Error", "Invalid package name '" + packageName + "'. Package names " + "should start with a letter, and contain only letters and numbers.");
onValidated.execute(false);
return;
}
final FileSystemItem projFile = FileSystemItem.createFile(input.getProjectFile());
final FileSystemItem projDir = projFile.getParentPath();
server_.stat(projDir.getPath(), new ServerRequestCallback<FileSystemItem>() {
@Override
public void onResponseReceived(final FileSystemItem item) {
// no file at this path -- safe for use
if (!item.exists()) {
onValidated.execute(true);
return;
}
// if it was a file, bail
if (!item.isDirectory()) {
globalDisplay_.showMessage(MessageDialog.WARNING, "Error", "A file already exists at path '" + item.getPath() + "'");
onValidated.execute(false);
return;
}
// check if this directory is empty
server_.listFiles(item, false, new ServerRequestCallback<DirectoryListing>() {
@Override
public void onResponseReceived(DirectoryListing listing) {
boolean ok = true;
JsArray<FileSystemItem> children = listing.getFiles();
for (FileSystemItem child : JsUtil.asIterable(children)) {
boolean canIgnore = child.getExtension().equals(".Rproj") || child.getName().startsWith(".");
if (canIgnore)
continue;
ok = false;
break;
}
if (!ok) {
globalDisplay_.showMessage(MessageDialog.WARNING, "Error", "Directory '" + item.getPath() + "' already exists and is not empty.");
}
onValidated.execute(ok);
}
@Override
public void onError(ServerError error) {
Debug.logError(error);
onValidated.execute(true);
}
});
}
@Override
public void onError(ServerError error) {
Debug.logError(error);
onValidated.execute(true);
}
});
}
Aggregations