Package com.nomagic.magicdraw.properties
Class PropertyManager
- java.lang.Object
-
- com.nomagic.magicdraw.properties.PropertyManager
-
- All Implemented Interfaces:
PropertyVisitorAcceptor
,java.beans.PropertyChangeListener
,java.lang.Cloneable
,java.util.EventListener
- Direct Known Subclasses:
ExtendablePropertyManager
@OpenApiAll public class PropertyManager extends java.lang.Object implements java.lang.Cloneable, java.beans.PropertyChangeListener, PropertyVisitorAcceptor
This class is used for managing of the set of the properties. The manager has name. Also manager can return some property with given property ID.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
PropertyManager.StateListener
-
Field Summary
Fields Modifier and Type Field Description private java.lang.ref.SoftReference<java.util.Map<java.lang.String,java.lang.Integer>>
cacheByID
Cache of properties by id.private java.util.Map<java.lang.String,java.lang.Object[][]>
enableMaps
private boolean
frozen
private java.util.Collection<java.lang.String>
hiddenProperties
Properties exists in parent property manager but should not be visible in this manager.private java.lang.String
id
ID of this property manager.static java.lang.String
IS_UNIQUE
Identifies the property as "unique".private java.lang.String
name
The name of the property manager.static java.lang.String
OWN_PROPERTY_ADDED
Identifies type ofPropertyChangeEvent
.static java.lang.String
OWN_PROPERTY_REMOVED
Identifies type ofPropertyChangeEvent
.private PropertyManager
parent
Property manager which can use "shared" properties from super type.private java.util.List<Property>
properties
The list of properties in this manager.private java.beans.PropertyChangeListener
stateListener
private Style
style
Style in which manager exits, can be null.private com.nomagic.utils.ExtendedPropertyChangeSupport
support
PropertyChangeListeners
support.
-
Constructor Summary
Constructors Constructor Description PropertyManager()
Constructs new property managerPropertyManager(PropertyManager parentPropertyManager, java.lang.String name, java.util.List<? extends Property> properties)
Constructs new property manager.PropertyManager(java.lang.String name, java.util.List<? extends Property> properties)
Constructs new property manager.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
accept(PropertyVisitor visitor)
Accepts the given visitor.void
addProperties(java.util.Collection<Property> properties)
Adds the properties to the property manager.void
addProperty(Property prop)
Adds the property to the property manager.void
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
AddsPropertyChangeListener
to the listeners list.private void
addStateListener(Property property)
void
append(PropertyManager manager)
Adds not existing properties from given manager to itself.void
append(PropertyManager manager, boolean makeUndefined, boolean mergeSources)
Adds not existing properties from given manager to itself.void
append(java.util.List<Property> properties)
Adds not existing properties from given list to itself.void
append(java.util.List<Property> properties, boolean makeUndefined, boolean mergeSources)
Adds not existing properties from given list to itself.void
apply(PropertyManager manager)
Applies properties from given manager.void
apply(java.util.Collection<Property> properties)
Applies properties from given list.void
applyValues(java.util.Collection<Property> col)
Applies properties values only from given list.private void
cleanCache()
Clean properties cachePropertyManager
clone()
Clones the manager.static java.util.List<Property>
cloneProperties(java.util.List<Property> properties)
private static boolean
containsValue(java.lang.Object values, java.lang.Object value)
void
distinct(PropertyManager man)
Sets to itself properties those are not equal to the given properties.java.util.List<Property>
distinct(java.util.List<Property> properties)
Returns properties those are not equal to the given properties.boolean
equalsTo(PropertyManager given)
boolean
equalsWithValues(PropertyManager pm, java.util.Set<java.lang.String> ids)
Check it equals with given property value.private void
firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
static void
generateDefaultDescriptionID(PropertyManager manager)
static void
generateNullDescriptionID(PropertyManager manager)
java.lang.String
getClassType()
Returns property class type.java.util.Collection<java.lang.String>
getHiddenProperties()
java.lang.String
getID()
Get IDjava.lang.String
getName()
Returns name of the property manager.java.util.List<Property>
getOrderedProperties()
Returns list of properties.java.util.List<Property>
getOwnProperties()
Returns the list of the properties.PropertyManager
getParentPropertyManager()
java.util.List<Property>
getProperties()
Returns the list of the properties.private java.util.Map<java.lang.String,java.lang.Integer>
getPropertiesCache(boolean create)
Return (create if needed) cache of propertiesprivate java.util.Map<java.lang.String,java.lang.Integer>
getPropertiesCash(boolean create)
Deprecated.Property
getProperty(java.lang.String id)
Returns the property from the properties list with given id.private Property
getProperty(java.lang.String id, boolean justOwned)
Returns the property from the properties list with given id.Property
getPropertyByName(java.lang.String name)
Returns property from the properties list with given name.private java.beans.PropertyChangeListener
getStateListener()
Style
getStyle()
Get property style.void
hideParentProperty(java.lang.String propertyID)
Hides given property with id from parent property manager.private static boolean
isEqualElements(Element element1, Element element2)
Compare two elements, may be from different projects (compare by id)private static boolean
isEqualValues(java.lang.Object value1, java.lang.Object value2)
boolean
isFrozen()
boolean
isHiddenParentProperty(java.lang.String propertyID)
Check if property with a given ID is hidden parent propertyboolean
isTheSame(PropertyManager manager)
Check if given property manager is the same as current.private void
justAddProperty(Property prop)
Adds the property to the property manager.void
leaveTheSame(PropertyManager manager)
Removes from this manager all properties those does not exist in the given manager.void
leaveTheSame(PropertyManager manager, boolean makeUndefined, boolean mergeSources)
Removes from this manager all properties those does not exist in the given manager.PropertyManager
makeCopy()
Make copy of property.void
makeOwnProperty(Property prop)
Makes given property as own property even if property with such id is in parent (makes property not shared)protected void
mergeBooleanProperty(BooleanProperty currentProp, BooleanProperty otherProp)
protected void
mergeChoiceProperty(ChoiceProperty currentProperty, ChoiceProperty otherProperty)
private static <T extends java.util.Collection<java.lang.Object>>
TmergeCollection(T collection1, T collection2, java.util.function.Supplier<T> collectionCreator)
protected void
mergeElementProperty(ElementProperty currentProp, ElementProperty otherProp)
protected void
mergeProperties(Property currentManagerProperty, Property property, boolean makeUndefined, boolean mergeSources)
protected void
mergePropertyByType(Property currentProperty, Property otherProperty)
private void
printIllegalStateException()
void
propertyChange(java.beans.PropertyChangeEvent e)
Listens toPropertyChangeEvents
.void
removeProperty(Property prop)
Removes the property from the property manager.void
removeProperty(java.lang.String id)
Removes the property with given ID from the property manager.void
removeProperty(java.util.Collection<java.lang.String> propertyIDs)
Removes all properties with given ids.void
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
RemovesPropertyChangeListener
from the listeners list.private void
removeStateListener(Property prop)
void
retainProperties(java.util.Collection<java.lang.String> ids)
Removes all properties except the the ones with given ids.void
setFrozen(boolean mFrozen)
void
setID(java.lang.String id)
Sets id for this property manager.void
setName(java.lang.String name)
Sets name of the manager.void
setParentPropertyManager(PropertyManager parentPropertyManager)
Set parent Property Manager.void
setParentPropertyManagerOnly(PropertyManager parentPropertyManager)
Set parent Property Manager.void
setProperties(java.util.List<Property> prop)
Sets the list of the properties.void
setPropertyEnableMap(java.lang.String propertyId, java.lang.Object[][] map)
Set Property Enable Mapvoid
setStyle(Style style)
Set style.java.lang.String
sGetID()
Property manager simple ID getter (does not generate ID if it is not present).void
shareProperty(Property prop)
Makes given property shared form parent PropertyManager.void
showParentProperty(java.lang.String propertyID)
Show parent property.java.lang.String
toString()
Returns info used for debug.private void
updateState(Property property)
private void
updateStates(Property property)
-
-
-
Field Detail
-
frozen
private boolean frozen
-
OWN_PROPERTY_ADDED
public static final java.lang.String OWN_PROPERTY_ADDED
Identifies type ofPropertyChangeEvent
. This type of even is fired when particular property is added toPropertyManager
own properties collection. It may be triggered byaddProperty(Property)
ormakeOwnProperty(Property)
method call.- See Also:
- Constant Field Values
-
OWN_PROPERTY_REMOVED
public static final java.lang.String OWN_PROPERTY_REMOVED
Identifies type ofPropertyChangeEvent
. This type of even is fired when particular property is removed fromPropertyManager
own properties collection. It may be triggered byremoveProperty(Property)
orshareProperty(Property)
method call.- See Also:
- Constant Field Values
-
IS_UNIQUE
public static final java.lang.String IS_UNIQUE
Identifies the property as "unique". Is set viaProperty.setAdditionalProperty(String, Object)
:property.setAdditionalProperty(PropertyManager.IS_UNIQUE, true);
Unique property will always be removed when callingleaveTheSame(PropertyManager, boolean, boolean)
method.- See Also:
- Constant Field Values
-
cacheByID
@CheckForNull private java.lang.ref.SoftReference<java.util.Map<java.lang.String,java.lang.Integer>> cacheByID
Cache of properties by id. Keep this cache on soft reference.
-
id
@CheckForNull private java.lang.String id
ID of this property manager.
-
parent
@CheckForNull private PropertyManager parent
Property manager which can use "shared" properties from super type. For example if shape and class can have color property, if class do not defines its own it should use shared shape property.
-
name
@CheckForNull private java.lang.String name
The name of the property manager.
-
properties
private java.util.List<Property> properties
The list of properties in this manager. Use list not set for saving the order in which the properties were added.
-
hiddenProperties
@CheckForNull private java.util.Collection<java.lang.String> hiddenProperties
Properties exists in parent property manager but should not be visible in this manager.
-
style
@CheckForNull private Style style
Style in which manager exits, can be null.
-
enableMaps
private java.util.Map<java.lang.String,java.lang.Object[][]> enableMaps
-
stateListener
private java.beans.PropertyChangeListener stateListener
-
support
@CheckForNull private com.nomagic.utils.ExtendedPropertyChangeSupport support
PropertyChangeListeners
support. Used to fire events when own properties collection changes.
-
-
Constructor Detail
-
PropertyManager
public PropertyManager()
Constructs new property manager
-
PropertyManager
public PropertyManager(@CheckForNull java.lang.String name, @CheckForNull java.util.List<? extends Property> properties)
Constructs new property manager.- Parameters:
name
- the name of the manager.properties
- the list of properties.
-
PropertyManager
public PropertyManager(@CheckForNull PropertyManager parentPropertyManager, @CheckForNull java.lang.String name, @CheckForNull java.util.List<? extends Property> properties)
Constructs new property manager.- Parameters:
name
- the name of the manager.properties
- the list of properties.parentPropertyManager
- parent property manager which can provides properties can be shared in this manager.
-
-
Method Detail
-
addStateListener
private void addStateListener(Property property)
-
getStateListener
private java.beans.PropertyChangeListener getStateListener()
-
getHiddenProperties
@CheckForNull public java.util.Collection<java.lang.String> getHiddenProperties()
-
updateStates
private void updateStates(Property property)
-
updateState
private void updateState(Property property)
-
containsValue
private static boolean containsValue(java.lang.Object values, @CheckForNull java.lang.Object value)
-
getID
public java.lang.String getID()
Get ID- Returns:
- ID of property.
-
sGetID
@CheckForNull public java.lang.String sGetID()
Property manager simple ID getter (does not generate ID if it is not present).- Returns:
- property manager ID or
null
-
getParentPropertyManager
@CheckForNull public PropertyManager getParentPropertyManager()
-
setParentPropertyManager
public void setParentPropertyManager(@CheckForNull PropertyManager parentPropertyManager)
Set parent Property Manager.- Parameters:
parentPropertyManager
- parent manager
-
setParentPropertyManagerOnly
public void setParentPropertyManagerOnly(@CheckForNull PropertyManager parentPropertyManager)
Set parent Property Manager.- Parameters:
parentPropertyManager
- parent manager
-
getProperty
@CheckForNull public Property getProperty(java.lang.String id)
Returns the property from the properties list with given id.- Parameters:
id
- the ID of property.- Returns:
- property with given ID. Null if such property is not added into the manager.
-
getProperty
@CheckForNull private Property getProperty(java.lang.String id, boolean justOwned)
Returns the property from the properties list with given id.- Parameters:
id
- the ID of property.justOwned
- do not check parent manager if this argument is true- Returns:
- property with given ID. Null if such property is not added into the manager.
-
getPropertyByName
@CheckForNull public Property getPropertyByName(java.lang.String name)
Returns property from the properties list with given name.- Parameters:
name
- name of the property- Returns:
- property with given name. Null if such property is not added into the manager.
-
addProperty
public void addProperty(Property prop)
Adds the property to the property manager. If property with such ID was already added, the old property is removed. Checking if property with same id already exists in parent property manager, and they value is the same do nothing- Parameters:
prop
- the new property.
-
addProperties
public void addProperties(java.util.Collection<Property> properties)
Adds the properties to the property manager. If property with such ID was already added, the old property is removed. Checking if property with same id already exists in parent property manager, and they value is the same do nothing- Parameters:
properties
- the new properties.
-
justAddProperty
private void justAddProperty(Property prop)
Adds the property to the property manager. If property with such ID was already added, the old property is removed.- Parameters:
prop
- the new property.
-
removeProperty
public void removeProperty(Property prop)
Removes the property from the property manager.- Parameters:
prop
- the property.
-
removeProperty
public void removeProperty(java.lang.String id)
Removes the property with given ID from the property manager.- Parameters:
id
- the property's ID.
-
getProperties
public java.util.List<Property> getProperties()
Returns the list of the properties.- Returns:
- all properties from this manager and parent managers.
-
getOwnProperties
public java.util.List<Property> getOwnProperties()
Returns the list of the properties.- Returns:
- all properties only from this manager. List is unmodifiable.
-
setProperties
public void setProperties(java.util.List<Property> prop)
Sets the list of the properties.- Parameters:
prop
- the list of new properties for this manager.
-
removeStateListener
private void removeStateListener(Property prop)
-
getOrderedProperties
public java.util.List<Property> getOrderedProperties()
Returns list of properties. Properties are stored in list no sorting needed- Returns:
- list of properties
-
clone
public PropertyManager clone()
Clones the manager. Does deep clone - all properties will be cloned too.- Overrides:
clone
in classjava.lang.Object
- Returns:
- the cloned manager.
-
cloneProperties
public static java.util.List<Property> cloneProperties(java.util.List<Property> properties)
-
makeCopy
public PropertyManager makeCopy()
Make copy of property.- Returns:
- Property Manager.
-
apply
public void apply(PropertyManager manager)
Applies properties from given manager. Property from given manager will be replaced with property from this manager if this manager: 1.has property with such ID. 2.state of this property is not UNDEFINED.- Parameters:
manager
- manager which properties will be applied to this.- See Also:
apply(Collection)
-
apply
public void apply(java.util.Collection<Property> properties)
Applies properties from given list. Property from given list will be replaced with property from this manager if this manager: 1.has property with such ID. 2.state of this property is not UNDEFINED.- Parameters:
properties
- collection of properties to be applied to this.
-
applyValues
public void applyValues(java.util.Collection<Property> col)
Applies properties values only from given list.- Parameters:
col
- collection of properties to be applied to this.
-
leaveTheSame
public void leaveTheSame(PropertyManager manager)
Removes from this manager all properties those does not exist in the given manager. Property will be removed if given manager does not have property with the same ID. Existing property in this manager will be set to undefined state if property in the given manager has different value.- Parameters:
manager
- the given manager.
-
leaveTheSame
public void leaveTheSame(PropertyManager manager, boolean makeUndefined, boolean mergeSources)
Removes from this manager all properties those does not exist in the given manager. Property will be removed if given manager does not have property with the same ID and the same value.- Parameters:
manager
- the given manager.makeUndefined
- existing property in this manager will be set to undefined state if property in given manager has different value.mergeSources
- if true, properties sources will be merged
-
mergeProperties
protected void mergeProperties(Property currentManagerProperty, Property property, boolean makeUndefined, boolean mergeSources)
-
mergePropertyByType
protected void mergePropertyByType(Property currentProperty, Property otherProperty)
-
mergeBooleanProperty
protected void mergeBooleanProperty(BooleanProperty currentProp, BooleanProperty otherProp)
-
mergeElementProperty
protected void mergeElementProperty(ElementProperty currentProp, ElementProperty otherProp)
-
mergeChoiceProperty
protected void mergeChoiceProperty(ChoiceProperty currentProperty, ChoiceProperty otherProperty)
-
mergeCollection
@CheckForNull private static <T extends java.util.Collection<java.lang.Object>> T mergeCollection(@CheckForNull T collection1, @CheckForNull T collection2, java.util.function.Supplier<T> collectionCreator)
-
setName
public void setName(java.lang.String name)
Sets name of the manager.- Parameters:
name
- the new name.
-
getName
public java.lang.String getName()
Returns name of the property manager.- Returns:
- the name of the property manager.
-
distinct
public java.util.List<Property> distinct(java.util.List<Property> properties)
Returns properties those are not equal to the given properties.- Parameters:
properties
- the given properties.- Returns:
- not equal properties to the given properties or empty list.
-
isEqualValues
private static boolean isEqualValues(@CheckForNull java.lang.Object value1, @CheckForNull java.lang.Object value2)
-
isEqualElements
private static boolean isEqualElements(@CheckForNull Element element1, @CheckForNull Element element2)
Compare two elements, may be from different projects (compare by id)- Parameters:
element1
- elementelement2
- element- Returns:
- true if element are equal, otherwise false.
-
distinct
public void distinct(PropertyManager man)
Sets to itself properties those are not equal to the given properties.- Parameters:
man
- the manager with given properties.
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent e)
Listens toPropertyChangeEvents
. Takes new value from the event(new value must be a list of properties) and sets these properties to itself.- Specified by:
propertyChange
in interfacejava.beans.PropertyChangeListener
- Parameters:
e
- the property change event.
-
accept
public void accept(PropertyVisitor visitor) throws java.lang.Exception
Accepts the given visitor.- Specified by:
accept
in interfacePropertyVisitorAcceptor
- Parameters:
visitor
- the PropertyVisitor.- Throws:
java.lang.Exception
-
getClassType
public java.lang.String getClassType()
Returns property class type.- Specified by:
getClassType
in interfacePropertyVisitorAcceptor
- Returns:
- PropertyID.PROPERTY_MANAGER
- See Also:
PropertyID.PROPERTY_MANAGER
-
append
public void append(PropertyManager manager)
Adds not existing properties from given manager to itself. The properties existence is checked by property ID.- Parameters:
manager
- the manager with properties.
-
append
public void append(PropertyManager manager, boolean makeUndefined, boolean mergeSources)
Adds not existing properties from given manager to itself. The properties existence is checked by property ID.- Parameters:
manager
- the manager with properties.makeUndefined
- existing property in this manager will be set to undefined state if property in given manager has different value.mergeSources
- if true, properties sources will be merged
-
append
public void append(java.util.List<Property> properties)
Adds not existing properties from given list to itself. The properties existence is checked by property ID.- Parameters:
properties
- the list of given properties.
-
append
public void append(java.util.List<Property> properties, boolean makeUndefined, boolean mergeSources)
Adds not existing properties from given list to itself. The properties existence is checked by property ID.- Parameters:
properties
- the list of given properties.makeUndefined
- existing property in this manager will be set to undefined state if property in given manager has different value.mergeSources
- if true, properties sources will be merged
-
toString
public java.lang.String toString()
Returns info used for debug.- Overrides:
toString
in classjava.lang.Object
- Returns:
- info for debug
-
shareProperty
public void shareProperty(Property prop)
Makes given property shared form parent PropertyManager. Value changed in parent will affect property in this property manager.- Parameters:
prop
- property to share.
-
makeOwnProperty
public void makeOwnProperty(Property prop)
Makes given property as own property even if property with such id is in parent (makes property not shared)- Parameters:
prop
- property
-
hideParentProperty
public void hideParentProperty(java.lang.String propertyID)
Hides given property with id from parent property manager. Not that if property with this id is in this property manager nothing will be changed.- Parameters:
propertyID
- property ID to hide from parent manager;
-
isHiddenParentProperty
public boolean isHiddenParentProperty(java.lang.String propertyID)
Check if property with a given ID is hidden parent property- Parameters:
propertyID
- property ID
-
showParentProperty
public void showParentProperty(java.lang.String propertyID)
Show parent property.- Parameters:
propertyID
- property ID
-
setID
public void setID(@CheckForNull java.lang.String id)
Sets id for this property manager.- Parameters:
id
- new id of this property manager.
-
getStyle
@CheckForNull public Style getStyle()
Get property style.- Returns:
- Returns the style.
-
setStyle
public void setStyle(@CheckForNull Style style)
Set style.- Parameters:
style
- The style to set.
-
setPropertyEnableMap
public void setPropertyEnableMap(java.lang.String propertyId, java.lang.Object[][] map)
Set Property Enable Map- Parameters:
propertyId
- Property id.map
- map
-
printIllegalStateException
private void printIllegalStateException()
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
AddsPropertyChangeListener
to the listeners list. Each listeners receivesOWN_PROPERTY_ADDED
andOWN_PROPERTY_REMOVED
event types.- Parameters:
listener
- thePropertyChangeListener
to be added- See Also:
PropertyChangeSupport
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
RemovesPropertyChangeListener
from the listeners list. Each listeners receivesOWN_PROPERTY_ADDED
andOWN_PROPERTY_REMOVED
event types.- Parameters:
listener
- the PropertyChangeListener to be removed- See Also:
PropertyChangeSupport
-
firePropertyChange
private void firePropertyChange(java.lang.String propertyName, @CheckForNull java.lang.Object oldValue, @CheckForNull java.lang.Object newValue)
-
equalsTo
public boolean equalsTo(PropertyManager given)
-
generateDefaultDescriptionID
public static void generateDefaultDescriptionID(PropertyManager manager)
-
generateNullDescriptionID
public static void generateNullDescriptionID(PropertyManager manager)
-
equalsWithValues
public boolean equalsWithValues(PropertyManager pm, @CheckForNull java.util.Set<java.lang.String> ids)
Check it equals with given property value.- Parameters:
pm
- The given property value.ids
- properties IDs to check (may be null - to check all properties)- Returns:
- boolean
-
cleanCache
private void cleanCache()
Clean properties cache
-
getPropertiesCache
@CheckForNull private java.util.Map<java.lang.String,java.lang.Integer> getPropertiesCache(boolean create)
Return (create if needed) cache of properties- Parameters:
create
- create flag- Returns:
- created map
-
getPropertiesCash
@CheckForNull @Deprecated private java.util.Map<java.lang.String,java.lang.Integer> getPropertiesCash(boolean create)
Deprecated.
-
removeProperty
public void removeProperty(java.util.Collection<java.lang.String> propertyIDs)
Removes all properties with given ids.- Parameters:
propertyIDs
- ids of the properties to remove from the manager.
-
retainProperties
public void retainProperties(java.util.Collection<java.lang.String> ids)
Removes all properties except the the ones with given ids.- Parameters:
ids
- ids of the properties to leave in the manager.
-
isTheSame
public boolean isTheSame(PropertyManager manager)
Check if given property manager is the same as current. Managers are the same if names are equal and parent managers are equal- Parameters:
manager
- manager- Returns:
- true if the same
-
isFrozen
public boolean isFrozen()
-
setFrozen
public void setFrozen(boolean mFrozen)
-
-