use of com.google.gwt.core.client.Scheduler.RepeatingCommand in project rstudio by rstudio.
the class TextEditingTarget method showStatusBarPopupMenu.
private void showStatusBarPopupMenu(StatusBarPopupRequest popupRequest) {
final StatusBarPopupMenu menu = popupRequest.getMenu();
MenuItem defaultItem = popupRequest.getDefaultMenuItem();
if (defaultItem != null) {
menu.selectItem(defaultItem);
Scheduler.get().scheduleFinally(new RepeatingCommand() {
public boolean execute() {
menu.ensureSelectedIsVisible();
return false;
}
});
}
menu.showRelativeToUpward((UIObject) statusBar_.getScope(), false);
}
use of com.google.gwt.core.client.Scheduler.RepeatingCommand in project rstudio by rstudio.
the class TextEditingTarget method initialize.
public void initialize(final SourceDocument document, FileSystemContext fileContext, FileType type, Provider<String> defaultNameProvider) {
id_ = document.getId();
fileContext_ = fileContext;
fileType_ = (TextFileType) type;
codeExecution_ = new EditingTargetCodeExecution(this, docDisplay_, getId(), this);
extendedType_ = document.getExtendedType();
extendedType_ = rmarkdownHelper_.detectExtendedType(document.getContents(), extendedType_, fileType_);
themeHelper_ = new TextEditingTargetThemeHelper(this, events_);
docUpdateSentinel_ = new DocUpdateSentinel(server_, docDisplay_, document, globalDisplay_.getProgressIndicator("Save File"), dirtyState_, events_);
view_ = new TextEditingTargetWidget(this, docUpdateSentinel_, commands_, prefs_, fileTypeRegistry_, docDisplay_, fileType_, extendedType_, events_, session_);
roxygenHelper_ = new RoxygenHelper(docDisplay_, view_);
// create notebook and forward resize events
chunks_ = new TextEditingTargetChunks(this);
notebook_ = new TextEditingTargetNotebook(this, chunks_, view_, docDisplay_, dirtyState_, docUpdateSentinel_, document, releaseOnDismiss_, dependencyManager_);
view_.addResizeHandler(notebook_);
// ensure that Makefile and Makevars always use tabs
name_.addValueChangeHandler(new ValueChangeHandler<String>() {
@Override
public void onValueChange(ValueChangeEvent<String> event) {
if ("Makefile".equals(event.getValue()) || "Makefile.in".equals(event.getValue()) || "Makefile.win".equals(event.getValue()) || "Makevars".equals(event.getValue()) || "Makevars.in".equals(event.getValue()) || "Makevars.win".equals(event.getValue())) {
docDisplay_.setUseSoftTabs(false);
}
}
});
name_.setValue(getNameFromDocument(document, defaultNameProvider), true);
String contents = document.getContents();
docDisplay_.setCode(contents, false);
// Load and apply folds.
final ArrayList<Fold> folds = Fold.decode(document.getFoldSpec());
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
for (Fold fold : folds) docDisplay_.addFold(fold.getRange());
}
});
// Load and apply Vim marks (if they exist).
if (document.getProperties().hasKey("marks")) {
final String marksSpec = document.getProperties().getString("marks");
final JsMap<Position> marks = VimMarks.decode(marksSpec);
// Time out the marks setting just to avoid conflict with other
// mutations of the editor.
new Timer() {
@Override
public void run() {
docDisplay_.setMarks(marks);
}
}.schedule(100);
}
registerPrefs(releaseOnDismiss_, prefs_, docDisplay_, document);
// Initialize sourceOnSave, and keep it in sync
view_.getSourceOnSave().setValue(document.sourceOnSave(), false);
view_.getSourceOnSave().addValueChangeHandler(new ValueChangeHandler<Boolean>() {
public void onValueChange(ValueChangeEvent<Boolean> event) {
docUpdateSentinel_.setSourceOnSave(event.getValue(), globalDisplay_.getProgressIndicator("Error Saving Setting"));
}
});
if (document.isDirty())
dirtyState_.markDirty(false);
else
dirtyState_.markClean();
docDisplay_.addValueChangeHandler(new ValueChangeHandler<Void>() {
public void onValueChange(ValueChangeEvent<Void> event) {
dirtyState_.markDirty(true);
docDisplay_.clearSelectionHistory();
}
});
docDisplay_.addFocusHandler(new FocusHandler() {
public void onFocus(FocusEvent event) {
// let anyone listening know this doc just got focus
events_.fireEvent(new DocFocusedEvent(getPath(), getId()));
if (queuedCollabParams_ != null) {
// of one
if (docDisplay_ != null && !docDisplay_.hasActiveCollabSession()) {
beginQueuedCollabSession();
}
}
// check to see if the file's been saved externally--we do this even
// in a collaborative editing session so we can get delete
// notifications
Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
public boolean execute() {
if (view_.isAttached())
checkForExternalEdit();
return false;
}
}, 500);
}
});
if (fileType_.isR()) {
docDisplay_.addBreakpointSetHandler(new BreakpointSetEvent.Handler() {
@Override
public void onBreakpointSet(BreakpointSetEvent event) {
if (event.isSet()) {
Breakpoint breakpoint = null;
// don't try to set breakpoints in unsaved code
if (isNewDoc()) {
view_.showWarningBar("Breakpoints cannot be set until " + "the file is saved.");
return;
}
// don't try to set breakpoints if the R version is too old
if (!session_.getSessionInfo().getHaveSrcrefAttribute()) {
view_.showWarningBar("Editor breakpoints require R 2.14 " + "or newer.");
return;
}
Position breakpointPosition = Position.create(event.getLineNumber() - 1, 1);
// if we're not in function scope, or this is a Shiny file,
// set a top-level (aka. Shiny-deferred) breakpoint
ScopeFunction innerFunction = null;
if (extendedType_ == null || !extendedType_.startsWith(SourceDocument.XT_SHINY_PREFIX))
innerFunction = docDisplay_.getFunctionAtPosition(breakpointPosition, false);
if (innerFunction == null || !innerFunction.isFunction() || StringUtil.isNullOrEmpty(innerFunction.getFunctionName())) {
breakpoint = breakpointManager_.setTopLevelBreakpoint(getPath(), event.getLineNumber());
} else // the scope tree will find nested functions, but in R these
// are addressable only as substeps of the parent function.
// keep walking up the scope tree until we've reached the top
// level function.
{
while (innerFunction.getParentScope() != null && innerFunction.getParentScope().isFunction()) {
innerFunction = (ScopeFunction) innerFunction.getParentScope();
}
String functionName = innerFunction.getFunctionName();
breakpoint = breakpointManager_.setBreakpoint(getPath(), functionName, event.getLineNumber(), dirtyState().getValue() == false);
}
docDisplay_.addOrUpdateBreakpoint(breakpoint);
} else {
breakpointManager_.removeBreakpoint(event.getBreakpointId());
}
updateBreakpointWarningBar();
}
});
docDisplay_.addBreakpointMoveHandler(new BreakpointMoveEvent.Handler() {
@Override
public void onBreakpointMove(BreakpointMoveEvent event) {
breakpointManager_.moveBreakpoint(event.getBreakpointId());
}
});
}
// validate required components (e.g. Tex, knitr, C++ etc.)
checkCompilePdfDependencies();
rmarkdownHelper_.verifyPrerequisites(view_, fileType_);
syncFontSize(releaseOnDismiss_, events_, view_, fontSizeManager_);
final String rTypeId = FileTypeRegistry.R.getTypeId();
releaseOnDismiss_.add(prefs_.softWrapRFiles().addValueChangeHandler(new ValueChangeHandler<Boolean>() {
public void onValueChange(ValueChangeEvent<Boolean> evt) {
if (fileType_.getTypeId().equals(rTypeId))
view_.adaptToFileType(fileType_);
}
}));
releaseOnDismiss_.add(events_.addHandler(FileChangeEvent.TYPE, new FileChangeHandler() {
@Override
public void onFileChange(FileChangeEvent event) {
// screen out adds and events that aren't for our path
FileChange fileChange = event.getFileChange();
if (fileChange.getType() == FileChange.ADD)
return;
else if (!fileChange.getFile().getPath().equals(getPath()))
return;
// always check for changes if this is the active editor
if (commandHandlerReg_ != null) {
checkForExternalEdit();
} else // this will show a confirmation dialog
if (event.getFileChange().getType() == FileChange.MODIFIED && dirtyState().getValue() == false) {
checkForExternalEdit();
}
}
}));
spelling_ = new TextEditingTargetSpelling(docDisplay_, docUpdateSentinel_);
// show/hide the debug toolbar when the dirty state changes. (note:
// this doesn't yet handle the case where the user saves the document,
// in which case we should still show some sort of warning.)
dirtyState().addValueChangeHandler(new ValueChangeHandler<Boolean>() {
public void onValueChange(ValueChangeEvent<Boolean> evt) {
updateDebugWarningBar();
}
});
// find all of the debug breakpoints set in this document and replay them
// onto the edit surface
ArrayList<Breakpoint> breakpoints = breakpointManager_.getBreakpointsInFile(getPath());
for (Breakpoint breakpoint : breakpoints) {
docDisplay_.addOrUpdateBreakpoint(breakpoint);
}
if (extendedType_.equals(SourceDocument.XT_RMARKDOWN)) {
// populate the popup menu with a list of available formats
updateRmdFormatList();
setRMarkdownBehaviorEnabled(true);
}
view_.addRmdFormatChangedHandler(new RmdOutputFormatChangedEvent.Handler() {
@Override
public void onRmdOutputFormatChanged(RmdOutputFormatChangedEvent event) {
setRmdFormat(event.getFormat());
}
});
syncPublishPath(document.getPath());
initStatusBar();
}
use of com.google.gwt.core.client.Scheduler.RepeatingCommand in project rstudio by rstudio.
the class CheckSpelling method handleMisspelledWord.
private void handleMisspelledWord(Range range) {
try {
docDisplay_.setSelectionRange(range);
docDisplay_.moveCursorNearTop();
view_.clearSuggestions();
view_.getReplacement().setText("");
final String word = docDisplay_.getTextForRange(range);
if (changeAll_.containsKey(word)) {
doReplacement(changeAll_.get(word));
findNextMisspelling();
return;
}
view_.getMisspelledWord().setText(word);
// This fixed delay is regrettable but necessary as it can take some
// time for Ace's scrolling logic to actually execute (i.e. the next
// time the renderloop runs). If we don't wait, then misspelled words
// at the end of the document will result in misreported cursor bounds,
// meaning we'll be avoiding a completely incorrect region.
Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
@Override
public boolean execute() {
showDialog(docDisplay_.getCursorBounds());
view_.focusReplacement();
spellChecker_.suggestionList(word, new ServerRequestCallback<JsArrayString>() {
@Override
public void onResponseReceived(JsArrayString response) {
String[] suggestions = JsUtil.toStringArray(response);
view_.setSuggestions(suggestions);
if (suggestions.length > 0) {
view_.getReplacement().setText(suggestions[0]);
view_.focusReplacement();
}
}
@Override
public void onError(ServerError error) {
Debug.logError(error);
}
});
return false;
}
}, 100);
} catch (Exception e) {
Debug.log(e.toString());
close();
RStudioGinjector.INSTANCE.getGlobalDisplay().showErrorMessage("Check Spelling", "An error has occurred:\n\n" + e.getMessage());
callback_.onFailure(e);
}
}
use of com.google.gwt.core.client.Scheduler.RepeatingCommand in project rstudio by rstudio.
the class CommitDetail method setDetails.
@Override
public void setDetails(final DiffParser unifiedParser, final boolean suppressViewLink) {
setProgressVisible(false);
invalidation_.invalidate();
final Token token = invalidation_.getInvalidationToken();
Scheduler.get().scheduleIncremental(new RepeatingCommand() {
@Override
public boolean execute() {
if (token.isInvalid())
return false;
final DiffFileHeader fileHeader = unifiedParser.nextFilePair();
if (fileHeader == null)
return false;
int filesCompared = 2;
ArrayList<ChunkOrLine> lines = new ArrayList<ChunkOrLine>();
DiffChunk chunk;
while (null != (chunk = unifiedParser.nextChunk())) {
if (!chunk.shouldIgnore())
filesCompared = chunk.getRanges().length;
lines.addAll(ChunkOrLine.fromChunk(chunk));
}
LineTableView view = new LineTableView(filesCompared);
view.setUseStartBorder(true);
view.setUseEndBorder(false);
view.setShowActions(false);
view.setData(lines, PatchMode.Stage);
view.setWidth("100%");
final DiffFrame diffFrame = new DiffFrame(null, fileHeader.getDescription(), null, commit_.getId(), view, new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
fireEvent(new ViewFileRevisionEvent(commit_.getId(), fileHeader.getDescription().trim()));
}
}, suppressViewLink);
diffFrame.setWidth("100%");
detailPanel_.add(diffFrame);
CommitTocRow tocAnchor = new CommitTocRow(fileHeader.getDescription());
tocAnchor.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Point relativePosition = DomUtils.getRelativePosition(container_.getElement(), diffFrame.getElement());
container_.setVerticalScrollPosition(relativePosition.getY());
}
});
tocPanel_.add(tocAnchor);
return true;
}
});
}
use of com.google.gwt.core.client.Scheduler.RepeatingCommand in project perun by CESNET.
the class AddPublicationsTabItem method loadImportScreen.
/**
* Draw tab content for IMPORT state.
*/
private void loadImportScreen() {
// MAIN PANEL
final VerticalPanel mainPanel = new VerticalPanel();
mainPanel.setSize("100%", "100%");
// MAIN MENU
TabMenu menu = new TabMenu();
mainPanel.add(menu);
mainPanel.setCellHeight(menu, "30px");
menu.addWidget(new Image(LargeIcons.INSTANCE.bookEditIcon()));
Label headerTitle = new Label("Import publications");
headerTitle.getElement().setAttribute("style", "font-size: 1.35em;");
menu.addWidget(headerTitle);
CustomButton searchButton = new CustomButton("Search in", SmallIcons.INSTANCE.booksIcon());
searchButton.setTitle("Search in external source for yours publications");
// CALLBACK
final FindExternalPublications find = new FindExternalPublications(userId, JsonCallbackEvents.disableButtonEvents(searchButton));
// WIDGETS
final CustomButton importButton = new CustomButton("Import", SmallIcons.INSTANCE.addIcon());
importButton.setTitle("Loading...");
final ListBox yearSince = new ListBox(false);
final ListBox yearTill = new ListBox(false);
final CheckBox addAsAuthor = new CheckBox("Add me as author");
addAsAuthor.setValue(true);
addAsAuthor.setTitle("When checked, you will be automatically added as author of imported publications");
final ListBox namespace = new ListBox(false);
namespace.addItem("Prezentator (MU)", "mu");
namespace.addItem("OBD 3.0 (ZČU)", "zcu");
namespace.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
// set namespace on change
find.setNamespace(namespace.getValue(namespace.getSelectedIndex()));
}
});
namespace.setTitle("Select publications external source to search in.");
// mu by default
find.setNamespace("mu");
// save for import
importButton.setEnabled(false);
GetCategories request = new GetCategories(new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
categories = JsonUtils.jsoAsList(jso);
if (!categories.isEmpty()) {
for (Category c : categories) {
if (c.getName().equalsIgnoreCase("Ke kontrole")) {
importButton.setTitle("Import selected publications into Perun");
// set default
defaultCategoryId = c.getId();
}
}
}
}
public void onError(PerunError error) {
importButton.setTitle("Unable to retrieve default category. Please refresh tab.");
importButton.setEnabled(false);
}
});
request.retrieveData();
importButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
for (final Publication pub : find.getTableSelectedList()) {
// set default category for import
pub.setCategoryId(defaultCategoryId);
CreatePublication request = new CreatePublication(new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
Publication pub = jso.cast();
importedPublications.add(pub);
counter--;
if (addAsAuthor.getValue() && !pub.getLocked()) {
// create authorship only if wanted and not locked
CreateAuthorship request = new CreateAuthorship();
request.createAuthorship(pub.getId(), userId);
}
}
@Override
public void onError(PerunError error) {
// FIXME - for local testing
/*
pub.setId(624);
pub.setLocked(false);
pub.setCategoryName("Ke kontrole");
importedPublications.add(pub);
*/
counter--;
hadError = true;
}
});
request.createPublication(pub);
counter++;
}
Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
public boolean execute() {
if (counter == 0) {
state = State.REVIEW;
// reload this tab with imported publications
session.getTabManager().reloadTab(tab);
return false;
} else {
return true;
}
}
}, // run every 500ms
500);
}
});
searchButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (userId == 0) {
Window.alert("User ID = 0 is not valid. Please select User tu search for his/hers publications.");
return;
}
find.setUser(userId);
find.setYearSince(Integer.parseInt(yearSince.getValue(yearSince.getSelectedIndex())));
find.setYearTill(Integer.parseInt(yearTill.getValue(yearTill.getSelectedIndex())));
find.clearTable();
find.retrieveData();
}
});
// FILL LISTBOXS
for (int i = 2004; i <= JsonUtils.getCurrentYear(); i++) {
yearSince.addItem(String.valueOf(i));
yearTill.addItem(String.valueOf(i));
}
yearSince.setSelectedIndex(yearSince.getItemCount() - 2);
yearTill.setSelectedIndex(yearTill.getItemCount() - 1);
// PUT WIDGETS IN MENU
CustomButton backButton = TabMenu.getPredefinedButton(ButtonType.BACK, "Go back to start page - !! ALL UNSAVED CHANGES WILL BE LOST !!", new ClickHandler() {
public void onClick(ClickEvent event) {
importedPublications.clear();
hadError = false;
// go back to original state
state = State.START;
session.getTabManager().reloadTab(tab);
}
});
menu.addWidget(backButton);
menu.addWidget(importButton);
menu.addWidget(addAsAuthor);
menu.addWidget(searchButton);
menu.addWidget(namespace);
menu.addWidget(new HTML("<strong>Year between:</strong>"));
menu.addWidget(yearSince);
menu.addWidget(yearTill);
// GET TABLE
CellTable<Publication> table = find.getEmptyTable();
importButton.setEnabled(false);
JsonUtils.addTableManagedButton(find, table, importButton);
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel();
sp.add(table);
sp.addStyleName("perun-tableScrollPanel");
mainPanel.add(sp);
// resize perun table to correct size on screen
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(mainPanel);
}
Aggregations