use of com.google.gwt.core.client.Scheduler.ScheduledCommand in project rstudio by rstudio.
the class FastSelectTable method setSelected.
public void setSelected(TableRowElement row, boolean selected) {
try {
if (row.getParentElement().getParentElement() != table_)
return;
} catch (NullPointerException npe) {
return;
}
boolean isCurrentlySelected = isSelected(row);
if (isCurrentlySelected == selected)
return;
if (selected && !codec_.isValueRow(row))
return;
setStyleName(row, selectedClassName_, selected);
if (selected)
selectedRows_.add(row);
else
selectedRows_.remove(row);
if (selected && !allowMultiSelect_) {
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
public void execute() {
fireEvent(new SelectionChangedEvent());
}
});
}
}
use of com.google.gwt.core.client.Scheduler.ScheduledCommand 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 com.google.gwt.core.client.Scheduler.ScheduledCommand in project rstudio by rstudio.
the class RemoteServerAuth method updateCredentials.
public void updateCredentials(final ServerRequestCallback<Integer> requestCallback) {
// safely cleanup any previously active update credentials forms
safeCleanupPreviousUpdateCredentials();
// create a hidden form panel to submit the update credentials to
// (we do this so GWT manages the trickiness associated with
// managing and reading the contents of a hidden iframe)
final FormPanel updateCredentialsForm = new FormPanel();
updateCredentialsForm.setMethod(FormPanel.METHOD_GET);
updateCredentialsForm.setEncoding(FormPanel.ENCODING_URLENCODED);
// form url
String url = remoteServer_.getApplicationURL("auth-update-credentials");
updateCredentialsForm.setAction(url);
// request log entry (fake up a json rpc method call to conform
// to the data format expected by RequestLog
String requestId = Integer.toString(Random.nextInt());
String requestData = createRequestData();
final RequestLogEntry logEntry = RequestLog.log(requestId, requestData);
// form submit complete handler
updateCredentialsForm.addSubmitCompleteHandler(new SubmitCompleteHandler() {
public void onSubmitComplete(SubmitCompleteEvent event) {
// parse the results
String results = event.getResults();
RpcResponse response = RpcResponse.parse(event.getResults());
if (response != null) {
logEntry.logResponse(ResponseType.Normal, results);
// check for error
RpcError rpcError = response.getError();
if (rpcError != null) {
if (rpcError.getCode() == RpcError.METHOD_NOT_FOUND) {
requestCallback.onResponseReceived(new Integer(CREDENTIALS_UPDATE_UNSUPPORTED));
} else {
requestCallback.onError(new RemoteServerError(rpcError));
}
} else // must be a valid response
{
Bool authenticated = response.getResult();
if (authenticated.getValue()) {
requestCallback.onResponseReceived(new Integer(CREDENTIALS_UPDATE_SUCCESS));
} else {
requestCallback.onResponseReceived(new Integer(CREDENTIALS_UPDATE_FAILURE));
}
}
} else // error parsing results
{
logEntry.logResponse(ResponseType.Error, results);
// form message
String msg = "Error parsing results: " + (results != null ? results : "(null)");
// we don't expect this so debug log to flag our attention
Debug.log("UPDATE CREDENTIALS: " + msg);
// return the error
RpcError rpcError = RpcError.create(RpcError.PARSE_ERROR, msg);
requestCallback.onError(new RemoteServerError(rpcError));
}
// remove the hidden form (from both last-ditch list and DOM)
previousUpdateCredentialsForms_.remove(updateCredentialsForm);
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
public void execute() {
RootPanel.get().remove(updateCredentialsForm);
}
});
}
});
// add the (hidden) form panel to the document and last ditch list
RootPanel.get().add(updateCredentialsForm, -1000, -1000);
previousUpdateCredentialsForms_.add(updateCredentialsForm);
// submit the form
updateCredentialsForm.submit();
}
use of com.google.gwt.core.client.Scheduler.ScheduledCommand in project rstudio by rstudio.
the class TextEditingTargetWidget method setFormatOptions.
@Override
public void setFormatOptions(TextFileType fileType, boolean showRmdFormatMenu, boolean canEditFormatOptions, List<String> options, List<String> values, List<String> extensions, String selectedOption) {
if (!canEditFormatOptions) {
setFormatText("");
}
setRmdFormatButtonVisible(showRmdFormatMenu);
rmdFormatButton_.setEnabled(showRmdFormatMenu);
rmdFormatButton_.clearMenu();
int parenPos = selectedOption.indexOf('(');
if (parenPos != -1)
selectedOption = selectedOption.substring(0, parenPos).trim();
// don't show format text (but leave the code in for now in case
// we change our mind)
// setFormatText(selectedOption);
setFormatText("");
String prefix = fileType.isPlainMarkdown() ? "Preview " : "Knit to ";
for (int i = 0; i < Math.min(options.size(), values.size()); i++) {
String ext = extensions.get(i);
ImageResource img = ext != null ? fileTypeRegistry_.getIconForFilename("output." + ext) : fileTypeRegistry_.getIconForFilename("Makefile");
final String valueName = values.get(i);
ScheduledCommand cmd = new ScheduledCommand() {
@Override
public void execute() {
handlerManager_.fireEvent(new RmdOutputFormatChangedEvent(valueName));
}
};
String text = ext == ".nb.html" ? "Preview Notebook" : prefix + options.get(i);
MenuItem item = ImageMenuItem.create(img, text, cmd, 2);
rmdFormatButton_.addMenuItem(item, values.get(i));
}
if (session_.getSessionInfo().getKnitParamsAvailable()) {
final AppCommand knitWithParams = commands_.knitWithParameters();
rmdFormatButton_.addSeparator();
ScheduledCommand cmd = new ScheduledCommand() {
@Override
public void execute() {
knitWithParams.execute();
}
};
MenuItem item = new MenuItem(knitWithParams.getMenuHTML(false), true, cmd);
rmdFormatButton_.addMenuItem(item, knitWithParams.getMenuLabel(false));
}
if (session_.getSessionInfo().getKnitWorkingDirAvailable()) {
MenuBar knitDirMenu = new MenuBar(true);
DocPropMenuItem knitInDocDir = new DocShadowPropMenuItem("Document Directory", docUpdateSentinel_, uiPrefs_.knitWorkingDir(), RenderRmdEvent.WORKING_DIR_PROP, UIPrefsAccessor.KNIT_DIR_DEFAULT);
knitDirMenu.addItem(knitInDocDir);
DocPropMenuItem knitInProjectDir = new DocShadowPropMenuItem("Project Directory", docUpdateSentinel_, uiPrefs_.knitWorkingDir(), RenderRmdEvent.WORKING_DIR_PROP, UIPrefsAccessor.KNIT_DIR_PROJECT);
knitDirMenu.addItem(knitInProjectDir);
DocPropMenuItem knitInCurrentDir = new DocShadowPropMenuItem("Current Working Directory", docUpdateSentinel_, uiPrefs_.knitWorkingDir(), RenderRmdEvent.WORKING_DIR_PROP, UIPrefsAccessor.KNIT_DIR_CURRENT);
knitDirMenu.addItem(knitInCurrentDir);
rmdFormatButton_.addSeparator();
rmdFormatButton_.addMenuItem(knitDirMenu, "Knit Directory");
}
addClearKnitrCacheMenu(rmdFormatButton_);
showRmdViewerMenuItems(true, canEditFormatOptions, fileType.isRmd(), RmdOutput.TYPE_STATIC);
if (publishButton_ != null)
publishButton_.setIsStatic(true);
isShiny_ = false;
}
use of com.google.gwt.core.client.Scheduler.ScheduledCommand in project rstudio by rstudio.
the class AceEditorBackgroundLinkHighlighter method onDocumentChanged.
@Override
public void onDocumentChanged(DocumentChangedEvent event) {
// clear markers within the delete range
clearMarkers(event.getEvent().getRange());
// prepare highlighter
int row = event.getEvent().getRange().getStart().getRow();
nextHighlightStart_ = Math.min(nextHighlightStart_, row);
timer_.schedule(700);
// update marker positions (deferred so that anchors update)
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
final SafeMap<Integer, List<MarkerRegistration>> newMarkers = new SafeMap<Integer, List<MarkerRegistration>>();
MapUtil.forEach(activeMarkers_, new ForEachCommand<Integer, List<MarkerRegistration>>() {
@Override
public void execute(Integer oldRow, List<MarkerRegistration> markers) {
if (markers == null || markers.isEmpty())
return;
// all markers here should have same row
int newRow = markers.get(0).getRange().getStart().getRow();
newMarkers.put(newRow, markers);
}
});
activeMarkers_.clear();
activeMarkers_ = newMarkers;
}
});
}
Aggregations