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;
}
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;
}
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;
}
}
}
}
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");
}
}
}
}
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;
}
Aggregations