public abstract class Attribute<A extends AttributeInterface<?>> extends java.lang.Object implements AttributeInterface<A>
The attribute is contained in the attribute list of a component (composite). It has an unique keyword inside a component.
Observer objects (AttributeObserver
) can be attached to the attribute
if they want to be notified about a value change of the attribute. The
notification is initiated by the concrete derived attributes calling the
method notifyObservers()
. Observers can be removed from the observer
list while they are notified.
ComponentInterface
Modifier and Type | Field and Description |
---|---|
protected AttributeValueFormatInterface<? super A> |
formatter
The attribute value formatter used by the method
formatValue() . |
protected MessageCatalogInterface |
messageCatalog
The message catalog used to get the display keyword.
|
Modifier | Constructor and Description |
---|---|
protected |
Attribute(java.lang.String keyword,
java.lang.Object displayKeywordKey,
MessageCatalogInterface messageCatalog,
java.lang.String attributeType,
boolean readonly)
The constructor initializes the attribute with the passed parameters.
|
Modifier and Type | Method and Description |
---|---|
void |
acceptVisitor(Visitor visitor)
This method applies to the visitor pattern and accepts a visitor for the
attribute.
|
void |
attachObserver(AttributeObserver<? super A> observer)
This method applies to the observer design pattern and attaches the
observer to the attribute.
|
void |
clear()
This method resets the value of the attribute to its default value.
|
void |
copyValue(A sourceAttribute,
ComponentInterface<?> component)
This method implements the interface
AttributeInterface and
copies the value of the passed source attribute to this
attribute. |
void |
detachObserver(AttributeObserver<? super A> observer)
This method removes the observer from the attribute (see also
attachObserver(AttributeObserver) ). |
java.lang.String |
formatValue()
This method returns the value of the attribute as string in user
friendly formatted way.
|
java.lang.String |
getDisplayKeyword()
This method returns the display keyword of the attribute.
|
java.lang.String |
getDisplayKeyword(java.util.Locale locale)
This method returns the display keyword of the attribute in the passed
locale.
|
java.lang.String |
getKeyword()
This method returns the keyword of the attribute.
|
AttributeMode |
getMode()
This method returns the mode of the attribute.
|
java.lang.String |
getType()
This method returns the type of the attribute as string.
|
java.lang.String |
getTypeInfo()
This method returns the attribute type, the mode character and the
value information in one string separated by comma.
|
java.lang.String |
getValueAsString()
This method returns the string representation of the attribute value.
|
java.lang.String |
getValueInfo()
This method returns the valid values for the attribute.
|
boolean |
isReadonly()
This method returns true if the attribute mode is
AttributeMode.READ_ONLY , otherwise false. |
boolean |
isValueEqual(A otherAttribute)
This method implements the interface
AttributeInterface and
compares the value of the passed attribute with the value of this
attribute. |
protected void |
notifyObservers()
This method notifies all observer objects about the attribute value
change.
|
void |
setAttributeValueFormatter(AttributeValueFormatInterface<? super A> formatter)
This method can be used to set a custom value formatter.
|
void |
setValueWithString(java.lang.String newValue)
This method converts the passed string representation of the attribute
value to the specific attribute value.
|
protected MessageCatalogInterface messageCatalog
protected AttributeValueFormatInterface<? super A extends AttributeInterface<?>> formatter
formatValue()
.protected Attribute(java.lang.String keyword, java.lang.Object displayKeywordKey, MessageCatalogInterface messageCatalog, java.lang.String attributeType, boolean readonly)
AttributeTypeTable
in this package. The readonly parameter
determines if the attribute mode is set to AttributeMode.READ_WRITE
or AttributeMode.READ_WRITE
. The mode
is usually used to determine if the attribute can be modified by the user
or only internally by the application. The attribute classes itself do
not check the mode. This is the responsibility of the caller.keyword
- The keyword of the attribute, used to identify the
attribute in its owning component.displayKeywordKey
- The key of the display keyword in the message
catalog. The display keyword is a locale specific text used to identify
the attribute in error messages and user interfaces. If null is
passed, the keyword is used as display keyword instead.messageCatalog
- The message catalog used to get the display
keyword. If null is passed, the keyword is used as display keyword
instead.attributeType
- The attribute type as string describing the type of
the concrete attribute.readonly
- The attribute mode. If true is passed the
attribute mode AttributeMode.READ_ONLY
is set, otherwise AttributeMode.READ_WRITE
. The flag determines if the attribute is
modifiable by the user (false) or not (true).public void acceptVisitor(Visitor visitor) throws AcafException
Visitor.visitAttribute(AttributeInterface)
of the passed visitor.acceptVisitor
in interface AttributeInterface<A extends AttributeInterface<?>>
visitor
- The visitor.AcafException
- May be thrown by the visitor.public void attachObserver(AttributeObserver<? super A> observer)
detachObserver(AttributeObserver)
) as often as it
has been attached. Observers are prepended to the list and notified in
the reverse order as they are attached. This gives the user the
possibility to attach new observers while the notification is in
progress. If observers are attached while the notification is in progress
these observers are not notified!attachObserver
in interface AttributeInterface<A extends AttributeInterface<?>>
observer
- The observer to attached to the attribute.public void clear() throws AttributeException
This implementation here is empty.
clear
in interface AttributeInterface<A extends AttributeInterface<?>>
AttributeException
- May be thrown by implementing classes, when
setting the default value fails.public void copyValue(A sourceAttribute, ComponentInterface<?> component) throws AcafException
AttributeInterface
and
copies the value of the passed source attribute to this
attribute. This implementation calls the method setValueWithString(String)
with the value returned by getValueAsString()
of the source attribute.copyValue
in interface AttributeInterface<A extends AttributeInterface<?>>
sourceAttribute
- The source attribute, the value is copied from.component
- The parent component containing this attribute.
The component is not used here.AcafException
- Thrown, when copying the attribute value fails.ComponentInterface.createCopy(ComponentInterface)
,
Component.addAttribute(AttributeInterface)
public void detachObserver(AttributeObserver<? super A> observer)
attachObserver(AttributeObserver)
). The observer must implement the
method Object.equals(Object)
to be removed properly.detachObserver
in interface AttributeInterface<A extends AttributeInterface<?>>
observer
- The observer to be detached.public java.lang.String formatValue()
formatValue
in interface AttributeInterface<A extends AttributeInterface<?>>
AttributeInterface.setAttributeValueFormatter(AttributeValueFormatInterface)
,
AttributeInterface.getValueAsString()
public java.lang.String getDisplayKeyword()
getDisplayKeyword
in interface AttributeInterface<A extends AttributeInterface<?>>
public java.lang.String getDisplayKeyword(java.util.Locale locale)
getDisplayKeyword
in interface AttributeInterface<A extends AttributeInterface<?>>
locale
- The locale of the display keyword.public java.lang.String getKeyword()
getKeyword
in interface AttributeInterface<A extends AttributeInterface<?>>
public AttributeMode getMode()
getMode
in interface AttributeInterface<A extends AttributeInterface<?>>
public java.lang.String getType()
getType
in interface AttributeInterface<A extends AttributeInterface<?>>
public java.lang.String getTypeInfo()
getTypeInfo
in interface AttributeInterface<A extends AttributeInterface<?>>
AttributeInterface.getTypeInfo()
,
AttributeInterface.getMode()
,
AttributeInterface.getValueInfo()
public java.lang.String getValueAsString()
AttributeInterface.setValueWithString(String)
.
The implementation here returns the empty string.
getValueAsString
in interface AttributeInterface<A extends AttributeInterface<?>>
public java.lang.String getValueInfo()
The implementation here returns the empty string.
getValueInfo
in interface AttributeInterface<A extends AttributeInterface<?>>
public boolean isValueEqual(A otherAttribute) throws AcafException
AttributeInterface
and
compares the value of the passed attribute with the value of this
attribute. This implementation compares the string representation of the
attributes returned by the the method getValueAsString()
. When
the strings are equal, the method returns true.isValueEqual
in interface AttributeInterface<A extends AttributeInterface<?>>
otherAttribute
- The attribute to be compared with this
attribute.AcafException
- May be thrown by derived classes.ComponentInterface.isComponentEqual(ComponentInterface)
public boolean isReadonly()
AttributeMode.READ_ONLY
, otherwise false.isReadonly
in interface AttributeInterface<A extends AttributeInterface<?>>
AttributeMode.READ_ONLY
, otherwise false.protected void notifyObservers()
AttributeObserver.attributeChanged(AttributeInterface)
for all
observers. Observers are managed in a linked list and are always notified
in the same order. Observers can remove itself calling the method detachObserver(AttributeObserver)
while they are notified by this
method. Observers can be attached more than once. They are notified as
often as they appear in the observer list. Observers are notified in the
order they are attached.public void setAttributeValueFormatter(AttributeValueFormatInterface<? super A> formatter)
setAttributeValueFormatter
in interface AttributeInterface<A extends AttributeInterface<?>>
formatter
- The attribute value formatter.public void setValueWithString(java.lang.String newValue) throws AttributeException
AttributeInterface.getValueAsString()
.
This implementation here is empty.
setValueWithString
in interface AttributeInterface<A extends AttributeInterface<?>>
newValue
- The string representation of the new attribute value.AttributeException
- My be thrown by the implementing classes when
converting the string representation or setting the attribute value
fails.