Search in sources :

Example 16 with Element

use of elemental.dom.Element 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 17 with Element

use of elemental.dom.Element in project che by eclipse.

the class EmptyEditorsPanel method render.

private void render(String title, Map<String, Action> actions) {
    this.title.setInnerText(title);
    container.removeAllChildren();
    Element listElement = Elements.createElement("ul", new String[] { style.list() });
    for (Map.Entry<String, Action> pair : actions.entrySet()) {
        LIElement liElement = Elements.createLiElement();
        liElement.appendChild(renderAction(pair.getKey(), pair.getValue()));
        listElement.appendChild(liElement);
    }
    container.appendChild((com.google.gwt.dom.client.Node) listElement);
}
Also used : CreateProjectAction(org.eclipse.che.ide.actions.CreateProjectAction) ImportProjectAction(org.eclipse.che.ide.actions.ImportProjectAction) Action(org.eclipse.che.ide.api.action.Action) NewFileAction(org.eclipse.che.ide.newresource.NewFileAction) Element(elemental.dom.Element) DivElement(com.google.gwt.dom.client.DivElement) LIElement(elemental.html.LIElement) SpanElement(elemental.html.SpanElement) HashMap(java.util.HashMap) Map(java.util.Map) LIElement(elemental.html.LIElement)

Example 18 with Element

use of elemental.dom.Element 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)

Example 19 with Element

use of elemental.dom.Element in project che by eclipse.

the class AnnotationGroupImpl method getMessages.

@Override
public List<String> getMessages() {
    final List<String> result = new ArrayList<>();
    final HTMLCollection children = asElemental().getChildren();
    for (int i = 0; i < children.length(); i++) {
        final Node child = (Node) children.at(i);
        if (child instanceof elemental.dom.Element) {
            final elemental.dom.Element element = (elemental.dom.Element) child;
            final Mappable dataset = element.getDataset();
            final String message = getMessage(dataset);
            if (message != null) {
                result.add(message);
            }
        }
    }
    return result;
}
Also used : HTMLCollection(elemental.html.HTMLCollection) Mappable(elemental.util.Mappable) Node(elemental.dom.Node) DivElement(elemental.html.DivElement) Element(elemental.dom.Element) ArrayList(java.util.ArrayList) Element(elemental.dom.Element)

Example 20 with Element

use of elemental.dom.Element in project che by eclipse.

the class AnnotationGroupImpl method removeAnnotation.

@Override
public final void removeAnnotation(final Annotation annotation, int offset) {
    final HTMLCollection children = asElemental().getChildren();
    for (int i = 0; i < children.length(); i++) {
        final Node child = (Node) children.at(i);
        if (child instanceof elemental.dom.Element) {
            final elemental.dom.Element element = (elemental.dom.Element) child;
            final Mappable dataset = element.getDataset();
            if (compareStrings(getMessage(dataset), annotation.getText()) && getOffset(dataset) == offset && getLayer(dataset) == annotation.getLayer() && compareStrings(getType(dataset), annotation.getType())) {
                // we may not strictly be on the same annotation instance, but it is not discernible
                asElemental().removeChild(element);
                updateIconVisibility();
                break;
            }
        }
    }
}
Also used : HTMLCollection(elemental.html.HTMLCollection) Mappable(elemental.util.Mappable) Node(elemental.dom.Node) DivElement(elemental.html.DivElement) Element(elemental.dom.Element) Element(elemental.dom.Element)

Aggregations

Element (elemental.dom.Element)48 SpanElement (elemental.html.SpanElement)23 DivElement (elemental.html.DivElement)15 JsElement (elemental.js.dom.JsElement)11 Event (elemental.events.Event)8 EventListener (elemental.events.EventListener)8 Node (elemental.dom.Node)7 HTMLCollection (elemental.html.HTMLCollection)5 LIElement (elemental.html.LIElement)5 TableCellElement (elemental.html.TableCellElement)5 TableElement (elemental.html.TableElement)5 InputElement (elemental.html.InputElement)4 JsLIElement (elemental.js.html.JsLIElement)4 JsUListElement (elemental.js.html.JsUListElement)4 TreeNodeElement (org.eclipse.che.ide.ui.tree.TreeNodeElement)4 SVGImage (org.vectomatic.dom.svg.ui.SVGImage)4 Scheduler (com.google.gwt.core.client.Scheduler)3 CustomEvent (elemental.events.CustomEvent)3 AnchorElement (elemental.html.AnchorElement)3 BRElement (elemental.html.BRElement)3