Module org.autogui

Class GuiReprActionList

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

public class GuiReprActionList extends Object implements GuiRepresentation
the abstract action definition for a list (an action taking a list as its argument)
     @GuiIncluded
     public class C {
         @GuiIncluded
         public List<String> list = new ArrayList<>();

         @GuiIncluded
         void action(List<String> selectedItemsInList) {
             ...
         }
     }
 

actions taking List<Integer> will receive indices of selected rows.

     @GuiIncluded
     public class C {
         @GuiIncluded
         public List<String> list = new ArrayList<>();

         @GuiIncluded
         void action(List<Integer> selectedRowsInList) {
             ...
         }
     }
 
For tables of List<Integer>, the action will always take indices of selected rows.

in order to handle multiple lists, the action can take the second argument for receiving the name of the target list.

          @GuiIncluded
          public List<String> listA = new ArrayList<>();
          @GuiIncluded
          public List<String> listB = new ArrayList<>();

          @GuiIncluded
          void action(List<String> selectedItemsInList, String name) {
              if (name.equals("listA") {
                  ...
              } else {
                  ...
              }
          }
   

automatic selection callback: the action with GuiListSelectionCallback will be automatically invoked when a user selects some items in the list.

        @GuiListSelectionCallback
        @GuiIncluded
        public void action(List<String> items) {
            ...
        }
    

list selection changer: the action with GuiListSelectionUpdater can specify the next selected items after execution of the action.

       @GuiListSelectionUpdater
       @GuiIncluded
       public List<String> action(List<String> items) {
              ...
       }
   
  • Constructor Details

    • GuiReprActionList

      public GuiReprActionList()
  • Method Details

    • match

      public boolean match(GuiMappingContext context)
      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 interface GuiRepresentation
      Parameters:
      context - the context of the repr.
      Returns:
      the matching result
    • checkAndUpdateSource

      public boolean checkAndUpdateSource(GuiMappingContext context)
      Description copied from interface: GuiRepresentation
      invoke the associated method and check the returned value whether it is updated or not. if updated, set the source of context to the value. This is non-recursive operation; GuiMappingContext recursively calls this method. The source of parent is already updated by the order of the calls.
      Specified by:
      checkAndUpdateSource in interface GuiRepresentation
      Parameters:
      context - the context of the repr.
      Returns:
      the representation is updated or not
    • executeActionForList

      public Object executeActionForList(GuiMappingContext context, List<?> selection, String targetName, GuiReprValue.ObjectSpecifier targetSpecifier)
      the action executor relying on GuiMappingContext.execute(Callable).
      Parameters:
      context - the context
      selection - the parameter
      targetName - the name of the target list
      targetSpecifier - the specifier for the target object
      Returns:
      result of execution or null
    • executeActionForList

      public Object executeActionForList(GuiMappingContext context, Object target, List<?> selection, String targetName)
    • toJson

      public Object toJson(GuiMappingContext context, Object source)
      Description copied from interface: GuiRepresentation
      convert the source into JSON format
      Specified by:
      toJson in interface GuiRepresentation
      Parameters:
      context - a context holds the representation
      source - the converted object
      Returns:
      JSON objects representing the source; String, Number, Boolean, List, Map or null
    • fromJson

      public Object fromJson(GuiMappingContext context, Object target, Object json)
      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 by GuiRepresentation.isJsonSetter().
      Specified by:
      fromJson in interface GuiRepresentation
      Parameters:
      context - a context holds the representation
      target - the target object or null
      json - JSON objects representing the target String, Number, Boolean, List, Map or null
      Returns:
      created object from the json, target if provided, or null.
    • isAutomaticSelectionAction

      public boolean isAutomaticSelectionAction(GuiMappingContext context)
    • isSelectionAction

      public boolean isSelectionAction(GuiMappingContext context, GuiMappingContext tableContext)
           //@GuiListSelectionCallback(index=true) //for automatic selection
           public void select(List<E> list) {...}
           public void select(List<E> list, String propName) {...}
       
      Parameters:
      context - the action context
      tableContext - context for the target element of list
      Returns:
      true if the action is taking a list of selected row values
    • isSelectionRowIndicesAction

      public boolean isSelectionRowIndicesAction(GuiMappingContext context)
           //@GuiListSelectionCallback(index=true) //for automatic selection
           public void select(List<Integer> rows) {...}
           public void select(List<Integer> rows, String propName) {...}
       
      Parameters:
      context - the action context
      Returns:
      true if the action is automatic selection and taking a list of row indices
    • isSelectionRowAndColumnIndicesAction

      public boolean isSelectionRowAndColumnIndicesAction(GuiMappingContext context)
           //@GuiListSelectionCallback(index=true) //for automatic selection
           public void select(List<int[]> rows) {...}
           public void select(List<int[]> rows, String propName) {...}
       
      Parameters:
      context - the action context
      Returns:
      true if the action is automatic selection and taking a list of row and column pair indices
    • getRowAndColumnIndicesType

      public static GuiTypeElement getRowAndColumnIndicesType()
    • isSelectionChangeAction

      public boolean isSelectionChangeAction(GuiMappingContext context, GuiMappingContext tableContext)
           @GuiListSelectionUpdater
           public Collection<E> select(List<E> items) { ... }
       
      Parameters:
      context - context of the action
      tableContext - table context
      Returns:
      true if matched
    • isSelectionChangeRowIndicesAction

      public boolean isSelectionChangeRowIndicesAction(GuiMappingContext context)
           @GuiListSelectionUpdater(index=true)
           public Collection<Integer> select(List<Integer> rows) { ... }
       
      Parameters:
      context - context of the action
      Returns:
      true if matched
    • isSelectionChangeRowAndColumnIndicesAction

      public boolean isSelectionChangeRowAndColumnIndicesAction(GuiMappingContext context)
           @GuiListSelectionUpdater(index=true)
           public Collection<int[]> select(List<int[]> indices) { ... }
       
      Parameters:
      context - context of the action
      Returns:
      true if matched
    • isSelectionChangeActionForActions

      public static boolean isSelectionChangeActionForActions(GuiMappingContext context, GuiMappingContext tableContext)
           @GuiListSelectionUpdater
           public Collection<E> select(...) { ... }
       
      Parameters:
      context - context of the action
      tableContext - table context
      Returns:
      true if matched
    • isCollectionType

      public static boolean isCollectionType(GuiTypeElement testedCollectionType, GuiTypeElement elementType)
    • isSelectionChangeRowIndicesActionForActions

      public static boolean isSelectionChangeRowIndicesActionForActions(GuiMappingContext context)
    • isSelectionChangeRowAndColumnIndicesActionForActions

      public static boolean isSelectionChangeRowAndColumnIndicesActionForActions(GuiMappingContext context)
    • isSelectionChangeTargetForActions

      public static boolean isSelectionChangeTargetForActions(GuiMappingContext context, GuiMappingContext tableContext)
      matching the action target name with the table property name (parent of the tableContext)
      Parameters:
      context - the action context
      tableContext - the target table-context
      Returns:
      the target-name of the context (obtained from GuiListSelectionUpdater.target() or the method name "select...") is equals to the table property name (parent name of the tableContext)
      Since:
      1.5
    • toString

      public String toString()
      Overrides:
      toString in class Object