Interface ViewElement

All Known Subinterfaces:
ConfigurableTextViewElement, HtmlViewElement, MutableViewElement
All Known Implementing Classes:
AbstractNodeViewElement, AbstractTextNodeViewElement, AbstractVoidNodeViewElement, ContainerViewElement, NodeViewElement, TemplateViewElement, TextViewElement, ViewElementGenerator, ViewElementSupport, VoidNodeViewElement

public interface ViewElement
Represents a ViewElement in its most simple form. In a web context this is almost certainly a HTML node or collection thereof.
See Also:
  • Method Details

    • getName

      String getName()
      A ViewElement can have an internal name that identifies it within a ContainerViewElement. A name is optional but when given, is preferably unique within its container as most operations work on the first element with a specific name.
      Returns:
      Internal name of this element, can be null.
      See Also:
    • getElementType

      String getElementType()
      Returns:
      Type id of this view element.
    • getCustomTemplate

      String getCustomTemplate()
      Returns:
      Custom template to use when rendering this view element.
    • set

      default ViewElement set(ViewElement.WitherSetter... setters)
      Execute one or more setter functions.
      Parameters:
      setters - to execute
      Returns:
      self
    • remove

      default ViewElement remove(ViewElement.WitherRemover... functions)
      Execute one or more remover functions. A remover is defined as a separate interface so implementations can both implement setter and remover at the same time.
      Parameters:
      functions - to execute
      Returns:
      self
    • matches

      default boolean matches(@NonNull @NonNull Predicate predicate)
      Check if the element matches the predicate given. Note there is no compiler type-safety on this method, predicate implementations should do the type checking. See also predicateFor(Class, Predicate) for a helper function to create a typed predicate inline.
      Parameters:
      predicate - to test
      Returns:
      predicate outcome
    • get

      default <U> U get(ViewElement.WitherGetter<?,U> function)
      Get a value from the element. Use ViewElement.WitherGetter.as(Class) for compile time typing. Note that runtime type casting execptions will occur when using the wrong type.
      Type Parameters:
      U - type of the expected return value
      Parameters:
      function - that returns the value
      Returns:
      value
    • with

      static <U extends ViewElement> ViewElement.Wither<U> with(@NonNull U element)
      Create a ViewElement.Wither wrapper for an element, which allows for a more descriptive, fluent configuration approach by using pre-defined lambdas.
      Type Parameters:
      U - type of the element
      Parameters:
      element - to create a wrapper for
      Returns:
      wither
    • predicateFor

      static <U extends ViewElement> Predicate<U> predicateFor(Class<U> elementType, Predicate<U> predicate)
      Short-hand for creating an anonymous typed predicate, can be used to inline type predicate creation.