OwnT - the type of the own valueSubjectT - the type of the subject valuepublic abstract class AbstractTypeConverter<OwnT,SubjectT> extends AbstractValueModel<OwnT> implements TypeConverter<OwnT,SubjectT>, ChangeListener, DelegateAccess
To use as a super class, implement TypeConverter.convertOwnToSubjectValue(Object)
and TypeConverter.convertSubjectToOwnValue(Object).
Return the correct value or throw a ConversionException
with an optional alternative value.
If you throw the exception, the sync state will be disabled, otherwise enabled.
If you provide an alternative value in the exception, that value is used as a result.
By default, the converter will throw an exception if the conversion fails and no alternative value is provided by the converter. You can modify that behaviour by setting propagateFailedConversions to false. In that case, a failed conversion will not throw an exception and, in case of a set, the subject value will not be modified, and in case of a get, the own value will be null.
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractTypeConverter(ValueModel<SubjectT> pSubject)
Create a new converter with the handed subject.
|
protected |
AbstractTypeConverter(ValueModel<SubjectT> pSubject,
boolean pPropagateFailedConversions)
Create a new converter with the handed subject and remember how conversion
failures are propagated.
|
| Modifier and Type | Method and Description |
|---|---|
void |
dispose()
Cleanup all resources: disconnect from any input sources (like
other ValueModel's ...), and remove all listeners.
|
boolean |
getPropagateFailedConversions() |
ValueModel<SubjectT> |
getSubject()
Return our subject ValueModel.
|
protected Object |
getSubjectValue()
Return the value of the subject without any conversion.
|
Object |
getSyncKey()
Get the sync key for the sync state.
|
String |
getSyncMessage()
Return a sync message, usefull when the conversation fails.
|
ValueModel<Boolean> |
getSyncState()
Return a ValueModel containing a Boolean that shows if the last
conversion in setValue() or getValue() was sucessfull.
|
OwnT |
getValue()
Get the current value, during a callback this is the new value.
|
Object |
getValue(Object pValue)
Transform the handed value to a new value.
|
boolean |
isEditable()
Returns always true
|
void |
setPropagateFailedConversions(boolean pPropagateFailedConversions)
Sets the flag if we should propagate a failed conversion
|
void |
setSyncKey(Object pKey)
Set the sync key for the sync state.
|
void |
setSyncMessage(String pMessage)
Set the sync message.
|
void |
setValue(OwnT pValue,
boolean pIsSetForced)
Set a new value, this will convert the handed value to
the subject's value.
|
void |
stateChanged(ChangeEvent pEvent)
Invoked when our subject changed.
|
addChangeListener, booleanValue, checkDisposed, doubleValue, fireStateChanged, floatValue, getDependents, getName, intValue, isDisposed, isInSetValue, isSetForced, longValue, onChangeSend, removeChangeListener, retractInterestsFor, setInSetValue, setName, setObjectValue, setValue, setValue, setValue, setValue, setValue, setValue, setValueForced, signalExternalUpdate, stringValueclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitconvertOwnToSubjectValue, convertSubjectToOwnValueaddChangeListener, booleanValue, doubleValue, floatValue, getDependents, getName, intValue, isDisposed, isSetForced, longValue, onChangeSend, removeChangeListener, retractInterestsFor, setName, setObjectValue, setValue, setValue, setValue, setValue, setValue, setValue, setValueForced, stringValueprotected AbstractTypeConverter(ValueModel<SubjectT> pSubject)
pSubject - the ValueModel holding the original value, must not be nullIllegalArgumentException - if pSubject is nullprotected AbstractTypeConverter(ValueModel<SubjectT> pSubject, boolean pPropagateFailedConversions)
pSubject - the ValueModel holding the original value, must not be nullpPropagateFailedConversions - if true, we propagate failed conversions as IllegalStateExceptionsIllegalArgumentException - if pSubject is nullpublic void setPropagateFailedConversions(boolean pPropagateFailedConversions)
pPropagateFailedConversions - if true, we propagate failed conversions as IllegalStateExceptionspublic boolean getPropagateFailedConversions()
public boolean isEditable()
isEditable in interface ValueModel<OwnT>public ValueModel<SubjectT> getSubject()
public void dispose()
dispose in interface ValueModel<OwnT>dispose in class AbstractValueModel<OwnT>public void setValue(OwnT pValue, boolean pIsSetForced)
setValue in interface ValueModel<OwnT>pValue - the new value (null is o.k.)pIsSetForced - true if a forced setValue should be doneUnsupportedOperationException - if this ValueModel is not mutableIllegalStateException - if we can't convert the valuepublic OwnT getValue()
getValue in interface ValueModel<OwnT>IllegalStateException - if we can't convert the valuepublic Object getValue(Object pValue)
getValue in interface DelegateAccesspValue - the value we should assume as our valueprotected Object getSubjectValue()
public ValueModel<Boolean> getSyncState()
getSyncState in interface TypeConverter<OwnT,SubjectT>public Object getSyncKey()
getSyncKey in interface TypeConverter<OwnT,SubjectT>public void setSyncKey(Object pKey)
setSyncKey in interface TypeConverter<OwnT,SubjectT>pKey - a key, may be nullpublic String getSyncMessage()
getSyncMessage in interface TypeConverter<OwnT,SubjectT>public void setSyncMessage(String pMessage)
setSyncMessage in interface TypeConverter<OwnT,SubjectT>pMessage - the sync message, must not be nullpublic void stateChanged(ChangeEvent pEvent)
stateChanged in interface ChangeListenerpEvent - a ChangeEvent objectCopyright © 2017 Jürgen Zeller (privat). All rights reserved.