Class MapProperty

java.lang.Object
com.vaadin.client.flow.nodefeature.MapProperty
All Implemented Interfaces:
ReactiveValue

public class MapProperty extends Object implements ReactiveValue
A property in a node map.
Since:
1.0
Author:
Vaadin Ltd
  • Field Details

    • NO_OP

      public static final Runnable NO_OP
  • Constructor Details

    • MapProperty

      public MapProperty(String name, NodeMap map)
      Creates a new property.
      Parameters:
      name - the name of the property
      map - the map that the property belongs to
    • MapProperty

      public MapProperty(String name, NodeMap map, boolean forceValueUpdate)
      Creates a new property.
      Parameters:
      name - the name of the property
      map - the map that the property belongs to
      forceValueUpdate - whether value update for name property should be applied regardless of previous value
  • Method Details

    • getName

      public String getName()
      Gets the name of this property.
      Returns:
      the property name
    • getMap

      public NodeMap getMap()
      Gets the map that this property belongs to.
      Returns:
      the map
    • getValue

      public Object getValue()
      Gets the property value.
      Returns:
      the property value
    • hasValue

      public boolean hasValue()
      Checks whether this property has a value. A property has a value if setValue(Object) has been invoked after the property was created or removeValue() was invoked.
      Returns:
      true if the property has a value, false if the property has no value.
      See Also:
    • setValue

      public void setValue(Object value)
      Sets the property value. Changing the value fires a MapPropertyChangeEvent.
      Parameters:
      value - the new property value
      See Also:
    • removeValue

      public void removeValue()
      Removes the value of this property so that hasValue() will return false and getValue() will return null until the next time setValue(Object) is run. A MapPropertyChangeEvent will be fired if this property has a value.

      Once a property has been created, it can no longer be removed from its map. The same semantics as e.g. Map.remove(Object) is instead provided by marking the value of the property as removed to distinguish it from assigning null as the value.

    • addChangeListener

      public elemental.events.EventRemover addChangeListener(MapPropertyChangeListener listener)
      Adds a listener that gets notified when the value of this property changes.
      Parameters:
      listener - the property change listener to add
      Returns:
      an event remover for unregistering the listener
    • addReactiveValueChangeListener

      public elemental.events.EventRemover addReactiveValueChangeListener(ReactiveValueChangeListener reactiveValueChangeListener)
      Description copied from interface: ReactiveValue
      Adds a listener that has a dependency to this value, and should be notified when this value changes.
      Specified by:
      addReactiveValueChangeListener in interface ReactiveValue
      Parameters:
      reactiveValueChangeListener - the listener to add
      Returns:
      an event remover that can be used for removing the added listener
    • getValueOrDefault

      public int getValueOrDefault(int defaultValue)
      Returns the value, or the given defaultValue if the property does not have a value or the property value is null.
      Parameters:
      defaultValue - the default value
      Returns:
      the value of the property or the default value if the property does not have a value or the property value is null
    • getValueOrDefault

      public boolean getValueOrDefault(boolean defaultValue)
      Returns the value, or the given defaultValue if the property does not have a value or the property value is null.
      Parameters:
      defaultValue - the default value
      Returns:
      the value of the property or the default value if the property does not have a value or the property value is null
    • getValueOrDefault

      public String getValueOrDefault(String defaultValue)
      Returns the value, or the given defaultValue if the property does not have a value or the property value is null.
      Parameters:
      defaultValue - the default value
      Returns:
      the value of the property or the default value if the property does not have a value or the property value is null
    • syncToServer

      public void syncToServer(Object newValue)
      Sets the value of this property and synchronizes the value to the server.
      Parameters:
      newValue - the new value to set.
      See Also:
    • getSyncToServerCommand

      public Runnable getSyncToServerCommand(Object newValue)
      Sets the value of this property and returns a synch to server command.
      Parameters:
      newValue - the new value to set.
      See Also:
    • setPreviousDomValue

      public void setPreviousDomValue(Object previousDomValue)
      Stores previous DOM value of this property for detection of value modification by the user during the server round-trip.
      Parameters:
      previousDomValue - DOM value of property prior to server round-trip start. Can be null;
    • getPreviousDomValue

      public Optional<Object> getPreviousDomValue()
      Returns previous DOM value of this property for detection of value modification by the user during the server round-trip.
      Returns:
      Optional of previous DOM value. Empty optional is returned if previous value has not been stored.
    • clearPreviousDomValue

      public void clearPreviousDomValue()
      Clears the previous DOM value of this property.