Package com.nomagic.magicdraw.properties
Class Property
- java.lang.Object
-
- com.nomagic.magicdraw.properties.Property
-
- All Implemented Interfaces:
PropertyVisitorAcceptor
,java.lang.Cloneable
- Direct Known Subclasses:
AbstractChoiceProperty
,BooleanProperty
,ColorProperty
,ElementProperty
,FileProperty
,FontProperty
,ListProperty
,NumberProperty
,PageFormatProperty
,StringProperty
,TypeProperty
@OpenApiAll public class Property extends java.lang.Object implements java.lang.Cloneable, PropertyVisitorAcceptor
This class represents some property with some value. This is based class, specific type properties must be derived from this class.
-
-
Field Summary
Fields Modifier and Type Field Description protected static PropertyResourceProvider
DEFAULT_PROPERTY_RESOURCE_PROVIDER
Default property resource provider.static java.lang.String
EDITABLE
"Editable" property namestatic java.lang.String
NULL
Representation of null value as string.static PropertyResourceProvider
NULL_ID_PROPERTY_RESOURCE_PROVIDER
A resource provider which does not try to translate property ID.static java.lang.String
UNDEFINED
Property "undefined" state literal.static java.lang.String
VALUE
"Value" property name
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Object
_getValue()
boolean
_isFrozen()
void
_setFrozen(boolean frozen)
This is an internal api method to mark property as frozen.protected void
_setValue(java.lang.Object value)
void
accept(PropertyVisitor v)
Accepts the given visitor.void
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
DelegatesaddPropertyChangeListener
to thePropertyChangeSupport
, the member of this class, which adds aPropertyChangeListener
to the listener list.void
addSource(java.lang.Object source)
Add source object to a project.void
addSources(java.util.Collection<?> sources)
Append given sources to already existing ones.protected boolean
areValuesEqual(java.lang.Object oldValue, java.lang.Object newValue)
Check if values are equal before setting new value.protected void
checkFrozen()
protected void
checkFrozen(java.util.function.Supplier<java.lang.String> detailsSupplier)
Property
clone()
Clones the property.javax.swing.CellEditor
createCellEditor(com.nomagic.magicdraw.properties.ui.jideui.RendererEditorFactory factory)
Returns the cell editor which edits this property in swing table.javax.swing.table.TableCellRenderer
createTableCellRenderer(com.nomagic.magicdraw.properties.ui.jideui.RendererEditorFactory factory)
Returns the cell renderer which renders this property in swing table.boolean
equals(java.lang.Object o)
Properties are equal if their id are equals.void
firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
DelegatesfirePropertyChange
to thePropertyChangeSupport
, the member of this class, which reports a bound property update to any registered listeners.static java.lang.String
generateDefaultDescriptionID(Property property)
Generates default property description id from property idjava.util.Map<java.lang.String,java.lang.Object>
getAdditionalProperties()
Return a map structure of attached tags to this property.<T> T
getAdditionalProperty(java.lang.String tag)
Return attached "tag" like string valuejava.lang.String
getClassType()
Returns property class type.java.lang.String
getDescription()
Returns property description from resource provider by property description id.java.lang.String
getDescriptionID()
Returns property description ID.Element
getFirstElementFromSources()
Looks for a first Element among sources.java.lang.String
getGroup()
Returns group name for property.java.lang.String
getID()
Returns property id.java.lang.String
getIntroductoryVersion()
Get application version the property was introduced in.java.lang.String
getName()
Returns name of the property.java.lang.String
getNonEditableReason()
Returns the property reasonProject
getProjectFromSourcesOrActive()
Looks for a project of property's sourcesjava.lang.String
getPureDescription()
Returns pure description - does not goes into resource provider.PropertyResourceProvider
getResourceProvider()
ReturnsPropertyResourceProvider
.java.lang.String
getResourceProviderID()
Returns Resource provider ID.Element
getSourceAsElement()
Returns source as Element if property has just one source and that source is an Elementjava.util.Collection<?>
getSources()
Return a collection of property sources.java.util.stream.Stream<java.lang.Object>
getSourcesAsStream()
Return a stream of property sources.static java.lang.String
getUndefinedString()
Returns representation string for "undefined" property statestatic java.lang.String
getUndefinedString(Property property)
Returns representation string for "undefined" property state.java.lang.Object
getValue()
Returns properties value.java.lang.String
getValueStringRepresentation()
Returns value's string representation.int
hashCode()
The hash code will be the same as ID's hash code.boolean
isEditable()
Gets mEnabled flag's value.boolean
isUndefinedState()
Returns value undefined state flag.protected boolean
isValueCompatible(java.lang.Object value)
void
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
DelegatesremovePropertyChangeListener
to thePropertyChangeSupport
, the member of this class, which removes a PropertyChangeListener from the listener list.void
setAdditionalProperties(java.util.Map<java.lang.String,java.lang.Object> tags)
Replace current tags with a new onesvoid
setAdditionalProperty(java.lang.String key, java.lang.Object value)
Attach tag like key-value information to a propertyvoid
setDescription(java.lang.String description)
Set property descriptionvoid
setDescriptionID(java.lang.String descriptionID)
Set property description ID.void
setEditable(boolean editable)
Set mEnabled flag's value.void
setGroup(java.lang.String group)
Sets new group name.void
setID(java.lang.String id)
Sets property id.void
setIntroductoryVersion(java.lang.String introductoryVersion)
Set application version property is introduced in.void
setNonEditableReason(java.lang.String reason)
Sets the property reasonvoid
setResourceProvider(PropertyResourceProvider provider)
Sets PropertyResourceProvider for this property.void
setResourceProviderID(java.lang.String resourceProviderID)
Set resource provider ID.void
setSources(java.util.Collection<?> sources)
Set property's sources.void
setUndefinedState(boolean value)
Sets undefined state for this property.void
setValue(java.lang.Object value)
Sets new property value.java.lang.String
toString()
Return string representation of property for debug purposes.
-
-
-
Field Detail
-
VALUE
public static final java.lang.String VALUE
"Value" property name- See Also:
- Constant Field Values
-
EDITABLE
public static final java.lang.String EDITABLE
"Editable" property name- See Also:
- Constant Field Values
-
UNDEFINED
public static final java.lang.String UNDEFINED
Property "undefined" state literal. ThePropertyChangeEvent.getPropertyName()
return this string when state of the property changes it's "undefined" state.- See Also:
setUndefinedState(boolean)
, Constant Field Values
-
NULL
public static final java.lang.String NULL
Representation of null value as string.- See Also:
- Constant Field Values
-
DEFAULT_PROPERTY_RESOURCE_PROVIDER
protected static final PropertyResourceProvider DEFAULT_PROPERTY_RESOURCE_PROVIDER
Default property resource provider.
-
NULL_ID_PROPERTY_RESOURCE_PROVIDER
public static final PropertyResourceProvider NULL_ID_PROPERTY_RESOURCE_PROVIDER
A resource provider which does not try to translate property ID.
-
-
Constructor Detail
-
Property
public Property()
Constructs new property. Property ID will be empty string, property value - null.
-
Property
public Property(java.lang.String id, @CheckForNull java.lang.Object value)
The property constructor.- Parameters:
id
- the ID of property.value
- the value of the property.
-
-
Method Detail
-
getName
public java.lang.String getName()
Returns name of the property. Property name is taken fromPropertyResourceProvider
with key - Property ID.- Returns:
- name of the property.
-
getID
public java.lang.String getID()
Returns property id.- Returns:
- property ID.
-
setID
public final void setID(java.lang.String id)
Sets property id.- Parameters:
id
- a new property id.
-
setValue
public void setValue(@CheckForNull java.lang.Object value)
Sets new property value. Will fire aPropertyChangeEvent
with propertyName - property ID, newValue and oldValue.- Parameters:
value
- a new property value.
-
isValueCompatible
protected boolean isValueCompatible(java.lang.Object value)
- Returns:
- true if given object can be assigned as value to this property
-
areValuesEqual
protected boolean areValuesEqual(java.lang.Object oldValue, java.lang.Object newValue)
Check if values are equal before setting new value. If values are equal value is not changed.- Parameters:
oldValue
- current value.newValue
- new value.- Returns:
- true if values are equal.
-
equals
public boolean equals(java.lang.Object o)
Properties are equal if their id are equals.- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- some other Property.
-
hashCode
public int hashCode()
The hash code will be the same as ID's hash code.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- property hash code.
-
getValue
public java.lang.Object getValue()
Returns properties value.- Returns:
- value of the property.
-
getValueStringRepresentation
public java.lang.String getValueStringRepresentation()
Returns value's string representation.- Returns:
- string "null" if property does not have value;
value. toString()
if property has value.
-
accept
public void accept(PropertyVisitor v) throws java.lang.Exception
Accepts the given visitor.- Specified by:
accept
in interfacePropertyVisitorAcceptor
- Parameters:
v
- the PropertyVisitor.- Throws:
java.lang.Exception
-
createCellEditor
@CheckForNull @NotApi public javax.swing.CellEditor createCellEditor(com.nomagic.magicdraw.properties.ui.jideui.RendererEditorFactory factory)
Returns the cell editor which edits this property in swing table.- Parameters:
factory
- factory- Returns:
- null here.
-
createTableCellRenderer
@CheckForNull @NotApi public javax.swing.table.TableCellRenderer createTableCellRenderer(com.nomagic.magicdraw.properties.ui.jideui.RendererEditorFactory factory)
Returns the cell renderer which renders this property in swing table.- Parameters:
factory
- factory- Returns:
- null here.
-
clone
public Property clone()
Clones the property. Clone is not deep, the clone will have the same instance of value. The clone will not have registered PropertyChangeListeners.- Overrides:
clone
in classjava.lang.Object
- Returns:
- the cloned property.
-
setUndefinedState
public void setUndefinedState(boolean value)
Sets undefined state for this property. Notifies property change listeners if property undefined state changes.- Parameters:
value
- the new value of undefined state flag.
-
isUndefinedState
public boolean isUndefinedState()
Returns value undefined state flag.- Returns:
- value value of undefined state flag.
-
getClassType
public java.lang.String getClassType()
Returns property class type.- Specified by:
getClassType
in interfacePropertyVisitorAcceptor
- Returns:
- PropertyID.PROPERTY
- See Also:
PropertyID.PROPERTY
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
DelegatesaddPropertyChangeListener
to thePropertyChangeSupport
, the member of this class, which adds aPropertyChangeListener
to the listener list.- Parameters:
listener
- thePropertyChangeListener
to be added- See Also:
PropertyChangeSupport
-
firePropertyChange
public void firePropertyChange(java.lang.String propertyName, @CheckForNull java.lang.Object oldValue, @CheckForNull java.lang.Object newValue)
DelegatesfirePropertyChange
to thePropertyChangeSupport
, the member of this class, which reports a bound property update to any registered listeners. No event is fired if old and new are equal and non-null.- Parameters:
propertyName
- the programmatic name of the property that was changed.oldValue
- the old value of the propertynewValue
- the new value of the property- See Also:
PropertyChangeSupport
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
DelegatesremovePropertyChangeListener
to thePropertyChangeSupport
, the member of this class, which removes a PropertyChangeListener from the listener list.- Parameters:
listener
- the PropertyChangeListener to be removed- See Also:
PropertyChangeSupport
-
toString
public java.lang.String toString()
Return string representation of property for debug purposes.- Overrides:
toString
in classjava.lang.Object
- Returns:
- string representation of the property.
-
getResourceProviderID
@CheckForNull public java.lang.String getResourceProviderID()
Returns Resource provider ID.- Returns:
- id of resource provider.
-
setResourceProviderID
public void setResourceProviderID(@CheckForNull java.lang.String resourceProviderID)
Set resource provider ID.- Parameters:
resourceProviderID
- resource provider id
-
setResourceProvider
public void setResourceProvider(@CheckForNull PropertyResourceProvider provider)
Sets PropertyResourceProvider for this property.- Parameters:
provider
- the given provider.
-
getResourceProvider
public PropertyResourceProvider getResourceProvider()
ReturnsPropertyResourceProvider
. If property does not have resource provider returns shared instance ofDefaultPropertyResourceProvider
.- Returns:
- set
PropertyResourceProvider
or default one.
-
getGroup
@CheckForNull public java.lang.String getGroup()
Returns group name for property. Properties with same group can be grouped in GUI.- Returns:
- Returns group name for property. Can be null.
-
setGroup
public void setGroup(@CheckForNull java.lang.String group)
Sets new group name.- Parameters:
group
- group name, can be null.
-
getDescriptionID
@CheckForNull public java.lang.String getDescriptionID()
Returns property description ID.- Returns:
- description id.
-
setDescriptionID
public void setDescriptionID(@CheckForNull java.lang.String descriptionID)
Set property description ID.- Parameters:
descriptionID
- description id.
-
setDescription
public void setDescription(@CheckForNull java.lang.String description)
Set property description- Parameters:
description
- description
-
getDescription
@CheckForNull public java.lang.String getDescription()
Returns property description from resource provider by property description id. May be null.- Returns:
- description of the property.
-
getPureDescription
@CheckForNull public java.lang.String getPureDescription()
Returns pure description - does not goes into resource provider.- Returns:
- description
-
generateDefaultDescriptionID
public static java.lang.String generateDefaultDescriptionID(Property property)
Generates default property description id from property id- Parameters:
property
- the given property.- Returns:
- description id.
-
isEditable
public boolean isEditable()
Gets mEnabled flag's value.- Returns:
- true if editing of the property is enabled, otherwise - false.
-
setEditable
public void setEditable(boolean editable)
Set mEnabled flag's value.- Parameters:
editable
- new value.
-
getUndefinedString
public static java.lang.String getUndefinedString()
Returns representation string for "undefined" property state- Returns:
- "undefined" representation string
-
getUndefinedString
public static java.lang.String getUndefinedString(Property property)
Returns representation string for "undefined" property state. Property can define its own "undefined" representation string by setting additional propertyQPropertiesHelper.UNDEFINED_STRING
.- Parameters:
property
- property for which undefined string is get.- Returns:
- "undefined" representation string
-
getSources
public java.util.Collection<?> getSources()
Return a collection of property sources. In most cases property represents a value of some object. In these case that object can be added as Property source if traceability is required from property to source object.- Returns:
- sources
- See Also:
setSources(java.util.Collection)
,getSourcesAsStream()
,getSourceAsElement()
,getFirstElementFromSources()
-
getSourcesAsStream
public java.util.stream.Stream<java.lang.Object> getSourcesAsStream()
Return a stream of property sources. In most cases property represents a value of some object. In these case that object can be added as Property source if traceability is required from property to source object.- Returns:
- sources
- See Also:
getSources()
,setSources(java.util.Collection)
,getSourceAsElement()
,getFirstElementFromSources()
-
setSources
public void setSources(java.util.Collection<?> sources)
Set property's sources.- Parameters:
sources
- sources- See Also:
getSources()
-
addSources
public void addSources(java.util.Collection<?> sources)
Append given sources to already existing ones.- Parameters:
sources
- sources to append- See Also:
getSources()
-
addSource
public void addSource(java.lang.Object source)
Add source object to a project.- Parameters:
source
- source object- See Also:
getSources()
-
getAdditionalProperty
@CheckForNull public <T> T getAdditionalProperty(java.lang.String tag)
Return attached "tag" like string value- Parameters:
tag
- tag key- Returns:
- value of given key or null
-
setAdditionalProperty
public void setAdditionalProperty(java.lang.String key, @CheckForNull java.lang.Object value)
Attach tag like key-value information to a property- Parameters:
key
- tag keyvalue
- tag value
-
getAdditionalProperties
@CheckForNull public java.util.Map<java.lang.String,java.lang.Object> getAdditionalProperties()
Return a map structure of attached tags to this property.- Returns:
- tags
- See Also:
setAdditionalProperty(String, Object)
-
setAdditionalProperties
public void setAdditionalProperties(@CheckForNull java.util.Map<java.lang.String,java.lang.Object> tags)
Replace current tags with a new ones- Parameters:
tags
- new tags
-
_isFrozen
public boolean _isFrozen()
- Returns:
- true if property is frozen
-
_setFrozen
public void _setFrozen(boolean frozen)
This is an internal api method to mark property as frozen. Value of frozen property can not be changed - runtime exception will be thrown- Parameters:
frozen
- frozen property state
-
getNonEditableReason
public java.lang.String getNonEditableReason()
Returns the property reason- Returns:
- property reason, if reason is null returns empty string
-
setNonEditableReason
public void setNonEditableReason(java.lang.String reason)
Sets the property reason- Parameters:
reason
- reason why property is not editable
-
getProjectFromSourcesOrActive
public Project getProjectFromSourcesOrActive()
Looks for a project of property's sources- Returns:
- source's project or active project
-
getFirstElementFromSources
@CheckForNull public Element getFirstElementFromSources()
Looks for a first Element among sources.- Returns:
- element
-
getSourceAsElement
@CheckForNull public Element getSourceAsElement()
Returns source as Element if property has just one source and that source is an Element- Returns:
- element
-
getIntroductoryVersion
@CheckForNull public java.lang.String getIntroductoryVersion()
Get application version the property was introduced in.- Returns:
- application version.
-
setIntroductoryVersion
public void setIntroductoryVersion(@CheckForNull java.lang.String introductoryVersion)
Set application version property is introduced in.- Parameters:
introductoryVersion
- current application version ornull
-
checkFrozen
protected void checkFrozen()
-
checkFrozen
protected void checkFrozen(@CheckForNull java.util.function.Supplier<java.lang.String> detailsSupplier)
-
_setValue
protected final void _setValue(@CheckForNull java.lang.Object value)
-
_getValue
@CheckForNull protected final java.lang.Object _getValue()
-
-