Module org.autogui

Class GuiReprCollectionTable

java.lang.Object
org.autogui.base.mapping.GuiReprValue
org.autogui.base.mapping.GuiReprCollectionTable
All Implemented Interfaces:
GuiRepresentation

public class GuiReprCollectionTable extends GuiReprValue
representation for 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: For O,

       (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 a CollectionTable (a subclass of JTable): the model is customized as it's row source is a list obtained from the context. The table is a GuiMappingContext.SourceUpdateListener and registered to the context.
    • GuiSwingCollectionTable constructs columns by GuiSwingTableColumnSet#createColumns(...)
    • GuiSwingTableColumnSet calls createColumn(subContext,...) to sub-contexts GuiSwingTableColumn and adds the returned TableColumn to the model.
  • getValue and update
For SL,
      (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) {}
                  }
              }
          }
      }