Search in sources :

Example 1 with EventListener

use of elemental.events.EventListener in project che by eclipse.

the class ClassFileSourcesDownloader method onEditorOpened.

@Override
public void onEditorOpened(EditorOpenedEvent event) {
    EditorPartPresenter editor = event.getEditor();
    VirtualFile file = editor.getEditorInput().getFile();
    if (file instanceof JarFileNode) {
        final JarFileNode jarFileNode = (JarFileNode) file;
        if (jarFileNode.isContentGenerated()) {
            if (editor instanceof TextEditor) {
                final TextEditor presenter = (TextEditor) editor;
                TextEditorPartView view = presenter.getView();
                final DivElement divElement = Elements.createDivElement();
                divElement.setClassName(resources.css().editorInfoPanel());
                Text textNode = Elements.createTextNode(constant.mavenClassDecompiled());
                DivElement decompiledElement = Elements.createDivElement();
                decompiledElement.appendChild(textNode);
                decompiledElement.setClassName(resources.css().editorMessage());
                divElement.appendChild(decompiledElement);
                AnchorElement anchorElement = Elements.createAnchorElement();
                anchorElement.appendChild(Elements.createTextNode(constant.mavenDownloadSources()));
                anchorElement.setHref("#");
                anchorElement.setClassName(resources.css().downloadLink());
                divElement.appendChild(anchorElement);
                final HasNotificationPanel.NotificationRemover remover = view.addNotification((Element) divElement);
                anchorElement.setOnclick(new EventListener() {

                    @Override
                    public void handleEvent(Event evt) {
                        downloadSources(jarFileNode, remover);
                    }
                });
            }
        }
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) AnchorElement(elemental.html.AnchorElement) Text(elemental.dom.Text) HasNotificationPanel(org.eclipse.che.ide.api.editor.texteditor.HasNotificationPanel) JarFileNode(org.eclipse.che.ide.ext.java.client.tree.library.JarFileNode) TextEditorPartView(org.eclipse.che.ide.api.editor.texteditor.TextEditorPartView) DivElement(elemental.html.DivElement) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) EditorOpenedEvent(org.eclipse.che.ide.api.editor.EditorOpenedEvent) Event(elemental.events.Event) FileContentUpdateEvent(org.eclipse.che.ide.api.event.FileContentUpdateEvent) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) EventListener(elemental.events.EventListener)

Example 2 with EventListener

use of elemental.events.EventListener in project che by eclipse.

the class QuickAssistWidget method createItem.

public Element createItem(final CompletionProposal proposal) {
    final Element element = Elements.createLiElement(popupResources.popupStyle().item());
    final Element icon = Elements.createDivElement(popupResources.popupStyle().icon());
    if (proposal.getIcon() != null && proposal.getIcon().getSVGImage() != null) {
        icon.appendChild((Node) proposal.getIcon().getSVGImage().getElement());
    } else if (proposal.getIcon() != null && proposal.getIcon().getImage() != null) {
        icon.appendChild((Node) proposal.getIcon().getImage().getElement());
    }
    element.appendChild(icon);
    final SpanElement label = Elements.createSpanElement(popupResources.popupStyle().label());
    label.setInnerHTML(proposal.getDisplayString());
    element.appendChild(label);
    final EventListener validateListener = new EventListener() {

        @Override
        public void handleEvent(final Event evt) {
            proposal.getCompletion(new CompletionProposal.CompletionCallback() {

                @Override
                public void onCompletion(final Completion completion) {
                    HandlesUndoRedo undoRedo = null;
                    if (textEditor instanceof UndoableEditor) {
                        UndoableEditor undoableEditor = (UndoableEditor) QuickAssistWidget.this.textEditor;
                        undoRedo = undoableEditor.getUndoRedo();
                    }
                    try {
                        if (undoRedo != null) {
                            undoRedo.beginCompoundChange();
                        }
                        completion.apply(textEditor.getDocument());
                        final LinearRange selection = completion.getSelection(textEditor.getDocument());
                        if (selection != null) {
                            textEditor.getDocument().setSelectedRange(selection, true);
                        }
                    } catch (final Exception e) {
                        Log.error(getClass(), e);
                    } finally {
                        if (undoRedo != null) {
                            undoRedo.endCompoundChange();
                        }
                    }
                }
            });
            hide();
        }
    };
    element.addEventListener(Event.DBLCLICK, validateListener, false);
    element.addEventListener(CUSTOM_EVT_TYPE_VALIDATE, validateListener, false);
    return element;
}
Also used : SpanElement(elemental.html.SpanElement) UndoableEditor(org.eclipse.che.ide.api.editor.texteditor.UndoableEditor) LinearRange(org.eclipse.che.ide.api.editor.text.LinearRange) CompletionProposal(org.eclipse.che.ide.api.editor.codeassist.CompletionProposal) Element(elemental.dom.Element) SpanElement(elemental.html.SpanElement) Node(elemental.dom.Node) HandlesUndoRedo(org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo) Completion(org.eclipse.che.ide.api.editor.codeassist.Completion) Event(elemental.events.Event) CustomEvent(elemental.events.CustomEvent) EventListener(elemental.events.EventListener)

Example 3 with EventListener

use of elemental.events.EventListener in project che by eclipse.

the class ProcessTreeRenderer method createCloseElement.

private SpanElement createCloseElement(final ProcessTreeNode node) {
    SpanElement closeButton = Elements.createSpanElement(resources.getCss().processesPanelCloseButtonForProcess());
    SVGImage icon = new SVGImage(partStackUIResources.closeIcon());
    closeButton.appendChild((Node) icon.getElement());
    Tooltip.create(closeButton, BOTTOM, MIDDLE, locale.viewCloseProcessOutputTooltip());
    closeButton.addEventListener(Event.CLICK, new EventListener() {

        @Override
        public void handleEvent(Event event) {
            if (stopProcessHandler != null) {
                stopProcessHandler.onCloseProcessOutputClick(node);
            }
        }
    }, true);
    return closeButton;
}
Also used : SpanElement(elemental.html.SpanElement) Event(elemental.events.Event) EventListener(elemental.events.EventListener) SVGImage(org.vectomatic.dom.svg.ui.SVGImage)

Example 4 with EventListener

use of elemental.events.EventListener in project che by eclipse.

the class ProcessTreeRenderer method createStopProcessElement.

private SpanElement createStopProcessElement(final ProcessTreeNode node) {
    SpanElement stopProcessButton = Elements.createSpanElement(resources.getCss().processesPanelStopButtonForProcess());
    Tooltip.create(stopProcessButton, BOTTOM, MIDDLE, locale.viewStropProcessTooltip());
    stopProcessButton.addEventListener(Event.CLICK, new EventListener() {

        @Override
        public void handleEvent(Event event) {
            if (stopProcessHandler != null) {
                stopProcessHandler.onStopProcessClick(node);
            }
        }
    }, true);
    return stopProcessButton;
}
Also used : SpanElement(elemental.html.SpanElement) Event(elemental.events.Event) EventListener(elemental.events.EventListener)

Example 5 with EventListener

use of elemental.events.EventListener in project che by eclipse.

the class Tooltip method attachToTargetElement.

/**
     * Adds event handlers to the target element for the tooltip to show it on
     * hover, and update position on mouse move.
     */
private List<EventRemover> attachToTargetElement() {
    List<EventRemover> removers = new ArrayList<>();
    for (int i = 0; i < targetElements.size(); i++) {
        final Element targetElement = targetElements.get(i);
        addPartner(targetElement);
        removers.add(targetElement.addEventListener(Event.MOUSEOUT, new EventListener() {

            @Override
            public void handleEvent(Event evt) {
                MouseEvent mouseEvt = (MouseEvent) evt;
                EventTarget relatedTarget = mouseEvt.getRelatedTarget();
                // Ignore the event unless we mouse completely out of the target element.
                if (relatedTarget == null || !targetElement.contains((Node) relatedTarget)) {
                    cancelPendingShow();
                }
            }
        }, false));
        removers.add(targetElement.addEventListener(Event.MOUSEDOWN, new EventListener() {

            @Override
            public void handleEvent(Event evt) {
                cancelPendingShow();
                hide();
            }
        }, false));
    }
    return removers;
}
Also used : MouseEvent(elemental.events.MouseEvent) EventRemover(elemental.events.EventRemover) Element(elemental.dom.Element) ArrayList(java.util.ArrayList) Event(elemental.events.Event) MouseEvent(elemental.events.MouseEvent) EventListener(elemental.events.EventListener) EventTarget(elemental.events.EventTarget)

Aggregations

Event (elemental.events.Event)11 EventListener (elemental.events.EventListener)11 Element (elemental.dom.Element)8 SpanElement (elemental.html.SpanElement)7 Node (elemental.dom.Node)3 CustomEvent (elemental.events.CustomEvent)3 SVGImage (org.vectomatic.dom.svg.ui.SVGImage)3 EventTarget (elemental.events.EventTarget)2 MouseEvent (elemental.events.MouseEvent)2 DivElement (elemental.html.DivElement)2 Completion (org.eclipse.che.ide.api.editor.codeassist.Completion)2 CompletionProposal (org.eclipse.che.ide.api.editor.codeassist.CompletionProposal)2 LinearRange (org.eclipse.che.ide.api.editor.text.LinearRange)2 HandlesUndoRedo (org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo)2 UndoableEditor (org.eclipse.che.ide.api.editor.texteditor.UndoableEditor)2 Scheduler (com.google.gwt.core.client.Scheduler)1 DivElement (com.google.gwt.dom.client.DivElement)1 Style (com.google.gwt.dom.client.Style)1 KeyCodes (com.google.gwt.event.dom.client.KeyCodes)1 Timer (com.google.gwt.user.client.Timer)1