java.lang.Object
org.autogui.base.mapping.GuiReprValue
- All Implemented Interfaces:
GuiRepresentation
- Direct Known Subclasses:
GuiReprCollectionElement
,GuiReprCollectionTable
,GuiReprEmbeddedComponent
,GuiReprObjectPane
,GuiReprPropertyPane
,GuiReprValueBooleanCheckBox
,GuiReprValueDocumentEditor
,GuiReprValueEnumComboBox
,GuiReprValueFilePathField
,GuiReprValueImagePane
,GuiReprValueLabel
,GuiReprValueNumberSpinner
,GuiReprValueStringField
a value component associated with
GuiTypeValue
.
matching Class
with the subclass implementing matchValueType(Class)
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
pair object for a value and a String name, can be converted to a JSON object member.static class
an auxiliary information for specifying a property value.static class
the indexed specifier for specifying an element in a liststatic class
special specifier, can be obtained byNONE
Nested classes/interfaces inherited from interface org.autogui.base.mapping.GuiRepresentation
GuiRepresentation.GuiReprNone
-
Field Summary
FieldsModifier and TypeFieldDescriptionspecial specifier for non-indexed property values without caching. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addHistoryValue
(GuiMappingContext context, Object value) static <T> T
castOrMake
(Class<T> cls, Object o, Supplier<T> v) casto
ifo
is a non-null and specified typecls
, otherwise callv
.boolean
checkAndUpdateSource
(GuiMappingContext context) the class supposes that the parent is aGuiReprPropertyPane
: [propName: [objectPane]].static void
convertLog
(String msg, Object from, Object to, GuiMappingContext context) createNewValue
(GuiMappingContext context) void
errorWhileAddHistoryValue
(GuiMappingContext context, Object value, Throwable ex) called fromaddHistoryValue(GuiMappingContext, Object)
and special handling forIllegalAccessException
which means an addition of a large object to the prefs storefromJson
(GuiMappingContext context, Object target, Object json) create a new value object from the JSON with treating the target as an old value, or update the target with the JSON contents.fromSource
(Object o) protected GuiUpdatedValue
fromSourceUpdated
(GuiMappingContext context, GuiUpdatedValue v) static Supplier
<GuiReprValue.ObjectSpecifier> getParentSource
(GuiMappingContext context, GuiReprValue.ObjectSpecifier parentSpecifier) obtain the current parent value from the parent context by callinggetUpdatedSource(GuiMappingContext, ObjectSpecifier)
getUpdatedSource
(GuiMappingContext context, GuiReprValue.ObjectSpecifier specifier) callgetUpdatedValue(GuiMappingContext, ObjectSpecifier)
only if the context holds a value pane and 1) the current source is NONE or 2)GuiReprValue.ObjectSpecifier.isUsingCache()
=false, and if NO_UPDATE, then return the current source from the context,getUpdatedValue
(GuiMappingContext context, GuiReprValue.ObjectSpecifier specifier) obtain the current value of the context.getUpdatedValueWithoutNoUpdate
(GuiMappingContext context, GuiReprValue.ObjectSpecifier specifier) callgetUpdatedValue(GuiMappingContext, ObjectSpecifier)
and never return NO_UPDATEgetValue
(GuiMappingContext context, GuiMappingContext.GuiSourceValue parentSource, GuiReprValue.ObjectSpecifier specifier, GuiMappingContext.GuiSourceValue prev) obtain the property value from parentSource as an owner.getValueCollectionElement
(GuiMappingContext context, GuiMappingContext.GuiSourceValue collection, GuiReprValue.ObjectSpecifier elementSpecifier, GuiMappingContext.GuiSourceValue prev) a table pane returns an element in a collectionint
getValueCollectionSize
(GuiMappingContext context, GuiMappingContext.GuiSourceValue collection, GuiReprValue.ObjectSpecifier specifier) a table pane returns the size of a collectionClass
<?> getValueType
(GuiMappingContext context) obtains the value type from the context.getValueWithoutNoUpdate
(GuiMappingContext context, GuiMappingContext.GuiSourceValue parentSource, GuiReprValue.ObjectSpecifier specifier) callgetValue(GuiMappingContext, GuiMappingContext.GuiSourceValue, GuiReprValue.ObjectSpecifier, GuiMappingContext.GuiSourceValue)
and never return NO_UPDATEboolean
isEditable
(GuiMappingContext context) boolean
boolean
isHistoryValueStored
(Object value) boolean
isHistoryValueStored
(GuiMappingContext context, Object value) currently checked byisHistoryValueSupported(GuiMappingContext)
boolean
boolean
isHistoryValueSupported
(GuiMappingContext context) checks whether the context supports the value history feature or not.boolean
boolean
match
(GuiMappingContext context) match the representation with the typeElement of the context, and if succeeded, it sets this representation to the context, and it might create sub-contexts for recursive matches *boolean
matchValueType
(Class<?> cls) protected void
notifyUpdateWithParentSourceNone
(GuiMappingContext context, Object newValue, GuiReprValue.ObjectSpecifier specifier, GuiMappingContext.GuiSourceValue src) the source value is "None" atupdateWithParentSource(GuiMappingContext, Object, ObjectSpecifier)
.void
setSource
(GuiMappingContext context, Object value) toJson
(GuiMappingContext context, Object source) convert the source into JSON formattoString()
toUpdateValue
(GuiMappingContext context, Object value) called from a GUI element in order to update its value.static Object
update
(GuiMappingContext context, GuiMappingContext.GuiSourceValue parentSource, Object newValue, GuiReprValue.ObjectSpecifier specifier) set a new value to a property of an object, which specified by the context usingGuiMappingContext.execute(Callable)
if the type is aGuiTypeMemberProperty
, update the property byGuiTypeMemberProperty.executeSet(Object, Object)
if parent is a propertyGuiReprPropertyPane
or a collection elementGuiReprCollectionElement
, obtain the parent source of the parent, and update the parent with the source and newValue.updateCollectionElement
(GuiMappingContext context, GuiMappingContext.GuiSourceValue collection, Object newValue, GuiReprValue.ObjectSpecifier elementSpecifier) a table pane updates a specified elementvoid
updateFromGui
(GuiMappingContext context, Object newValue, GuiReprValue.ObjectSpecifier specifier, GuiTaskClock viewClock) call the setter by editing on GUI, andGuiMappingContext.updateSourceFromGui(Object)
.updateWithParentSource
(GuiMappingContext context, Object newValue, GuiReprValue.ObjectSpecifier specifier) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.autogui.base.mapping.GuiRepresentation
continueCheckAndUpdateSourceForChildren, fromHumanReadableString, fromJsonWithNamed, isJsonSetter, isTaskRunnerUsedFor, matchAndSetNotifiersAsInit, setNotifiersTree, shutdown, toHumanReadableString, toJsonWithNamed, toStringHeader
-
Field Details
-
NONE
special specifier for non-indexed property values without caching. the parent of the specifier always this instance (cyclic). -
NONE_WITH_CACHE
-
-
Constructor Details
-
GuiReprValue
public GuiReprValue()
-
-
Method Details
-
match
Description copied from interface:GuiRepresentation
match the representation with the typeElement of the context, and if succeeded, it sets this representation to the context, and it might create sub-contexts for recursive matches *- Specified by:
match
in interfaceGuiRepresentation
- Parameters:
context
- the context of the repr.- Returns:
- the matching result
-
getValueType
obtains the value type from the context. the implementation checks the context is a property, or an element value- Parameters:
context
- the context- Returns:
- a property type class, an element value class, or null
-
matchValueType
-
checkAndUpdateSource
the class supposes that the parent is aGuiReprPropertyPane
: [propName: [objectPane]]. then, the parent of source and this source are a same value; and the parent is already checkAndUpdateSource and a new value is supplied. the method usesgetUpdatedValue(GuiMappingContext, ObjectSpecifier)
with theNONE
specifier.As additional side effect, the updated value will be added to the value-history if supported by
addHistoryValue(GuiMappingContext, Object)
, and the value will also be set as a new source value bysetSource(GuiMappingContext, Object)
- Specified by:
checkAndUpdateSource
in interfaceGuiRepresentation
- Parameters:
context
- the source context- Returns:
- the source context is updated or not
-
addHistoryValue
-
errorWhileAddHistoryValue
called fromaddHistoryValue(GuiMappingContext, Object)
and special handling forIllegalAccessException
which means an addition of a large object to the prefs store- Parameters:
context
- the context objectvalue
- the added valueex
- the exception caught- Since:
- 1.2
-
setSource
-
getValue
public GuiUpdatedValue getValue(GuiMappingContext context, GuiMappingContext.GuiSourceValue parentSource, GuiReprValue.ObjectSpecifier specifier, GuiMappingContext.GuiSourceValue prev) throws Throwable obtain the property value from parentSource as an owner.In this class, support following cases:
- the type is a
GuiTypeMemberProperty
- other types: use methods of
GuiTypeValue
with prev and parentSource as the inherited value
- Parameters:
context
- the context holding the repr.parentSource
- the property owner. if no value then nothing will happen for propertiesspecifier
- the specifier of the valueprev
- a previous value compared to the obtained value- Returns:
- an obtained property value (nullable) or
GuiUpdatedValue.NO_UPDATE
if the value is equivalent to the previous value. - Throws:
Throwable
- might be caused by executing method invocations.
- the type is a
-
convertLog
-
toParentSource
-
fromSourceUpdated
-
getValueWithoutNoUpdate
public Object getValueWithoutNoUpdate(GuiMappingContext context, GuiMappingContext.GuiSourceValue parentSource, GuiReprValue.ObjectSpecifier specifier) throws Throwable callgetValue(GuiMappingContext, GuiMappingContext.GuiSourceValue, GuiReprValue.ObjectSpecifier, GuiMappingContext.GuiSourceValue)
and never return NO_UPDATE- Parameters:
context
- the contextparentSource
- the property owner. if null then nothing will happen for propertiesspecifier
- the specifier of the value- Returns:
- an obtained value or null
- Throws:
Throwable
- might be caused by executing method invocation
-
unwrapNoUpdate
-
getUpdatedValue
public GuiUpdatedValue getUpdatedValue(GuiMappingContext context, GuiReprValue.ObjectSpecifier specifier) throws Throwable obtain the current value of the context. This is called fromcheckAndUpdateSource(GuiMappingContext)
, and invokegetParentSource(GuiMappingContext, GuiReprValue.ObjectSpecifier)
andgetValue(GuiMappingContext, GuiMappingContext.GuiSourceValue, GuiReprValue.ObjectSpecifier, GuiMappingContext.GuiSourceValue)
- Parameters:
context
- target context,specifier
- the specifier of the value- Returns:
- the current value (nullable) or
GuiUpdatedValue.NO_UPDATE
- Throws:
Throwable
- might be caused by executing method invocations.
-
getUpdatedValueWithoutNoUpdate
public Object getUpdatedValueWithoutNoUpdate(GuiMappingContext context, GuiReprValue.ObjectSpecifier specifier) throws Throwable callgetUpdatedValue(GuiMappingContext, ObjectSpecifier)
and never return NO_UPDATE- Parameters:
context
- the contextspecifier
- the specifier of the value- Returns:
- original source (nullable), never NO_UPDATE
- Throws:
Throwable
- might be caused by executing method invocation
-
getUpdatedSource
public GuiMappingContext.GuiSourceValue getUpdatedSource(GuiMappingContext context, GuiReprValue.ObjectSpecifier specifier) throws Throwable callgetUpdatedValue(GuiMappingContext, ObjectSpecifier)
only if the context holds a value pane and 1) the current source is NONE or 2)GuiReprValue.ObjectSpecifier.isUsingCache()
=false, and if NO_UPDATE, then return the current source from the context,- Parameters:
context
- the contextspecifier
- the specifier of the value- Returns:
- the updated value as a source-value or the current source value of the context
- Throws:
Throwable
- might be caused d by executing method invocation
-
getParentSource
public GuiMappingContext.GuiSourceValue getParentSource(GuiMappingContext context, GuiReprValue.ObjectSpecifier parentSpecifier) throws Throwable obtain the current parent value from the parent context by callinggetUpdatedSource(GuiMappingContext, ObjectSpecifier)
- Parameters:
context
- the context of the repr.parentSpecifier
- the specifier of the parent value- Returns:
- the source value of the parent
- Throws:
Throwable
- the action might cause an error
-
getValueCollectionElement
public GuiUpdatedValue getValueCollectionElement(GuiMappingContext context, GuiMappingContext.GuiSourceValue collection, GuiReprValue.ObjectSpecifier elementSpecifier, GuiMappingContext.GuiSourceValue prev) a table pane returns an element in a collection- Parameters:
context
- the context of the reprcollection
- a collection targetelementSpecifier
- an element index i.e.GuiReprValue.ObjectSpecifierIndex
prev
- the previous value of the element- Returns:
- an element in the collection, default is null
-
getValueCollectionSize
public int getValueCollectionSize(GuiMappingContext context, GuiMappingContext.GuiSourceValue collection, GuiReprValue.ObjectSpecifier specifier) throws Throwable a table pane returns the size of a collection- Parameters:
context
- the context of the reprcollection
- a collection targetspecifier
- the specifier of the collection- Returns:
- the size of the collection, default is 1
- Throws:
Throwable
- an error while getting
-
updateCollectionElement
public Object updateCollectionElement(GuiMappingContext context, GuiMappingContext.GuiSourceValue collection, Object newValue, GuiReprValue.ObjectSpecifier elementSpecifier) throws Throwable a table pane updates a specified element- Parameters:
context
- the context of the reprcollection
- a collection targetnewValue
- an element valueelementSpecifier
- an element index i.e.GuiReprValue.ObjectSpecifierIndex
- Returns:
- the updated value
- Throws:
Throwable
- an error while updating
-
updateFromGui
public void updateFromGui(GuiMappingContext context, Object newValue, GuiReprValue.ObjectSpecifier specifier, GuiTaskClock viewClock) call the setter by editing on GUI, andGuiMappingContext.updateSourceFromGui(Object)
.- add
newValue
to the history byaddHistoryValue(GuiMappingContext, Object)
- obtain parent source and update
updateWithParentSource(GuiMappingContext, Object, ObjectSpecifier)
- check
isUpdateContextSourceByUpdateFromGui(GuiMappingContext)
andGuiMappingContext.updateSourceFromGui(Object)
: update the source and notify to listeners
- Parameters:
context
- the context of this repr.newValue
- the updated property valuespecifier
- the specifier of the valueviewClock
- the clock value of sender view
- add
-
isUpdateContextSourceByUpdateFromGui
-
updateWithParentSource
public Object updateWithParentSource(GuiMappingContext context, Object newValue, GuiReprValue.ObjectSpecifier specifier) throws Throwable obtain the parent source bygetUpdatedSource(GuiMappingContext, GuiReprValue.ObjectSpecifier)
and callupdate(GuiMappingContext, GuiMappingContext.GuiSourceValue, Object, GuiReprValue.ObjectSpecifier)
- Parameters:
context
- the target contextnewValue
- a new value to be set to the propertyspecifier
- the specifier of the value- Returns:
- the returned value by updating
- Throws:
Throwable
- an error while getParentSource or update
-
notifyUpdateWithParentSourceNone
protected void notifyUpdateWithParentSourceNone(GuiMappingContext context, Object newValue, GuiReprValue.ObjectSpecifier specifier, GuiMappingContext.GuiSourceValue src) the source value is "None" atupdateWithParentSource(GuiMappingContext, Object, ObjectSpecifier)
. The default behavior is nothing- Parameters:
context
- the contextnewValue
- the updating new valuespecifier
- the specifier of the valuesrc
- the source for the context- Since:
- 1.7
-
update
public Object update(GuiMappingContext context, GuiMappingContext.GuiSourceValue parentSource, Object newValue, GuiReprValue.ObjectSpecifier specifier) throws Throwable set a new value to a property of an object, which specified by the context- using
GuiMappingContext.execute(Callable)
- if the type is a
GuiTypeMemberProperty
, update the property byGuiTypeMemberProperty.executeSet(Object, Object)
- if parent is a property
GuiReprPropertyPane
or a collection elementGuiReprCollectionElement
, obtain the parent source of the parent, and update the parent with the source and newValue. This will be done by parent'supdateWithParentSource(GuiMappingContext, Object, ObjectSpecifier)
- otherwise call
GuiTypeValue.writeValue(Object, Object)
or a similar method
- Parameters:
context
- the target contextparentSource
- the property ownernewValue
- a new value to be set to the propertyspecifier
- the specifier of the value- Returns:
- newValue which will need to be passed to
GuiMappingContext.updateSourceFromGui(Object)
, or null if error - Throws:
Throwable
- an error while updating
- using
-
isHistoryValueSupported
public boolean isHistoryValueSupported()- Returns:
- if true,
updateFromGui(GuiMappingContext, Object, ObjectSpecifier, GuiTaskClock)
automatically add the value to the preferences. the default impl. returns true.
-
isHistoryValueStored
- Parameters:
value
- the tested value, or null at loading- Returns:
- if true, actually the value is stored to the preferences store
-
isHistoryValueStored
currently checked byisHistoryValueSupported(GuiMappingContext)
- Parameters:
context
- the context objectvalue
- stored value- Returns:
- true if the context supports storing the value as a history
- Since:
- 1.2
-
isHistoryValueSupported
checks whether the context supports the value history feature or not. it can be controlled by the annotation parameter "history".- Parameters:
context
- the context object- Returns:
- true if the context supports storing history values
- Since:
- 1.2
-
isEditable
- Parameters:
context
- the context of the repr.- Returns:
- the result of
GuiTypeMemberProperty.isWritable()
and so on.
-
toUpdateValue
called from a GUI element in order to update its value. subclass can change to returned type and convert the value to the type. a typical use case is just down-casting and converting null to an empty object.- Parameters:
context
- the context of the repr.value
- the current value- Returns:
- the updated value
-
toJson
Description copied from interface:GuiRepresentation
convert the source into JSON format -
fromJson
Description copied from interface:GuiRepresentation
create a new value object from the JSON with treating the target as an old value, or update the target with the JSON contents. the behavior can be varied by each representation, confirmed byGuiRepresentation.isJsonSetter()
.- Specified by:
fromJson
in interfaceGuiRepresentation
- Parameters:
context
- a context holds the representationtarget
- the target object or nulljson
- JSON objects representing the targetString
,Number
,Boolean
,List
,Map
or null- Returns:
- created object from the json, target if provided, or null.
-
isFromJsonTakingMapWithContextNameEntry
- Parameters:
context
- the target context- Returns:
- true means
fromJson(GuiMappingContext, Object, Object)
takes a map with the entry namedGuiMappingContext.getName()
-
createNewValue
- Throws:
Throwable
-
castOrMake
casto
ifo
is a non-null and specified typecls
, otherwise callv
. used intoJson(GuiMappingContext, Object)
.- Type Parameters:
T
- the required type- Parameters:
cls
- the required classT
o
- the current value, nullablev
- the falling-back supplier- Returns:
o
or the result ofv
-
toString
-
fromSource
- Parameters:
o
- a raw-object which can be directly passed to type-element's executing methods- Returns:
- a wrapped object for clients of the representation
-
toSource
- Parameters:
o
- a wrapped object for clients of the representation- Returns:
- a raw-object which can be directly passed to type-element's executing methods
-
getNoneSupplier
- Returns:
- a lambda for returning
NONE
-