Class LeafletObject

java.lang.Object
org.vaadin.addons.componentfactory.leaflet.LeafletObject
All Implemented Interfaces:
Serializable, Identifiable, ExecutableFunctions
Direct Known Subclasses:
Layer, LeafletControl

public abstract class LeafletObject extends Object implements ExecutableFunctions, Serializable
Base class for serializable client-side Leaflet objects. It provides a unique identifier, JSON serialization and access to the Leaflet constructor arguments declared through LeafletArgument.
See Also:
  • Constructor Details

    • LeafletObject

      protected LeafletObject()
      Creates a new Leaflet object, initializing its Jackson mapper and assigning it a random unique identifier.
  • Method Details

    • configureObjectMapper

      protected void configureObjectMapper(tools.jackson.databind.json.JsonMapper.Builder builder)
      Hook for subclasses to customize the Jackson mapper used for serializing this object. Jackson 3 mappers are immutable, so configuration must be applied to the JsonMapper.Builder before the mapper is built.
      Parameters:
      builder - the mapper builder to configure
    • getUuid

      public String getUuid()
      Returns the unique identifier of this object.
      Specified by:
      getUuid in interface Identifiable
      Returns:
      the object uuid
    • getJson

      public String getJson()
      Returns the JSON representation of this object, computing it lazily on first access.
      Returns:
      the JSON representation of this object
    • getConstructorArgumentNames

      public List<String> getConstructorArgumentNames()
      Returns the names of the fields used as client-side constructor arguments, ordered by their LeafletArgument index.
      Returns:
      the constructor argument names
    • getLeafletType

      public String getLeafletType()
      Returns the Leaflet type name of this object, used to instantiate the matching class on the client side.
      Returns:
      the Leaflet type name
    • executeJs

      public void executeJs(Identifiable target, String functionName, Serializable... arguments)
      Delegates the execution of the named client-side function to the parent, if any.
      Specified by:
      executeJs in interface ExecutableFunctions
      Parameters:
      target - the client object to invoke the function on
      functionName - the name of the function to call
      arguments - the arguments passed to the function
    • call

      public <T extends Serializable> CompletableFuture<T> call(Identifiable target, String functionName, Class<T> resultType, Serializable... arguments)
      Delegates a client-side function call, returning a result, to the parent, if any.
      Specified by:
      call in interface ExecutableFunctions
      Type Parameters:
      T - the type of the returned result
      Parameters:
      target - the client object to invoke the function on
      functionName - the name of the function to call
      resultType - the type the client result should be deserialized to
      arguments - the arguments passed to the function
      Returns:
      a future completed with the function result, or null if there is no parent to delegate to
    • setParent

      protected void setParent(ExecutableFunctions parent)
      Sets the parent through which client-side function calls are delegated.
      Parameters:
      parent - the parent to set
    • getParent

      protected ExecutableFunctions getParent()
      Returns the parent through which client-side function calls are delegated.
      Returns:
      the parent