本文整理了Java中com.vaadin.flow.dom.Element.getChildren()
方法的一些代码示例,展示了Element.getChildren()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.getChildren()
方法的具体详情如下:
包路径:com.vaadin.flow.dom.Element
类名称:Element
方法名:getChildren
[英]Gets all the children of this element.
If property "innerHTML" has been set explicitly then its value (the new element structure) won't be populated on the server side and this method returns an empty stream.
[中]获取此元素的所有子元素。
如果已显式设置属性“innerHTML”,则不会在服务器端填充其值(新元素结构),并且此方法返回空流。
代码示例来源:origin: com.vaadin/vaadin-button-flow
private Element[] getTextNodes() {
return getElement().getChildren().filter(Element::isTextNode)
.toArray(Element[]::new);
}
代码示例来源:origin: com.vaadin/flow-server
private Stream<Element> flattenChildren(Element node) {
if (node.getChildCount() > 0) {
return node.getChildren().flatMap(this::flattenChildren);
}
return Stream.of(node);
}
代码示例来源:origin: com.vaadin/vaadin-upload-flow
private void removeElementsAtSlot(String slot) {
getElement().getChildren()
.filter(child -> slot.equals(child.getAttribute("slot")))
.forEach(Element::removeFromParent);
}
代码示例来源:origin: com.vaadin/vaadin-upload-flow
private Component getComponentAtSlot(String slot) {
return getElement().getChildren()
.filter(child -> slot.equals(child.getAttribute("slot")))
.filter(child -> child.getComponent().isPresent())
.map(child -> child.getComponent().get()).findFirst()
.orElse(null);
}
代码示例来源:origin: com.vaadin/vaadin-button-flow
private Element[] getNonTextNodes() {
return getElement().getChildren()
.filter(element -> !element.isTextNode())
.toArray(Element[]::new);
}
代码示例来源:origin: com.vaadin/vaadin-text-field-flow
/**
* Gets all the child elements of the parent that are in the specified slot.
*
* @param parent
* the component to get children from, not {@code null}
* @param slot
* the name of the slot inside the parent, not {@code null}
* @return the child elements of the parent that are inside the slot
*/
public static Stream<Element> getElementsInSlot(HasElement parent,
String slot) {
return parent.getElement().getChildren()
.filter(child -> slot.equals(child.getAttribute("slot")));
}
代码示例来源:origin: com.vaadin/flow-server
private void appendTextContent(StringBuilder builder,
Predicate<? super Element> childFilter) {
if (isTextNode()) {
builder.append(getText());
} else {
getChildren().filter(childFilter)
.forEach(e -> e.appendTextContent(builder, childFilter));
}
}
代码示例来源:origin: com.vaadin/flow-server
/**
* Finds the first component instance in each {@link Element} subtree by
* traversing the {@link Element} tree starting from the given element.
*
* @param element
* the element to start scanning from
* @param componentConsumer
* a consumer which is called for each found component
*/
public static void findComponents(Element element,
Consumer<Component> componentConsumer) {
assert element != null;
assert componentConsumer != null;
Optional<Component> maybeComponent = element.getComponent();
if (maybeComponent.isPresent()) {
Component component = maybeComponent.get();
componentConsumer.accept(component);
return;
}
element.getChildren().forEach(childElement -> ComponentUtil
.findComponents(childElement, componentConsumer));
}
代码示例来源:origin: com.vaadin/vaadin-notification-flow
@Override
public Stream<Component> getChildren() {
Builder<Component> childComponents = Stream.builder();
container.getChildren().forEach(childElement -> ComponentUtil
.findComponents(childElement, childComponents::add));
return childComponents.build();
}
代码示例来源:origin: com.vaadin/vaadin-upload-flow
/**
* Removes all contents from this component, this includes child components,
* text content as well as child elements that have been added directly to
* this component using the {@link Element} API.
*/
protected void removeAll() {
getElement().getChildren()
.forEach(child -> child.removeAttribute("slot"));
getElement().removeAllChildren();
}
}
代码示例来源:origin: com.vaadin/vaadin-crud-flow
/**
* Sets the content of the toolbar.
* Any content with the attribute `new-button` triggers a new item creation.
*
* @param components the content to be set
*/
public void setToolbar(Component... components) {
final Element[] existingToolbarElements = getElement().getChildren()
.filter(e -> TOOLBAR_SLOT_NAME.equals(e.getAttribute(SLOT_KEY)))
.toArray(Element[]::new);
getElement().removeChild(existingToolbarElements);
final Element[] newToolbarElements = Arrays.stream(components)
.map(Component::getElement)
.map(e -> e.setAttribute(SLOT_KEY, TOOLBAR_SLOT_NAME))
.toArray(Element[]::new);
getElement().appendChild(newToolbarElements);
}
代码示例来源:origin: com.vaadin/vaadin-text-field-flow
/**
* Removes all contents from this component, this includes child components,
* text content as well as child elements that have been added directly to
* this component using the {@link Element} API.
*/
protected void removeAll() {
getElement().getChildren()
.forEach(child -> child.removeAttribute("slot"));
getElement().removeAllChildren();
}
代码示例来源:origin: com.vaadin/vaadin-split-layout-flow
/**
* Removes all contents from this component, this includes child components,
* text content as well as child elements that have been added directly to
* this component using the {@link Element} API.
*/
protected void removeAll() {
getElement().getChildren()
.forEach(child -> child.removeAttribute("slot"));
getElement().removeAllChildren();
}
}
代码示例来源:origin: com.vaadin/vaadin-form-layout-flow
/**
* Removes all contents from this component, this includes child components,
* text content as well as child elements that have been added directly to
* this component using the {@link Element} API.
*/
protected void removeAll() {
getElement().getChildren()
.forEach(child -> child.removeAttribute("slot"));
getElement().removeAllChildren();
}
}
代码示例来源:origin: com.vaadin/vaadin-button-flow
/**
* Removes all contents from this component except elements in
* {@code exclusion} array. This includes child components, text content as
* well as child elements that have been added directly to this component
* using the {@link Element} API.
*
* @see Button#removeAll()
*/
private void removeAll(Element... exclusion) {
Set<Element> toExclude = Stream.of(exclusion)
.collect(Collectors.toSet());
Predicate<Element> filter = toExclude::contains;
getElement().getChildren().filter(filter.negate())
.forEach(child -> child.removeAttribute("slot"));
getElement().removeAllChildren();
getElement().appendChild(exclusion);
}
代码示例来源:origin: com.vaadin/vaadin-button-flow
/**
* Removes all contents from this component, this includes child components,
* text content as well as child elements that have been added directly to
* this component using the {@link Element} API.
*/
protected void removeAll() {
getElement().getChildren()
.forEach(child -> child.removeAttribute("slot"));
getElement().removeAllChildren();
}
代码示例来源:origin: com.vaadin/vaadin-text-field-flow
/**
* Removes all contents from this component, this includes child components,
* text content as well as child elements that have been added directly to
* this component using the {@link Element} API.
*/
protected void removeAll() {
getElement().getChildren()
.forEach(child -> child.removeAttribute("slot"));
getElement().removeAllChildren();
}
代码示例来源:origin: com.vaadin/vaadin-date-picker-flow
/**
* Removes all contents from this component, this includes child components,
* text content as well as child elements that have been added directly to
* this component using the {@link Element} API.
*/
protected void removeAll() {
getElement().getChildren()
.forEach(child -> child.removeAttribute("slot"));
getElement().removeAllChildren();
}
代码示例来源:origin: com.vaadin/vaadin-select-flow
/**
* Removes all contents from this component, this includes child components,
* text content as well as child elements that have been added directly to
* this component using the {@link Element} API.
*/
protected void removeAll() {
getElement().getChildren()
.forEach(child -> child.removeAttribute("slot"));
getElement().removeAllChildren();
}
代码示例来源:origin: com.vaadin/flow-server
/**
* Gets the child components of this component.
* <p>
* The default implementation finds child components by traversing each
* child {@link Element} tree.
* <p>
* If the component is injected to a PolymerTemplate using the
* <code>@Id</code> annotation the getChildren method will only return
* children added from the server side and will not return any children
* declared in the template file.
*
* @see Id
*
* @return the child components of this component
*/
public Stream<Component> getChildren() {
// This should not ever be called for a Composite as it will return
// wrong results
assert !(this instanceof Composite);
if (!getElement().getComponent().isPresent()) {
throw new IllegalStateException(
"You cannot use getChildren() on a wrapped component. Use Component.wrapAndMap to include the component in the hierarchy");
}
Builder<Component> childComponents = Stream.builder();
getElement().getChildren().forEach(childElement -> ComponentUtil
.findComponents(childElement, childComponents::add));
return childComponents.build();
}
内容来源于网络,如有侵权,请联系作者删除!