use of com.google.gwt.core.client.JsArray in project rstudio by rstudio.
the class RemoteServerEventListener method doListen.
private void doListen() {
// abort if we are no longer running
if (!isListening_)
return;
// setup request callback (save reference for cancellation)
activeRequestCallback_ = new ServerRequestCallback<JsArray<ClientEvent>>() {
@Override
public void onResponseReceived(JsArray<ClientEvent> events) {
// keep watchdog appraised of successful receipt of events
watchdog_.notifyResponseReceived();
try {
// only processs events if we are still listening
if (isListening_ && (events != null)) {
for (int i = 0; i < events.length(); i++) {
// is dispatched
if (!isListening_)
return;
// disppatch event
ClientEvent event = events.get(i);
dispatchEvent(event);
lastEventId_ = event.getId();
}
}
}// listen() again after processing
catch (Throwable e) {
GWT.log("ERROR: Processing client events", e);
}
// listen for more events
listen();
}
@Override
public void onError(ServerError error) {
// stop listening for events
stop();
// if this was server unavailable then signal event and return
if (error.getCode() == ServerError.UNAVAILABLE) {
ServerUnavailableEvent event = new ServerUnavailableEvent();
server_.getEventBus().fireEvent(event);
return;
}
// result in our server getting hammered with requests)
if (listenErrorCount_++ <= 5) {
Timer startTimer = new Timer() {
@Override
public void run() {
// by some other means (e.g. ensureListening, etc)
if (!isListening_)
start();
}
};
startTimer.schedule(500);
} else // otherwise reset the listen error count and remain stopped
{
listenErrorCount_ = 0;
}
}
};
// retry handler (restart listener)
RetryHandler retryHandler = new RetryHandler() {
public void onRetry() {
// need to do a full restart to ensure that the existing
// activeRequest_ and activeRequestCallback_ are cleaned up
// and all state is reset correctly
restart();
}
public void onError(RpcError error) {
// error while attempting to recover, to be on the safe side
// we simply stop listening for events. if rather than stopping
// we restarted we would open ourselves up to a situation
// where we keep hitting the same error over and over again.
stop();
}
};
// send request
activeRequest_ = server_.getEvents(lastEventId_, activeRequestCallback_, retryHandler);
}
use of com.google.gwt.core.client.JsArray in project rstudio by rstudio.
the class SourceWindowManager method navigateToPath.
// this function implements the core of routing navigation requests among
// source windows; it does the following:
// 1. attempts to find a window open with the given path
// (which can be a physical file or e.g. a code browser)
// 2. if such a window is found, fires the given event to the window, or
// closes the window's instance of the tab (server mode w/tab stealing)
// 3. if such a window is not found, indicates as much
private NavigationResult navigateToPath(String path, CrossWindowEvent<?> event, boolean focus) {
// if this is the main window, check to see if we should route an event
// there instead
String sourceWindowId = getWindowIdOfDocPath(path);
if (isMainSourceWindow()) {
// if this is the main window but the doc is open in a satellite...
if (!StringUtil.isNullOrEmpty(sourceWindowId) && isSourceWindowOpen(sourceWindowId)) {
if (canActivateSourceWindows()) {
// in desktop mode (and IE) we can bring the appropriate window
// forward
fireEventToSourceWindow(sourceWindowId, event, focus);
return new NavigationResult(NavigationResult.RESULT_NAVIGATED);
} else {
// otherwise, move the tab over to this window by closing it in
// in its origin window
JsArray<SourceDocument> sourceDocs = getSourceDocs();
for (int i = 0; i < sourceDocs.length(); i++) {
if (sourceDocs.get(i).getPath() == path) {
assignSourceDocWindowId(sourceDocs.get(i).getId(), getSourceWindowId(), null);
fireEventToSourceWindow(sourceWindowId, new DocWindowChangedEvent(sourceDocs.get(i).getId(), sourceWindowId, null, sourceDocs.get(i).getCollabParams(), 0), true);
return new NavigationResult(NavigationResult.RESULT_RELOCATE, sourceDocs.get(i).getId());
}
}
}
}
} else if (sourceWindowId != null && sourceWindowId != getSourceWindowId()) {
if (canActivateSourceWindows()) {
// in desktop mode (and IE) we can just route to the main window
events_.fireEventToMainWindow(event);
// if the destination is the main window, raise it
if (sourceWindowId.isEmpty()) {
pSatellite_.get().focusMainWindow();
}
return new NavigationResult(NavigationResult.RESULT_NAVIGATED);
} else {
// otherwise, move the tab over to this window by closing it in
// in its origin window
JsArray<SourceDocument> sourceDocs = getSourceDocs();
for (int i = 0; i < sourceDocs.length(); i++) {
if (sourceDocs.get(i).getPath() == path) {
// take ownership of the doc immediately
assignSourceDocWindowId(sourceDocs.get(i).getId(), getSourceWindowId(), null);
events_.fireEventToMainWindow(new DocWindowChangedEvent(sourceDocs.get(i).getId(), sourceWindowId, null, sourceDocs.get(i).getCollabParams(), 0));
return new NavigationResult(NavigationResult.RESULT_RELOCATE, sourceDocs.get(i).getId());
}
}
}
}
return new NavigationResult(NavigationResult.RESULT_NONE);
}
use of com.google.gwt.core.client.JsArray in project rstudio by rstudio.
the class AceEditorWidget method removeMarkersOnCursorLine.
public void removeMarkersOnCursorLine() {
// Defer this so other event handling can update anchors etc.
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
int cursorRow = editor_.getCursorPosition().getRow();
JsArray<AceAnnotation> newAnnotations = JsArray.createArray().cast();
for (int i = 0; i < annotations_.size(); i++) {
AnchoredAceAnnotation annotation = annotations_.get(i);
int markerId = annotation.getMarkerId();
Marker marker = editor_.getSession().getMarker(markerId);
// a previous action.
if (marker == null)
continue;
Range range = marker.getRange();
int rowStart = range.getStart().getRow();
int rowEnd = range.getEnd().getRow();
if (cursorRow >= rowStart && cursorRow <= rowEnd)
editor_.getSession().removeMarker(markerId);
else
newAnnotations.push(annotation.asAceAnnotation());
}
editor_.getSession().setAnnotations(newAnnotations);
editor_.getRenderer().renderMarkers();
}
});
}
use of com.google.gwt.core.client.JsArray in project rstudio by rstudio.
the class TextEditingTarget method updateRmdFormatList.
private void updateRmdFormatList() {
String formatUiName = "";
List<String> formatList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
List<String> extensionList = new ArrayList<String>();
RmdSelectedTemplate selTemplate = getSelectedTemplate();
if (selTemplate != null && selTemplate.isShiny) {
view_.setIsShinyFormat(selTemplate.format != null, selTemplate.format != null && selTemplate.format.endsWith(RmdOutputFormat.OUTPUT_PRESENTATION_SUFFIX), isShinyPrerenderedDoc());
} else // could be runtime: shiny with a custom format
if (isShinyDoc()) {
// no output options b/c no template
view_.setIsShinyFormat(// no output options b/c no template
false, // not a presentation (unknown format)
false, isShinyPrerenderedDoc());
} else {
view_.setIsNotShinyFormat();
if (selTemplate != null) {
JsArray<RmdTemplateFormat> formats = selTemplate.template.getFormats();
for (int i = 0; i < formats.length(); i++) {
// skip notebook format (will enable it later if discovered)
if (formats.get(i).getName() == RmdOutputFormat.OUTPUT_HTML_NOTEBOOK) {
continue;
}
String uiName = formats.get(i).getUiName();
formatList.add(uiName);
valueList.add(formats.get(i).getName());
extensionList.add(formats.get(i).getExtension());
if (formats.get(i).getName().equals(selTemplate.format)) {
formatUiName = uiName;
}
}
}
// add formats not in the selected template
boolean isNotebook = false;
List<String> outputFormats = getOutputFormats();
for (int i = 0; i < outputFormats.size(); i++) {
String format = outputFormats.get(i);
if (format == RmdOutputFormat.OUTPUT_HTML_NOTEBOOK) {
if (i == 0)
isNotebook = true;
formatList.add(0, "Notebook");
valueList.add(0, format);
extensionList.add(0, ".nb.html");
continue;
}
if (!valueList.contains(format)) {
String uiName = format;
int nsLoc = uiName.indexOf("::");
if (nsLoc != -1)
uiName = uiName.substring(nsLoc + 2);
formatList.add(uiName);
valueList.add(format);
extensionList.add(null);
}
}
view_.setFormatOptions(fileType_, // can choose output formats
getCustomKnit().length() == 0, // can edit format options
selTemplate != null, formatList, valueList, extensionList, formatUiName);
// update notebook-specific options
if (isNotebook) {
// if the user manually set the output to console in a notebook,
// respect that (even though it's weird)
String outputType = RmdEditorOptions.getString(YamlFrontMatter.getFrontMatter(docDisplay_), TextEditingTargetNotebook.CHUNK_OUTPUT_TYPE, null);
if (outputType != TextEditingTargetNotebook.CHUNK_OUTPUT_CONSOLE) {
// chunk output should always be inline in notebooks
outputType = docUpdateSentinel_.getProperty(TextEditingTargetNotebook.CHUNK_OUTPUT_TYPE);
if (outputType != TextEditingTargetNotebook.CHUNK_OUTPUT_INLINE) {
docUpdateSentinel_.setProperty(TextEditingTargetNotebook.CHUNK_OUTPUT_TYPE, TextEditingTargetNotebook.CHUNK_OUTPUT_INLINE);
}
}
view_.setIsNotebookFormat();
}
}
if (isShinyDoc()) {
// turn off inline output in Shiny documents (if it's not already)
if (docDisplay_.showChunkOutputInline())
docDisplay_.setShowChunkOutputInline(false);
}
}
use of com.google.gwt.core.client.JsArray in project perun by CESNET.
the class FindPublicationsByGUIFilter method getEmptyTable.
/**
* Returns table of users publications
* @return
*/
public CellTable<Publication> getEmptyTable() {
// Table data provider.
dataProvider = new ListDataProvider<Publication>(list);
// Cell table
table = new PerunTable<Publication>(list);
// display row-count for perun admin only
if (!session.isPerunAdmin()) {
table.removeRowCountChangeHandler();
}
// Connect the table to the data provider.
dataProvider.addDataDisplay(table);
// Sorting
ListHandler<Publication> columnSortHandler = new ListHandler<Publication>(dataProvider.getList());
table.addColumnSortHandler(columnSortHandler);
// table selection
table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<Publication>createCheckboxManager());
// set empty content & loader
table.setEmptyTableWidget(loaderImage);
loaderImage.setEmptyResultMessage("No publications found. Try to change filtering options.");
// show checkbox column
if (this.checkable) {
table.addCheckBoxColumn();
}
// ID COLUMN
table.addIdColumn("Publication ID", tableFieldUpdater, 60);
Column<Publication, ImageResource> lockedColumn = new Column<Publication, ImageResource>(new CustomImageResourceCell("click")) {
public ImageResource getValue(Publication object) {
if (object.getLocked() == true) {
return SmallIcons.INSTANCE.lockIcon();
} else {
return SmallIcons.INSTANCE.lockOpenIcon();
}
}
public void onBrowserEvent(final Context context, final Element elem, final Publication object, NativeEvent event) {
// on click and for perun admin
if ("click".equals(event.getType()) && session.isPerunAdmin()) {
final ImageResource value;
if (object.getLocked() == true) {
value = SmallIcons.INSTANCE.lockOpenIcon();
object.setLocked(false);
} else {
value = SmallIcons.INSTANCE.lockIcon();
object.setLocked(true);
}
LockUnlockPublications request = new LockUnlockPublications(new JsonCallbackEvents() {
@Override
public void onLoadingStart() {
getCell().setValue(context, elem, SmallIcons.INSTANCE.updateIcon());
}
@Override
public void onFinished(JavaScriptObject jso) {
// change picture (object already changed)
getCell().setValue(context, elem, value);
}
@Override
public void onError(PerunError error) {
// on error switch object back
if (object.getLocked() == true) {
object.setLocked(false);
getCell().setValue(context, elem, SmallIcons.INSTANCE.lockOpenIcon());
} else {
object.setLocked(true);
getCell().setValue(context, elem, SmallIcons.INSTANCE.lockIcon());
}
}
});
// send request
ArrayList<Publication> list = new ArrayList<Publication>();
list.add(object);
request.lockUnlockPublications(object.getLocked(), list);
}
}
};
table.addColumn(lockedColumn, "Lock");
// TITLE COLUMN
Column<Publication, String> titleColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {
public String getValue(Publication object) {
return object.getTitle();
}
}, this.tableFieldUpdater);
titleColumn.setSortable(true);
columnSortHandler.setComparator(titleColumn, new PublicationComparator(PublicationComparator.Column.TITLE));
table.addColumn(titleColumn, "Title");
// if display authors
if (ids.containsKey("authors")) {
if ((Integer) ids.get("authors") == 1) {
// AUTHORS COLUMN
Column<Publication, String> authorColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {
public String getValue(Publication object) {
return object.getAuthorsFormatted();
}
}, this.tableFieldUpdater);
authorColumn.setSortable(true);
columnSortHandler.setComparator(authorColumn, new PublicationComparator(PublicationComparator.Column.AUTHORS));
table.addColumn(authorColumn, "Reported by");
}
}
// YEAR COLUMN
Column<Publication, String> yearColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {
public String getValue(Publication object) {
return String.valueOf(object.getYear());
}
}, this.tableFieldUpdater);
yearColumn.setSortable(true);
columnSortHandler.setComparator(yearColumn, new PublicationComparator(PublicationComparator.Column.YEAR));
table.addColumn(yearColumn, "Year");
// CATEGORY COLUMN
Column<Publication, String> categoryColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {
public String getValue(Publication object) {
return object.getCategoryName();
}
}, this.tableFieldUpdater);
categoryColumn.setSortable(true);
columnSortHandler.setComparator(categoryColumn, new PublicationComparator(PublicationComparator.Column.CATEGORY));
table.addColumn(categoryColumn, "Category");
// THANKS COLUMN
Column<Publication, String> thanksColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {
public String getValue(Publication object) {
String result = "";
JsArray<Thanks> thks = object.getThanks();
for (int i = 0; i < thks.length(); i++) {
result += thks.get(i).getOwnerName() + ", ";
}
if (result.length() >= 2) {
result = result.substring(0, result.length() - 2);
}
return result;
}
}, this.tableFieldUpdater);
thanksColumn.setSortable(true);
columnSortHandler.setComparator(thanksColumn, new PublicationComparator(PublicationComparator.Column.THANKS));
table.addColumn(thanksColumn, "Thanked to");
/*
* HIDE ISBN COLUMN FOR NOW
// ISBN COLUMN
Column<Publication, String> isbnColumn = JsonUtils.addColumn(
new CustomClickableTextCell(), "",
new JsonUtils.GetValue<Publication, String>() {
public String getValue(Publication object) {
return object.getIsbn();
}
}, this.tableFieldUpdater);
isbnColumn.setSortable(true);
columnSortHandler.setComparator(isbnColumn, new PublicationComparator(PublicationComparator.Column.ISBN));
table.addColumn(isbnColumn, "ISBN");
*/
// CITE COLUMN
Column<Publication, String> citaceColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {
public String getValue(Publication object) {
return "Cite";
}
}, new FieldUpdater<Publication, String>() {
public void update(int index, Publication object, String value) {
SimplePanel sp = new SimplePanel();
sp.add(new HTML(object.getMain()));
Confirm cf = new Confirm("Cite publication", sp, true);
cf.show();
}
;
});
table.addColumn(citaceColumn, "Cite");
return table;
}
Aggregations