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
-
-
Constructor Summary
Constructors Constructor Description MapProperty(String name, NodeMap map)Creates a new property.MapProperty(String name, NodeMap map, boolean forceValueUpdate)Creates a new property.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description elemental.events.EventRemoveraddChangeListener(MapPropertyChangeListener listener)Adds a listener that gets notified when the value of this property changes.elemental.events.EventRemoveraddReactiveValueChangeListener(ReactiveValueChangeListener reactiveValueChangeListener)Adds a listener that has a dependency to this value, and should be notified when this value changes.NodeMapgetMap()Gets the map that this property belongs to.StringgetName()Gets the name of this property.RunnablegetSyncToServerCommand(Object newValue)Sets the value of this property and returns a synch to server command.ObjectgetValue()Gets the property value.booleangetValueOrDefault(boolean defaultValue)Returns the value, or the given defaultValue if the property does not have a value or the property value is null.intgetValueOrDefault(int defaultValue)Returns the value, or the given defaultValue if the property does not have a value or the property value is null.StringgetValueOrDefault(String defaultValue)Returns the value, or the given defaultValue if the property does not have a value or the property value is null.booleanhasValue()Checks whether this property has a value.voidremoveValue()Removes the value of this property so thathasValue()will returnfalseandgetValue()will returnnulluntil the next timesetValue(Object)is run.voidsetValue(Object value)Sets the property value.voidsyncToServer(Object newValue)Sets the value of this property and synchronizes the value to the server.
-
-
-
Method Detail
-
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 ifsetValue(Object)has been invoked after the property was created orremoveValue()was invoked.- Returns:
trueif the property has a value,falseif the property has no value.- See Also:
removeValue()
-
setValue
public void setValue(Object value)
Sets the property value. Changing the value fires aMapPropertyChangeEvent.- Parameters:
value- the new property value- See Also:
addChangeListener(MapPropertyChangeListener)
-
removeValue
public void removeValue()
Removes the value of this property so thathasValue()will returnfalseandgetValue()will returnnulluntil the next timesetValue(Object)is run. AMapPropertyChangeEventwill 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 assigningnullas 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:ReactiveValueAdds a listener that has a dependency to this value, and should be notified when this value changes.- Specified by:
addReactiveValueChangeListenerin interfaceReactiveValue- 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(Object)
-
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:
syncToServer(Object)
-
-