本文整理了Java中com.vaadin.flow.dom.Element.getParentNode()
方法的一些代码示例,展示了Element.getParentNode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.getParentNode()
方法的具体详情如下:
包路径:com.vaadin.flow.dom.Element
类名称:Element
方法名:getParentNode
暂无
代码示例来源:origin: com.vaadin/flow-server
/**
* Gets the parent element.
* <p>
* The method may return {@code null} if the parent is not an element but a
* {@link Node}.
*
* @see #getParentNode()
*
* @return the parent element or null if this element does not have a parent
* or the parent is not an element
*/
public Element getParent() {
Node<?> parent = getParentNode();
if (parent instanceof Element) {
return (Element) parent;
}
return null;
}
代码示例来源:origin: com.vaadin/flow-server
/**
* Ensures that the {@code child} has the correct parent.
* <p>
* Default implementation doesn't do anything. Subclasses may override the
* method to implement their own behavior.
*
* @param child
* the element to check for its parent
* @param internalCheck
* whether to use assertions or throw an exception on failure
*/
protected void ensureChildHasParent(Element child, boolean internalCheck) {
if (!Objects.equals(this, child.getParentNode())) {
if (internalCheck) {
assert false : "Child should have this element as a parent";
} else {
throw new IllegalArgumentException(
"Child should have this element as a parent");
}
}
}
代码示例来源:origin: com.vaadin/flow-server
/**
* Removes this element from its parent.
* <p>
* Has no effect if the element does not have a parent
*
* @return this element
*/
public Element removeFromParent() {
Node<?> parent = getParentNode();
if (parent != null) {
parent.removeChild(this);
}
return this;
}
代码示例来源:origin: com.vaadin/flow-server
/**
* Gets the UI this component is attached to.
*
* @return an optional UI component, or an empty optional if this component
* is not attached to a UI
*/
public Optional<UI> getUI() {
Optional<Component> parent = getParent();
if (parent.isPresent()) {
return parent.flatMap(Component::getUI);
} else if (getElement().getParentNode() instanceof ShadowRoot) {
parent = ComponentUtil.findParentComponent(
((ShadowRoot) getElement().getParentNode()).getHost());
return parent.flatMap(Component::getUI);
}
return Optional.empty();
}
代码示例来源:origin: com.vaadin/flow-server
/**
* Returns the index of the specified {@code child} in the children list, or
* -1 if this list does not contain the {@code child}.
*
* @param child
* the child element
* @return index of the {@code child} or -1 if it's not a child
*/
public int indexOfChild(Element child) {
if (child == null) {
throw new IllegalArgumentException(
"Child parameter cannot be null");
}
if (!equals(child.getParentNode())) {
return -1;
}
for (int i = 0; i < getChildCount(); i++) {
Element element = getChild(i);
if (element.equals(child)) {
return i;
}
}
return -1;
}
代码示例来源:origin: com.vaadin/flow-server
"Element to insert must not be null");
Node<?> parentNode = child.getParentNode();
if (parentNode != null) {
throw new IllegalArgumentException(
代码示例来源:origin: com.vaadin/flow-server
"Element to insert must not be null");
if (equals(child.getParentNode())) {
int childIndex = indexOfChild(child);
if (childIndex == insertIndex) {
代码示例来源:origin: com.vaadin/incubator-tooltip-flow
/**
* Assigns the tooltip to a specific component.
* <p>
* The tooltip is removed from the parent after the component that the tooltip is
* attached is detached.
*
* @param component the tooltip is attached to this component
* @param appended <code>true</code> the tooltip is automatically appended
* to the component's father.<code>false</code>,
* it is not appended. It should be added to a layout manually.
*/
public void attachToComponent(Component component, boolean appended) {
Objects.requireNonNull(component);
getElement().getNode().runWhenAttached(ui -> {
ui.getPage().executeJavaScript("$0.targetElement = $1;",
getElement(), component.getElement()
);
});
if ( appended ){
component.getElement().getNode().runWhenAttached(ui -> {
component.getElement().getParentNode().appendChild(getElement());
});
}
if ( detachedRegistration != null ){
detachedRegistration.remove();
}
detachedRegistration = component.addDetachListener(event -> {
this.getElement().removeFromParent();
});
}
内容来源于网络,如有侵权,请联系作者删除!