本文整理了Java中com.vaadin.flow.dom.Element.getParent()
方法的一些代码示例,展示了Element.getParent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.getParent()
方法的具体详情如下:
包路径:com.vaadin.flow.dom.Element
类名称:Element
方法名:getParent
[英]Gets the parent element.
The method may return null if the parent is not an element but a Node.
[中]获取父元素。
如果父对象不是元素而是节点,则该方法可能返回null。
代码示例来源:origin: com.vaadin/flow-server
/**
* Finds the first component by traversing upwards in the element hierarchy,
* starting from the given element.
*
* @param element
* the element from which to begin the search
* @return optional of the component, empty if no component is found
*/
public static Optional<Component> findParentComponent(Element element) {
Element mappedElement = element;
while (mappedElement != null
&& !mappedElement.getComponent().isPresent()) {
mappedElement = mappedElement.getParent();
}
if (mappedElement == null) {
return Optional.empty();
}
return Optional.of(getInnermostComponent(mappedElement));
}
代码示例来源:origin: com.vaadin/vaadin-notification-flow
/**
* Remove the given components from this notification.
*
* @param components
* the components to remove
*/
@Override
public void remove(Component... components) {
for (Component component : components) {
Objects.requireNonNull(component,
"Component to remove cannot be null");
if (container.equals(component.getElement().getParent())) {
container.removeChild(component.getElement());
} else {
throw new IllegalArgumentException("The given component ("
+ component + ") is not a child of this component");
}
}
}
代码示例来源:origin: com.vaadin/flow-server
/**
* Removes the given child components from this component.
*
* @param components
* the components to remove
* @throws IllegalArgumentException
* if any of the components is not a child of this component
*/
default void remove(Component... components) {
Objects.requireNonNull(components, "Components should not be null");
for (Component component : components) {
Objects.requireNonNull(component,
"Component to remove cannot be null");
Element parent = component.getElement().getParent();
if (parent == null) {
LoggerFactory.getLogger(HasComponents.class).debug(
"Remove of a component with no parent does nothing.");
return;
}
if (getElement().equals(parent)) {
getElement().removeChild(component.getElement());
} else {
throw new IllegalArgumentException("The given component ("
+ component + ") is not a child of this component");
}
}
}
代码示例来源:origin: com.vaadin/flow-server
/**
* Gets the parent component of this component.
* <p>
* A component can only have one parent.
*
* @return an optional parent component, or an empty optional if the
* component is not attached to a parent
*/
public Optional<Component> getParent() {
// If "this" is a component inside a Composite, iterate from the
// Composite downwards
Optional<Component> mappedComponent = getElement().getComponent();
if (!mappedComponent.isPresent()) {
throw new IllegalStateException(
"You cannot use getParent() on a wrapped component. Use Component.wrapAndMap to include the component in the hierarchy");
}
if (isInsideComposite(mappedComponent.get())) {
Component parent = ComponentUtil.getParentUsingComposite(
(Composite<?>) mappedComponent.get(), this);
return Optional.of(parent);
}
// Find the parent component based on the first parent element which is
// mapped to a component
return ComponentUtil.findParentComponent(getElement().getParent());
}
代码示例来源:origin: com.vaadin/flow-data
if (contentTemplate.getParent() != container) {
container.appendChild(contentTemplate);
代码示例来源:origin: com.vaadin/vaadin-crud-flow
/**
* Sets the grid
*
* @param grid the grid
*/
public void setGrid(Grid<E> grid) {
Objects.requireNonNull(grid, "Grid cannot be null");
if (this.grid != null && this.grid.getElement().getParent() == getElement()) {
this.grid.getElement().removeFromParent();
}
this.grid = grid;
grid.getElement().setAttribute(SLOT_KEY, GRID_SLOT_NAME);
// It might already have a parent e.g when injected from a template
if (grid.getElement().getParent() == null) {
getElement().appendChild(grid.getElement());
}
}
代码示例来源:origin: alejandro-du/crudui
@Override
public void hideForm() {
formComponentLayout.removeAll();
if (formCaptionLayout.getElement().getParent() != null) {
secondComponent.getElement().removeChild(formCaptionLayout.getElement());
}
}
代码示例来源:origin: com.vaadin/flow-server
if (!uiElement.equals(rootElement.getParent())) {
if (oldRoot != null) {
oldRoot.getElement().removeFromParent();
代码示例来源:origin: com.vaadin/vaadin-date-picker-flow
/**
* Removes the given child components from this component.
*
* @param components
* The components to remove.
* @throws IllegalArgumentException
* if any of the components is not a child of this component.
*/
protected void remove(Component... components) {
for (Component component : components) {
if (getElement().equals(component.getElement().getParent())) {
component.getElement().removeAttribute("slot");
getElement().removeChild(component.getElement());
} else {
throw new IllegalArgumentException("The given component ("
+ component + ") is not a child of this component");
}
}
}
代码示例来源:origin: com.vaadin/vaadin-button-flow
/**
* Removes the given child components from this component.
*
* @param components
* The components to remove.
* @throws IllegalArgumentException
* if any of the components is not a child of this component.
*/
protected void remove(Component... components) {
for (Component component : components) {
if (getElement().equals(component.getElement().getParent())) {
component.getElement().removeAttribute("slot");
getElement().removeChild(component.getElement());
} else {
throw new IllegalArgumentException("The given component ("
+ component + ") is not a child of this component");
}
}
}
代码示例来源:origin: com.vaadin/vaadin-text-field-flow
/**
* Removes the given child components from this component.
*
* @param components
* The components to remove.
* @throws IllegalArgumentException
* if any of the components is not a child of this component.
*/
protected void remove(Component... components) {
for (Component component : components) {
if (getElement().equals(component.getElement().getParent())) {
component.getElement().removeAttribute("slot");
getElement().removeChild(component.getElement());
} else {
throw new IllegalArgumentException("The given component ("
+ component + ") is not a child of this component");
}
}
}
代码示例来源:origin: com.vaadin/vaadin-upload-flow
/**
* Removes the given child components from this component.
*
* @param components
* The components to remove.
* @throws IllegalArgumentException
* if any of the components is not a child of this component.
*/
protected void remove(Component... components) {
for (Component component : components) {
if (getElement().equals(component.getElement().getParent())) {
component.getElement().removeAttribute("slot");
getElement().removeChild(component.getElement());
} else {
throw new IllegalArgumentException("The given component ("
+ component + ") is not a child of this component");
}
}
}
代码示例来源:origin: com.vaadin/vaadin-text-field-flow
/**
* Removes the given child components from this component.
*
* @param components
* The components to remove.
* @throws IllegalArgumentException
* if any of the components is not a child of this component.
*/
protected void remove(Component... components) {
for (Component component : components) {
if (getElement().equals(component.getElement().getParent())) {
component.getElement().removeAttribute("slot");
getElement().removeChild(component.getElement());
} else {
throw new IllegalArgumentException("The given component ("
+ component + ") is not a child of this component");
}
}
}
代码示例来源:origin: com.vaadin/vaadin-split-layout-flow
/**
* Removes the given child components from this component.
*
* @param components
* The components to remove.
* @throws IllegalArgumentException
* if any of the components is not a child of this component.
*/
protected void remove(Component... components) {
for (Component component : components) {
if (getElement().equals(component.getElement().getParent())) {
component.getElement().removeAttribute("slot");
getElement().removeChild(component.getElement());
} else {
throw new IllegalArgumentException("The given component ("
+ component + ") is not a child of this component");
}
}
}
代码示例来源:origin: com.vaadin/vaadin-form-layout-flow
/**
* Removes the given child components from this component.
*
* @param components
* The components to remove.
* @throws IllegalArgumentException
* if any of the components is not a child of this component.
*/
protected void remove(Component... components) {
for (Component component : components) {
if (getElement().equals(component.getElement().getParent())) {
component.getElement().removeAttribute("slot");
getElement().removeChild(component.getElement());
} else {
throw new IllegalArgumentException("The given component ("
+ component + ") is not a child of this component");
}
}
}
代码示例来源:origin: com.vaadin/vaadin-select-flow
/**
* Removes the given child components from this component.
*
* @param components
* The components to remove.
* @throws IllegalArgumentException
* if any of the components is not a child of this component.
*/
protected void remove(Component... components) {
for (Component component : components) {
if (getElement().equals(component.getElement().getParent())) {
component.getElement().removeAttribute("slot");
getElement().removeChild(component.getElement());
} else {
throw new IllegalArgumentException("The given component ("
+ component + ") is not a child of this component");
}
}
}
代码示例来源:origin: com.vaadin/vaadin-crud-flow
/**
* Sets the editor.
* When injecting a {@link Crud} with {@literal @}Id this method must be called
* before the crud is put into use.
*
* @param editor the editor
*/
public void setEditor(CrudEditor<E> editor) {
Objects.requireNonNull(editor, "Editor cannot be null");
if (this.editor != null
&& this.editor.getView() != null
&& this.editor.getView().getElement().getParent() == getElement()) {
this.editor.getView().getElement().removeFromParent();
}
this.editor = editor;
// It might already have a parent e.g when injected from a template
if (editor.getView() != null && editor.getView().getElement().getParent() == null) {
editor.getView().getElement().setAttribute(SLOT_KEY, FORM_SLOT_NAME);
getElement().appendChild(editor.getView().getElement());
}
}
代码示例来源:origin: alejandro-du/crudui
@Override
public void showForm(CrudOperation operation, Component form) {
String caption = formCaptions.get(operation);
if (caption != null) {
Div label = new Div(new Text(caption));
label.getStyle().set("color", "var(--lumo-primary-text-color)");
formCaptionLayout.removeAll();
formCaptionLayout.add(label);
secondComponent.getElement().insertChild(secondComponent.getComponentCount() - 1, formCaptionLayout.getElement());
} else if (formCaptionLayout.getElement().getParent() != null) {
secondComponent.getElement().removeChild(formCaptionLayout.getElement());
}
formComponentLayout.removeAll();
formComponentLayout.add(form);
}
内容来源于网络,如有侵权,请联系作者删除!