- 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 }:
GuiMappingContextwhere 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:GuiSwingCollectionTablecreates aCollectionTable(a subclass ofJTable): the model is customized as it's row source is a list obtained from the context. The table is aGuiMappingContext.SourceUpdateListenerand registered to the context.GuiSwingCollectionTableconstructs columns byGuiSwingTableColumnSet#createColumns(...)GuiSwingTableColumnSetcallscreateColumn(subContext,...)to sub-contexts GuiSwingTableColumn and adds the returned TableColumn to the model.
getValue and updateObjectTableModelfirst obtains row list viaCollectionTable#getSource(): it returnssourcepreviously 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 classa list wraps an array.static classa selected cell valuestatic interfacein order to support arrays, the table-representation use a converter for input/output of values.static classa converter for arrays: converting between a wrapping list and an arraystatic classa converter for list object.static interfaceinterface for actions which handle selected-rows; an actual implementation relies on a concrete GUI componentstatic interfacea subtype of table-target, also supporting selecting partial columns; in the type,GuiReprCollectionTable.TableTarget.getSelectedCells()returns the values of the partial columns.static interfacean interface for operating a specific column with selected rowsstatic classa 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.ObjectSpecifierNothingNested classes/interfaces inherited from interface org.autogui.base.mapping.GuiRepresentation
GuiRepresentation.GuiReprNone, GuiRepresentation.TreeString, GuiRepresentation.TreeStringComposite, GuiRepresentation.TreeStringValue -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected GuiReprCollectionTable.ListConverterprotected GuiRepresentationFields 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) intgetArrayDimension(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 collectionintgetValueCollectionSize(GuiMappingContext context, GuiMappingContext.GuiSourceValue collection, GuiReprValue.ObjectSpecifier specifier) a table pane returns the size of a collectionbooleanisHistoryValueStored(Object value) booleanbooleanbooleanmatch(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 *toHumanReadableStringTree(GuiMappingContext context, Object source) toJson(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, updateWithParentSourceMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.autogui.base.mapping.GuiRepresentation
continueCheckAndUpdateSourceForChildren, fromJsonWithNamed, isTaskRunnerUsedFor, matchAndSetNotifiersAsInit, setNotifiersTree, shutdown, toHumanReadableString, 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:GuiRepresentationmatch 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:
matchin interfaceGuiRepresentation- Overrides:
matchin classGuiReprValue- Parameters:
context- the context of the repr.- Returns:
- the matching result
-
create
-
getArrayDimension
-
fromSource
- Overrides:
fromSourcein 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:
toSourcein 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:GuiReprValuecalled 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:
toUpdateValuein 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:GuiReprValuea table pane returns the size of a collection- Overrides:
getValueCollectionSizein 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:GuiReprValuea table pane returns an element in a collection- Overrides:
getValueCollectionElementin classGuiReprValue- Parameters:
context- the context of the reprcollection- a collection targetelementSpecifier- an element index i.e.GuiReprValue.ObjectSpecifierIndexprev- 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:GuiReprValuea table pane updates a specified element- Overrides:
updateCollectionElementin 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:GuiRepresentationconvert the source into JSON format- Specified by:
toJsonin interfaceGuiRepresentation- Overrides:
toJsonin classGuiReprValue- Parameters:
context- a context holds the representationsource- the converted object- Returns:
- List: { elementJson, ... }. Note: null elements are skipped
-
fromJson
Description copied from interface:GuiRepresentationcreate 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:
fromJsonin interfaceGuiRepresentation- Overrides:
fromJsonin classGuiReprValue- Parameters:
context- a context holds the representationtarget- the target object or nulljson- JSON objects representing the targetString,Number,Boolean,List,Mapor 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
-
toHumanReadableStringTree
public GuiRepresentation.TreeString toHumanReadableStringTree(GuiMappingContext context, Object source) - Parameters:
context- the context of the reprsource- convert to string- Returns:
- tree string of source, can be encoded by
Object.toString()(used byGuiRepresentation.toHumanReadableString(GuiMappingContext, Object)
-
fromHumanReadableString
-
isHistoryValueSupported
public boolean isHistoryValueSupported()- Overrides:
isHistoryValueSupportedin classGuiReprValue- Returns:
- if true,
GuiReprValue.updateFromGui(GuiMappingContext, Object, ObjectSpecifier, GuiTaskClock)automatically add the value to the preferences. the default impl. returns true.
-
isHistoryValueStored
- Overrides:
isHistoryValueStoredin classGuiReprValue- Parameters:
value- the tested value, or null at loading- Returns:
- if true, actually the value is stored to the preferences store
-
toString
- Overrides:
toStringin classGuiReprValue
-