Search in sources :

Example 1 with Node

use of elemental.dom.Node 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 2 with Node

use of elemental.dom.Node 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 3 with Node

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

Example 4 with Node

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

the class AnnotationGroupImpl method updateIconVisibility.

private void updateIconVisibility() {
    int maxLayer = 0;
    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 int layer = getLayer(dataset);
            if (maxLayer < layer) {
                maxLayer = layer;
            }
        }
    }
    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 int layer = getLayer(dataset);
            if (layer >= maxLayer) {
                element.getStyle().removeProperty("display");
            } else {
                element.getStyle().setDisplay("none");
            }
        }
    }
}
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)

Example 5 with Node

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

the class ProcessTreeRenderer method createMachineElement.

private SpanElement createMachineElement(final ProcessTreeNode node) {
    final MachineEntity machine = (MachineEntity) node.getData();
    final String machineId = machine.getId();
    final MachineConfig machineConfig = machine.getConfig();
    final String machineCategory = machineConfig.isDev() ? locale.devMachineCategory() : machineConfig.getType();
    SpanElement root = Elements.createSpanElement();
    root.appendChild(createMachineLabel(machineCategory));
    Element statusElement = Elements.createSpanElement(resources.getCss().machineStatus());
    root.appendChild(statusElement);
    if (node.isRunning()) {
        statusElement.appendChild(Elements.createDivElement(resources.getCss().machineStatusRunning()));
    } else {
        statusElement.appendChild(Elements.createDivElement(resources.getCss().machineStatusPausedLeft()));
        statusElement.appendChild(Elements.createDivElement(resources.getCss().machineStatusPausedRight()));
    }
    Tooltip.create(statusElement, BOTTOM, MIDDLE, locale.viewMachineRunningTooltip());
    /***************************************************************************
         *
         * New terminal button
         *
         ***************************************************************************/
    if (node.isRunning() && node.hasTerminalAgent()) {
        SpanElement newTerminalButton = Elements.createSpanElement(resources.getCss().newTerminalButton());
        newTerminalButton.appendChild((Node) new SVGImage(resources.addTerminalIcon()).getElement());
        root.appendChild(newTerminalButton);
        Tooltip.create(newTerminalButton, BOTTOM, MIDDLE, locale.viewNewTerminalTooltip());
        newTerminalButton.addEventListener(Event.CLICK, new EventListener() {

            @Override
            public void handleEvent(Event event) {
                event.stopPropagation();
                event.preventDefault();
                if (addTerminalClickHandler != null) {
                    addTerminalClickHandler.onAddTerminalClick(machineId);
                }
            }
        }, true);
        /**
             * This listener cancels mouse events on '+' button and prevents the jitter of the selection in the tree.
             */
        EventListener blockMouseListener = new EventListener() {

            @Override
            public void handleEvent(Event event) {
                event.stopPropagation();
                event.preventDefault();
            }
        };
        /**
             * Prevent jitter when pressing mouse on '+' button.
             */
        newTerminalButton.addEventListener(Event.MOUSEDOWN, blockMouseListener, true);
        newTerminalButton.addEventListener(Event.MOUSEUP, blockMouseListener, true);
        newTerminalButton.addEventListener(Event.CLICK, blockMouseListener, true);
        newTerminalButton.addEventListener(Event.DBLCLICK, blockMouseListener, true);
    }
    /***************************************************************************
         *
         * SSH button
         *
         ***************************************************************************/
    if (node.isRunning() && node.hasSSHAgent()) {
        SpanElement sshButton = Elements.createSpanElement(resources.getCss().sshButton());
        sshButton.setTextContent("SSH");
        root.appendChild(sshButton);
        sshButton.addEventListener(Event.CLICK, new EventListener() {

            @Override
            public void handleEvent(Event event) {
                if (previewSshClickHandler != null) {
                    previewSshClickHandler.onPreviewSshClick(machineId);
                }
            }
        }, true);
        Tooltip.create(sshButton, BOTTOM, MIDDLE, locale.connectViaSSH());
    }
    Element monitorsElement = Elements.createSpanElement(resources.getCss().machineMonitors());
    root.appendChild(monitorsElement);
    Node monitorNode = (Node) machineMonitors.getMonitorWidget(machineId, this).getElement();
    monitorsElement.appendChild(monitorNode);
    Element nameElement = Elements.createSpanElement(resources.getCss().nameLabel());
    nameElement.setTextContent(machineConfig.getName());
    Tooltip.create(nameElement, BOTTOM, MIDDLE, machineConfig.getName());
    root.appendChild(nameElement);
    return root;
}
Also used : MachineEntity(org.eclipse.che.ide.api.machine.MachineEntity) SpanElement(elemental.html.SpanElement) MachineConfig(org.eclipse.che.api.core.model.machine.MachineConfig) DivElement(elemental.html.DivElement) TreeNodeElement(org.eclipse.che.ide.ui.tree.TreeNodeElement) Element(elemental.dom.Element) SpanElement(elemental.html.SpanElement) Node(elemental.dom.Node) Event(elemental.events.Event) EventListener(elemental.events.EventListener) SVGImage(org.vectomatic.dom.svg.ui.SVGImage)

Aggregations

Element (elemental.dom.Element)7 Node (elemental.dom.Node)7 DivElement (elemental.html.DivElement)4 HTMLCollection (elemental.html.HTMLCollection)4 SpanElement (elemental.html.SpanElement)4 Event (elemental.events.Event)3 EventListener (elemental.events.EventListener)3 Mappable (elemental.util.Mappable)3 CustomEvent (elemental.events.CustomEvent)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 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 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)1