use of elemental.events.Event in project che by eclipse.
the class ContentAssistWidget method createProposalPopupItem.
/**
* Creates a new proposal item.
*
* @param index
* of proposal
*/
private Element createProposalPopupItem(int index) {
final CompletionProposal proposal = proposals.get(index);
final Element element = Elements.createLiElement(popupResources.popupStyle().item());
element.setId(Integer.toString(index));
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);
element.setTabIndex(1);
final EventListener validateListener = evt -> applyProposal(proposal);
element.addEventListener(Event.DBLCLICK, validateListener, false);
element.addEventListener(CUSTOM_EVT_TYPE_VALIDATE, validateListener, false);
element.addEventListener(Event.CLICK, event -> select(element), false);
element.addEventListener(Event.FOCUS, this, false);
element.addEventListener(DOCUMENTATION, new EventListener() {
@Override
public void handleEvent(Event event) {
proposal.getAdditionalProposalInfo(new AsyncCallback<Widget>() {
@Override
public void onSuccess(Widget info) {
if (info != null) {
docPopup.clear();
docPopup.add(info);
docPopup.getElement().getStyle().setOpacity(1);
if (!docPopup.isAttached()) {
final int x = popupElement.getOffsetLeft() + popupElement.getOffsetWidth() + 3;
final int y = popupElement.getOffsetTop();
RootPanel.get().add(docPopup);
updateMenuPosition(docPopup, x, y);
}
} else {
docPopup.getElement().getStyle().setOpacity(0);
}
}
@Override
public void onFailure(Throwable e) {
Log.error(getClass(), e);
docPopup.getElement().getStyle().setOpacity(0);
}
});
}
}, false);
return element;
}
Aggregations