use of com.google.gwt.event.shared.HandlerRegistration in project webprotege by protegeproject.
the class PrimitiveDataEditorViewImpl method addSelectionHandler.
@Override
public HandlerRegistration addSelectionHandler(final SelectionHandler<EntitySuggestion> handler) {
final HandlerRegistration handlerReg = addHandler(handler, SelectionEvent.getType());
final HandlerRegistration delegateReg = textBox.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() {
@Override
public void onSelection(SelectionEvent<SuggestOracle.Suggestion> event) {
SuggestOracle.Suggestion suggestion = event.getSelectedItem();
if (suggestion instanceof EntitySuggestion) {
SelectionEvent.fire(PrimitiveDataEditorViewImpl.this, (EntitySuggestion) suggestion);
}
}
});
return new HandlerRegistration() {
@Override
public void removeHandler() {
handlerReg.removeHandler();
delegateReg.removeHandler();
}
};
}
use of com.google.gwt.event.shared.HandlerRegistration in project che by eclipse.
the class TreeResourceRevealer method expand.
protected void expand(final ResourceNode parent, final Path segment, final boolean select, final AsyncCallback<ResourceNode> callback) {
if (parent.getData().getLocation().equals(segment)) {
if (select) {
if (toSelect == null) {
toSelect = new Node[] { parent };
} else {
final int index = toSelect.length;
toSelect = copyOf(toSelect, index + 1);
toSelect[index] = parent;
}
selectTask.delay(200);
}
callback.onSuccess(parent);
return;
}
final HandlerRegistration[] handler = new HandlerRegistration[1];
handler[0] = tree.getNodeLoader().addPostLoadHandler(new PostLoadHandler() {
@Override
public void onPostLoad(PostLoadEvent event) {
if (!event.getRequestedNode().equals(parent)) {
return;
}
if (handler[0] != null) {
handler[0].removeHandler();
}
final List<Node> children = tree.getNodeStorage().getChildren(event.getRequestedNode());
for (Node child : children) {
if (child instanceof ResourceNode && ((ResourceNode) child).getData().getLocation().isPrefixOf(segment)) {
expand((ResourceNode) child, segment, select, callback);
return;
}
}
callback.onFailure(new IllegalStateException("Not found"));
}
});
tree.getNodeLoader().loadChildren(parent);
}
use of com.google.gwt.event.shared.HandlerRegistration in project rstudio by rstudio.
the class InlineToolbarButton method addClickHandler.
@Override
public HandlerRegistration addClickHandler(ClickHandler clickHandler) {
/*
* When we directly subscribe to this widget's ClickEvent, sometimes the
* click gets ignored (inconsistent repro but it happens enough to be
* annoying). Doing it this way fixes it.
*/
hasHandlers_.addHandler(ClickEvent.getType(), clickHandler);
final HandlerRegistration mouseDown = addDomHandler(new MouseDownHandler() {
public void onMouseDown(MouseDownEvent event) {
event.preventDefault();
event.stopPropagation();
down_ = true;
}
}, MouseDownEvent.getType());
final HandlerRegistration mouseOut = addDomHandler(new MouseOutHandler() {
public void onMouseOut(MouseOutEvent event) {
event.preventDefault();
event.stopPropagation();
down_ = false;
}
}, MouseOutEvent.getType());
final HandlerRegistration mouseUp = addDomHandler(new MouseUpHandler() {
public void onMouseUp(MouseUpEvent event) {
event.preventDefault();
event.stopPropagation();
if (down_) {
down_ = false;
NativeEvent clickEvent = Document.get().createClickEvent(1, event.getScreenX(), event.getScreenY(), event.getClientX(), event.getClientY(), event.getNativeEvent().getCtrlKey(), event.getNativeEvent().getAltKey(), event.getNativeEvent().getShiftKey(), event.getNativeEvent().getMetaKey());
DomEvent.fireNativeEvent(clickEvent, hasHandlers_);
}
}
}, MouseUpEvent.getType());
return new HandlerRegistration() {
public void removeHandler() {
mouseDown.removeHandler();
mouseOut.removeHandler();
mouseUp.removeHandler();
}
};
}
use of com.google.gwt.event.shared.HandlerRegistration in project rstudio by rstudio.
the class AceEditor method updateKeyboardHandlers.
private void updateKeyboardHandlers() {
// clear out existing editor handlers (they will be refreshed if necessary)
for (HandlerRegistration handler : editorEventListeners_) if (handler != null)
handler.removeHandler();
editorEventListeners_.clear();
// save and restore Vim marks as they can be lost when refreshing
// the keyboard handlers. this is necessary as keyboard handlers are
// regenerated on each document save, and clearing the Vim handler will
// clear any local Vim state.
JsMap<Position> marks = JsMap.create().cast();
if (useVimMode_)
marks = widget_.getEditor().getMarks();
// create a keyboard previewer for our special hooks
AceKeyboardPreviewer previewer = new AceKeyboardPreviewer(completionManager_);
// set default key handler
if (useVimMode_)
widget_.getEditor().setKeyboardHandler(KeyboardHandler.vim());
else if (useEmacsKeybindings_)
widget_.getEditor().setKeyboardHandler(KeyboardHandler.emacs());
else
widget_.getEditor().setKeyboardHandler(null);
// add the previewer
widget_.getEditor().addKeyboardHandler(previewer.getKeyboardHandler());
// Listen for command execution
editorEventListeners_.add(AceEditorNative.addEventListener(widget_.getEditor().getCommandManager(), "afterExec", new CommandWithArg<JavaScriptObject>() {
@Override
public void execute(JavaScriptObject event) {
events_.fireEvent(new AceAfterCommandExecutedEvent(event));
}
}));
// Listen for keyboard activity
editorEventListeners_.add(AceEditorNative.addEventListener(widget_.getEditor(), "keyboardActivity", new CommandWithArg<JavaScriptObject>() {
@Override
public void execute(JavaScriptObject event) {
events_.fireEvent(new AceKeyboardActivityEvent(event));
}
}));
if (useVimMode_)
widget_.getEditor().setMarks(marks);
}
use of com.google.gwt.event.shared.HandlerRegistration in project rstudio by rstudio.
the class EditingTargetInlineChunkExecution method execute.
public void execute(Range range) {
// synthesize an identifier for this chunk execution
final String chunkId = "i" + StringUtil.makeRandomId(12);
// are, remove it to make way for the new one
for (ChunkInlineOutput output : outputs_.values()) {
if (output.range().isEqualTo(range)) {
if (output.state() == ChunkInlineOutput.State.Finished) {
// remove old, completed output for this input
output.hide();
outputs_.remove(output.chunkId());
} else {
// unintended duplicate.
return;
}
}
}
// create dummy scope for execution
Scope scope = Scope.createRScopeNode(chunkId, range.getStart(), range.getEnd(), Scope.SCOPE_TYPE_CHUNK);
// create popup panel to host output
final ChunkInlineOutput output = new ChunkInlineOutput(chunkId, display_.createAnchoredSelection(range.getStart(), range.getEnd()));
// auto dismiss the panel when the cursor leaves the inline chunk
final Mutable<HandlerRegistration> cursorHandler = new Mutable<HandlerRegistration>();
cursorHandler.set(display_.addCursorChangedHandler(new CursorChangedHandler() {
@Override
public void onCursorChanged(CursorChangedEvent event) {
Position position = event.getPosition();
if (!output.range().contains(position)) {
output.hide();
}
}
}));
// when the popup is dismissed, clean up local state
output.addCloseHandler(new CloseHandler<PopupPanel>() {
@Override
public void onClose(CloseEvent<PopupPanel> event) {
outputs_.remove(chunkId);
cursorHandler.get().removeHandler();
}
});
// render offscreen until complete
output.setPopupPosition(-100000, -100000);
output.show();
outputs_.put(chunkId, output);
SendToChunkConsoleEvent event = new SendToChunkConsoleEvent(docId_, scope, range, NotebookQueueUnit.EXEC_SCOPE_INLINE);
events_.fireEvent(event);
}
Aggregations