- All Implemented Interfaces:
GuiRepresentation
GuiTypeCollection
.
@GuiIncluded public class C { @GuiIncluded public List<String> items = new ArrayList<>(); @GuiIncluded public void addItem() { items.add("item-" + items.size()); items = new ArrayList<>(items); //in order to update a GUI table, it needs to change reference of the list. } }
@GuiIncluded public List<E> objList; //list of some object @GuiIncluded public class E {...} @GuiIncluded public int[] array; //array as a table @GuiIncluded public List<List<String>> strMatrix; //list of list: dynamic changing columns @GuiIncluded public List<M> objList; //complex definition of table @GuiIncluded public class M { @GuiIncluded public List<String> items; }
matching and sub-contexts
GuiTypeCollection.getChildren()
will return the element type of the collection.
Also, the subRepresentation
will take a factory of GuiReprCollectionElement
.
The factory will match the element type with the GuiTypeCollection
as it's parent
(the element itself is a regular element type but the collection element repr. has higher precedence in the factory).
So, a sub-context becomes a single element with the GuiReprCollectionElement
.
The sub-contexts of the sub-collection element become a singleton list of the wrapped element representation.
For cases of object elements in a collection, reprs of contexts become
GuiReprCollectionTable
->
GuiReprCollectionElement
(wrapping GuiReprObjectPane
) ->
GuiReprObjectPane
-> children of GuiReprObjectPane
[ { "e1": v1_1 , "e2":v1_2}, { "e1": v2_1 , "e2":v2_2}, { "e1": v3_1 , "e2":v3_2} ] => table: | e1 | e2 | ------------|-------------- | v1_1 | v1_2 | | v2_1 | v2_2 | | v3_1 | v3_2 |For cases of a list of a list,
GuiReprCollectionElement
wraps GuiReprCollectionTable
.
GuiReprCollectionTable
->
GuiReprCollectionElement
(wrapping GuiReprCollectionTable
) ->
GuiReprCollectionTable
->
GuiReprCollectionElement
(wrapping ...) -> ...
[ [ v1_1 , v1_2], [ v2_1 , v2_2], [ v3_1 , v3_2] ] => table: | 0 | 1 | ------------|-------------- | v1_1 | v1_2 | | v2_1 | v2_2 | | v3_1 | v3_2 |
accessing collection values
contexts of GuiReprCollectionElement
do not have any values or have a temporary element value.
GuiReprCollectionElement.checkAndUpdateSource(GuiMappingContext)
do nothing,
A concrete GUI component for the repr., like GuiSwingViewCollectionTable,
can partially obtain properties of an element of a collection as on-demand cells.
A GUI column obtains its model value via GuiReprValue.getUpdatedValue(GuiMappingContext, GuiReprValue.ObjectSpecifier)
,
and then the repr. obtains a parent value which is an element in a list.
A parent GuiReprCollectionElement
provides an element value by
the special getValueCollectionElement(GuiMappingContext, GuiMappingContext.GuiSourceValue, GuiReprValue.ObjectSpecifier, GuiMappingContext.GuiSourceValue)
.
examples
class O { List<E> list; } class E { String prop; } class SL { List<String> list; }Notation:
- (t,r,s) { cs }:
GuiMappingContext
where t is a typeGuiTypeElement
, r is aGuiRepresentation
, s is a swing component, and cs is a list of sub-contexts. - Obj(T) :
GuiTypeObject
- Prop(n,t) :
GuiTypeMemberProperty
- Coll(T<E>) :
GuiTypeCollection
(Obj(O),GuiReprObjectPane
, GuiSwingViewObjectPane) { (Prop(list,Coll(List<E>)),GuiReprPropertyPane
(subRepr=GuiReprCollectionTable
), GuiSwingViewPropertyPane) { (Coll(List<E>),GuiReprCollectionTable
(subRepr=GuiReprCollectionElement
), GuiSwingViewCollectionTable) { (Obj(E),GuiReprCollectionElement
(GuiReprObjectPane
), GuiSwingTableColumnSetDefault) { (Obj(E),GuiReprObjectPane
, GuiSwingTableColumnSetDefault) { (Prop(prop,String),GuiReprValueStringField
, GuiSwingTableColumnString) {} } } } } }
-
createView
:GuiSwingCollectionTable
creates aCollectionTable
(a subclass ofJTable
): the model is customized as it's row source is a list obtained from the context. The table is aGuiMappingContext.SourceUpdateListener
and registered to the context.GuiSwingCollectionTable
constructs columns byGuiSwingTableColumnSet#createColumns(...)
GuiSwingTableColumnSet
callscreateColumn(subContext,...)
to sub-contexts GuiSwingTableColumn and adds the returned TableColumn to the model.
getValue and update
ObjectTableModel
first obtains row list viaCollectionTable#getSource()
: it returnssource
previously set bysetSwingViewValue(Object)
, with callingtoUpdateValue(GuiMappingContext, Object)
.ObjectTableModel#getValueAt(int,int)
obtains a row object from the obtained source list- and call
ObjectTableColumnValue#getCellValue(rowObject,ri,ci)
, which causesGuiReprValue.getValueWithoutNoUpdate(GuiMappingContext, GuiMappingContext.GuiSourceValue, GuiReprValue.ObjectSpecifier)
with the rowObject and a row-indexed specifier.
(Obj(SL), GuiReprObjectPane, GUiSwingViewObjectPane) { (Prop(list,Coll(List<String>)), GuiReprPropertyPane(subRepr=GuiReprCollectionTable), GuiSwingViewPropertyPane) { (Coll(List<String>), GuiReprCollectionTable(subRepr=GuiReprCollectionElement), GuiSwingViewCollectionTable) { (Obj(String), GuiReprCollectionElement(GuiReprValueStringField), GuiSwingTableColumnSetDefault) { (Obj(String), GuiReprValueStringField, GuiSwingTableColumnString) {} } } } }
update
: For updating the String element value.ObjectTableModel#setValueAt(v,ri,ci)
causesObjectTableColumnValue#setCellValue(rowObj,ri,ci,v)
- the reprs update is
GuiReprValue.update(GuiMappingContext, GuiMappingContext.GuiSourceValue, Object, GuiReprValue.ObjectSpecifier)
and it matches the case of the parent context is a collection-element, then it calls parent'sGuiReprValue.updateWithParentSource(GuiMappingContext, Object, GuiReprValue.ObjectSpecifier)
- the method of the parent obtains the source of the parent of the parent, which is a list, and
call
GuiReprCollectionElement.update(GuiMappingContext, GuiMappingContext.GuiSourceValue, Object, GuiReprValue.ObjectSpecifier)
as the parent update. the method delegatesupdateCollectionElement(GuiMappingContext, GuiMappingContext.GuiSourceValue, Object, GuiReprValue.ObjectSpecifier)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
a list wraps an array.static class
a selected cell valuestatic interface
in order to support arrays, the table-representation use a converter for input/output of values.static class
a converter for arrays: converting between a wrapping list and an arraystatic class
a converter for list object.static interface
interface for actions which handle selected-rows; an actual implementation relies on a concrete GUI componentstatic interface
a subtype of table-target, also supporting selecting partial columns; in the type,GuiReprCollectionTable.TableTarget.getSelectedCells()
returns the values of the partial columns.static interface
an interface for operating a specific column with selected rowsstatic class
a function for setting cell-values with different sized valuesNested classes/interfaces inherited from class org.autogui.base.mapping.GuiReprValue
GuiReprValue.NamedValue, GuiReprValue.ObjectSpecifier, GuiReprValue.ObjectSpecifierIndex, GuiReprValue.ObjectSpecifierNothing
Nested classes/interfaces inherited from interface org.autogui.base.mapping.GuiRepresentation
GuiRepresentation.GuiReprNone
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected GuiReprCollectionTable.ListConverter
protected GuiRepresentation
Fields inherited from class org.autogui.base.mapping.GuiReprValue
NONE, NONE_WITH_CACHE
-
Constructor Summary
ConstructorsConstructorDescriptionGuiReprCollectionTable
(GuiRepresentation subRepresentation) GuiReprCollectionTable
(GuiRepresentation subRepresentation, GuiReprCollectionTable.ListConverter listConverter) -
Method Summary
Modifier and TypeMethodDescriptioncreate
(GuiMappingContext context) fromHumanReadableString
(GuiMappingContext context, String str) fromJson
(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) int
getArrayDimension
(GuiTypeElement element) getElementContext
(GuiMappingContext context) getElementValueContext
(GuiMappingContext context) 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 collectionboolean
isHistoryValueStored
(Object value) boolean
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 *toHumanReadableString
(GuiMappingContext context, Object source) method for constructing "toString" copy operations: the returned string will be separated by tabs and new-linestoJson
(GuiMappingContext context, Object source) convert the source into JSON formattoString()
List
<?> toUpdateValue
(GuiMappingContext context, Object newValue) called from a GUI element in order to update its value.updateCollectionElement
(GuiMappingContext context, GuiMappingContext.GuiSourceValue collection, Object newValue, GuiReprValue.ObjectSpecifier elementSpecifier) a table pane updates a specified elementMethods inherited from class org.autogui.base.mapping.GuiReprValue
addHistoryValue, castOrMake, checkAndUpdateSource, convertLog, createNewValue, errorWhileAddHistoryValue, fromSourceUpdated, getNoneSupplier, getParentSource, getUpdatedSource, getUpdatedValue, getUpdatedValueWithoutNoUpdate, getValue, getValueType, getValueWithoutNoUpdate, isEditable, isFromJsonTakingMapWithContextNameEntry, isHistoryValueStored, isHistoryValueSupported, isUpdateContextSourceByUpdateFromGui, matchValueType, notifyUpdateWithParentSourceNone, setSource, toParentSource, unwrapNoUpdate, update, updateFromGui, updateWithParentSource
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, fromJsonWithNamed, isTaskRunnerUsedFor, matchAndSetNotifiersAsInit, setNotifiersTree, shutdown, toJsonWithNamed, toStringHeader
-
Field Details
-
subRepresentation
-
listConverter
-
castConverter
-
-
Constructor Details
-
GuiReprCollectionTable
-
GuiReprCollectionTable
public GuiReprCollectionTable(GuiRepresentation subRepresentation, GuiReprCollectionTable.ListConverter listConverter)
-
-
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
- Overrides:
match
in classGuiReprValue
- Parameters:
context
- the context of the repr.- Returns:
- the matching result
-
create
-
getArrayDimension
-
fromSource
- Overrides:
fromSource
in classGuiReprValue
- 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
- Overrides:
toSource
in classGuiReprValue
- 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
-
getElementValueContext
-
toUpdateValue
Description copied from class:GuiReprValue
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.- Overrides:
toUpdateValue
in classGuiReprValue
- Parameters:
context
- the context of the repr.newValue
- the current value- Returns:
- the updated value
-
getValueCollectionSize
public int getValueCollectionSize(GuiMappingContext context, GuiMappingContext.GuiSourceValue collection, GuiReprValue.ObjectSpecifier specifier) throws Throwable Description copied from class:GuiReprValue
a table pane returns the size of a collection- Overrides:
getValueCollectionSize
in classGuiReprValue
- 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
-
getValueCollectionElement
public GuiUpdatedValue getValueCollectionElement(GuiMappingContext context, GuiMappingContext.GuiSourceValue collection, GuiReprValue.ObjectSpecifier elementSpecifier, GuiMappingContext.GuiSourceValue prev) Description copied from class:GuiReprValue
a table pane returns an element in a collection- Overrides:
getValueCollectionElement
in classGuiReprValue
- 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
-
updateCollectionElement
public Object updateCollectionElement(GuiMappingContext context, GuiMappingContext.GuiSourceValue collection, Object newValue, GuiReprValue.ObjectSpecifier elementSpecifier) throws Throwable Description copied from class:GuiReprValue
a table pane updates a specified element- Overrides:
updateCollectionElement
in classGuiReprValue
- 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
-
toJson
Description copied from interface:GuiRepresentation
convert the source into JSON format- Specified by:
toJson
in interfaceGuiRepresentation
- Overrides:
toJson
in classGuiReprValue
- Parameters:
context
- a context holds the representationsource
- the converted object- Returns:
- List: { elementJson, ... }. Note: null elements are skipped
-
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
- Overrides:
fromJson
in classGuiReprValue
- 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.
-
getElementContext
-
isJsonSetter
public boolean isJsonSetter()- Returns:
- true means
GuiRepresentation.fromJson(GuiMappingContext, Object, Object)
takes a target object and set json properties to the target. otherwise, the method will return a new value, thus the target can be null
-
toHumanReadableString
Description copied from interface:GuiRepresentation
method for constructing "toString" copy operations: the returned string will be separated by tabs and new-lines- Parameters:
context
- the context of the repr.source
- converted to string- Returns:
- a string representation of the source
-
fromHumanReadableString
-
isHistoryValueSupported
public boolean isHistoryValueSupported()- Overrides:
isHistoryValueSupported
in classGuiReprValue
- Returns:
- if true,
GuiReprValue.updateFromGui(GuiMappingContext, Object, ObjectSpecifier, GuiTaskClock)
automatically add the value to the preferences. the default impl. returns true.
-
isHistoryValueStored
- Overrides:
isHistoryValueStored
in classGuiReprValue
- Parameters:
value
- the tested value, or null at loading- Returns:
- if true, actually the value is stored to the preferences store
-
toString
- Overrides:
toString
in classGuiReprValue
-