Search in sources :

Example 16 with HandlerRegistration

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();
        }
    };
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) EntitySuggestion(edu.stanford.bmir.protege.web.client.library.suggest.EntitySuggestion) EntitySuggestion(edu.stanford.bmir.protege.web.client.library.suggest.EntitySuggestion)

Example 17 with HandlerRegistration

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);
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) PostLoadEvent(org.eclipse.che.ide.ui.smartTree.event.PostLoadEvent) Node(org.eclipse.che.ide.api.data.tree.Node) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode) PostLoadHandler(org.eclipse.che.ide.ui.smartTree.event.PostLoadEvent.PostLoadHandler) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode)

Example 18 with HandlerRegistration

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();
        }
    };
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 19 with HandlerRegistration

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);
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) InputEditorPosition(org.rstudio.studio.client.workbench.views.console.shell.editor.InputEditorPosition) SourcePosition(org.rstudio.studio.client.workbench.views.source.model.SourcePosition) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CommandWithArg(org.rstudio.core.client.CommandWithArg)

Example 20 with HandlerRegistration

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);
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) PopupPanel(com.google.gwt.user.client.ui.PopupPanel) CursorChangedEvent(org.rstudio.studio.client.workbench.views.source.editors.text.events.CursorChangedEvent) ChunkInlineOutput(org.rstudio.studio.client.workbench.views.source.editors.text.ChunkInlineOutput) Mutable(org.rstudio.core.client.Mutable) Scope(org.rstudio.studio.client.workbench.views.source.editors.text.Scope) CursorChangedHandler(org.rstudio.studio.client.workbench.views.source.editors.text.events.CursorChangedHandler) SendToChunkConsoleEvent(org.rstudio.studio.client.rmarkdown.events.SendToChunkConsoleEvent)

Aggregations

HandlerRegistration (com.google.gwt.event.shared.HandlerRegistration)48 Test (org.junit.Test)7 MouseEvent (com.google.gwt.event.dom.client.MouseEvent)4 ViewEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.ViewEvent)4 NodeMouseEnterEvent (com.ait.lienzo.client.core.event.NodeMouseEnterEvent)2 NodeMouseEnterHandler (com.ait.lienzo.client.core.event.NodeMouseEnterHandler)2 NodeMouseExitEvent (com.ait.lienzo.client.core.event.NodeMouseExitEvent)2 NodeMouseExitHandler (com.ait.lienzo.client.core.event.NodeMouseExitHandler)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 Widget (com.google.gwt.user.client.ui.Widget)2 Map (java.util.Map)2 MouseDoubleClickEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseDoubleClickEvent)2 MouseEnterEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseEnterEvent)2 CommandWithArg (org.rstudio.core.client.CommandWithArg)2 Mutable (org.rstudio.core.client.Mutable)2 Attribute (com.ait.lienzo.client.core.Attribute)1 AbstractNodeGestureEvent (com.ait.lienzo.client.core.event.AbstractNodeGestureEvent)1 NodeGestureChangeEvent (com.ait.lienzo.client.core.event.NodeGestureChangeEvent)1 NodeGestureChangeHandler (com.ait.lienzo.client.core.event.NodeGestureChangeHandler)1