Module org.autogui

Class GuiMappingContext

java.lang.Object
org.autogui.base.mapping.GuiMappingContext

public class GuiMappingContext extends Object
a tree node describing a mapping between GuiTypeElement and GuiRepresentation. The tree constructs an abstract GUI representation of an object tree (like HTML DOM tree).

First, an instance of this class is created with a GuiTypeElement tree of a target object: GuiMappingContext(GuiTypeElement). The type-element tree can be obtained by GuiTypeBuilder.

Second, GuiReprSet receives the unmapped context object, and constructs sub-trees. The sub-trees are created by using createChildCandidates() and matched with GuiReprSet.match(GuiMappingContext). The only matched sub-context becomes an actual child of a context by addToParent(). Also, if matched, the context becomes to have a GuiRepresentation. The entry point of construction can be the match method of GuiRepresentation.getDefaultSet().

Third, concrete entities of GuiRepresentations, like GuiSwingView, can create concrete GUI components. Then the components can compute updating of their displays by using retained mapped objects and listeners, which can be obtained by getSource() and getListeners().

  1. a GUI component can call updateSourceFromRoot(GuiMappingContext) with passing an associated context. Note, updateSourceFromRoot()) is the no-source version and can be used for obtaining initial values.
  2. The method obtains the root context by getRoot(),
  3. and traverses the tree and collects updated contexts, by collectUpdatedSource(GuiMappingContext, List).
  4. GuiRepresentation.checkAndUpdateSource(GuiMappingContext) do the actual computation of checking the update.
  5. After that, GuiMappingContext.SourceUpdateListener.update(GuiMappingContext, Object, GuiTaskClock) of each updated context will be called.

getType...(), isType...() check and obtain typeElement as a specified type. isParent...() check the type of the parent.

  • Field Details

  • Constructor Details

  • Method Details

    • getContextClock

      public GuiTaskClock getContextClock()
    • setRepresentation

      public void setRepresentation(GuiRepresentation representation)
    • getTypeElement

      public GuiTypeElement getTypeElement()
    • getRepresentation

      public GuiRepresentation getRepresentation()
    • getChildren

      public List<GuiMappingContext> getChildren()
    • getParent

      public GuiMappingContext getParent()
    • createChildCandidates

      public List<GuiMappingContext> createChildCandidates()
    • getChildrenForAdding

      public List<GuiMappingContext> getChildrenForAdding()
    • createChildCandidate

      public GuiMappingContext createChildCandidate(GuiTypeElement typeElement)
    • addToParent

      public void addToParent()
    • isRecursive

      public boolean isRecursive()
    • getRoot

      public GuiMappingContext getRoot()
    • hasParent

      public boolean hasParent()
    • getName

      public String getName()
      Returns:
      the name of typeElement
    • getDescription

      public String getDescription()
    • getAcceleratorKeyStroke

      public String getAcceleratorKeyStroke()
    • isAcceleratorKeyStrokeSpecified

      public boolean isAcceleratorKeyStrokeSpecified()
    • isTypeElementProperty

      public boolean isTypeElementProperty()
    • getTypeElementPropertyTypeAsClass

      public Class<?> getTypeElementPropertyTypeAsClass()
    • isTypeElementAction

      public boolean isTypeElementAction()
    • isTypeElementActionList

      public boolean isTypeElementActionList()
    • isTypeElementObject

      public boolean isTypeElementObject()
    • isTypeElementValue

      public boolean isTypeElementValue()
      Returns:
      includes GuiTypeObject and GuiTypeCollection which are subtypes of GuiTypeValue
    • isTypeElementCollection

      public boolean isTypeElementCollection()
    • getTypeElementValueAsClass

      public Class<?> getTypeElementValueAsClass()
    • getTypeElementAsProperty

      public GuiTypeMemberProperty getTypeElementAsProperty()
    • getTypeElementAsAction

      public GuiTypeMemberAction getTypeElementAsAction()
    • getTypeElementAsActionList

      public GuiTypeMemberActionList getTypeElementAsActionList()
    • getTypeElementCollection

      public GuiTypeCollection getTypeElementCollection()
    • getTypeElementValue

      public GuiTypeValue getTypeElementValue()
    • getTypeElementObject

      public GuiTypeObject getTypeElementObject()
      Returns:
      typeElement as type-object
      Since:
      1.2
    • setSource

      public void setSource(GuiMappingContext.GuiSourceValue source)
      only set the source value
      Parameters:
      source - the source
    • getSource

      Returns:
      actual value of the context
    • addSourceUpdateListener

      public void addSourceUpdateListener(GuiMappingContext.SourceUpdateListener listener)
    • removeSourceUpdateListener

      public void removeSourceUpdateListener(GuiMappingContext.SourceUpdateListener listener)
    • getListeners

    • updateSourceFromGui

      public void updateSourceFromGui(Object newValue)
      set the source to newValue, call updateSourceFromRoot(GuiMappingContext) starting with this. Note: the method does not update any properties of parent or other source objects The clock is already set.
      Parameters:
      newValue - the new source value to be set
    • updateSourceFromGuiByThisDelayed

      public void updateSourceFromGuiByThisDelayed()
    • updateSourceFromRoot

      public void updateSourceFromRoot()
      updateSourceFromGui(Object) with the null cause
    • updateSourceFromRoot

      public void updateSourceFromRoot(GuiMappingContext cause)
      obtains the root context, recursively collect updated sub-contexts from the root, and call listeners with each updated context.
      Parameters:
      cause - the cause of the updating process, and the process avoids to update the context.
    • sendUpdateToListeners

      public void sendUpdateToListeners(GuiMappingContext cause)
    • clearSourceSubTree

      public void clearSourceSubTree()
    • updateSourceSubTree

      public void updateSourceSubTree()
      recursively collect updated sub-contexts from this and call listeners
    • collectUpdatedSource

      public void collectUpdatedSource(GuiMappingContext cause, List<GuiMappingContext> updated)
      recursively call GuiRepresentation.checkAndUpdateSource(GuiMappingContext): the checkAndUpdateSource invokes the getter of the target source object in order to update the value.

      the recursion can be controlled by GuiRepresentation.continueCheckAndUpdateSourceForChildren(GuiMappingContext, boolean): this is used for avoiding recursion of list elements.

      the method alone does not cause GUI updates because of no listener calls

      Parameters:
      cause - the cause context
      updated - the list which the updated contexts will be added
    • getDisplayName

      public String getDisplayName()
      Returns:
      space separated words from the camel-case context name e.g. "myPropName" -> "My Prop Name"
    • getIconName

      public String getIconName()
      Returns:
      the top word of the split name, which is an action verb in most cases: e.g. "getProp" -> "get"
    • nameJoinForDisplay

      public String nameJoinForDisplay(List<String> words)
    • nameSplit

      public static List<String> nameSplit(String name, boolean forDisplay)
      split a name to a list of words by camel case.
      Parameters:
      name - the split name
      forDisplay - if true,
        "helloWorld" => ["hello", "World"]
        "HelloWorld" => ["Hello", "World"]
        "helloWORLD" => ["hello", "WORLD"]
        "HELLOWorld" => ["HELLO", "World"]
        "" => [""]
       
      Returns:
      the split list, never null If forDisplay=false, "MYName" => ["M", "Y", "Name"]
    • isNameCharUpper

      public static boolean isNameCharUpper(char c, int i, int len, String name, boolean forDisplay)
    • isNameSeparator

      public static boolean isNameSeparator(char c)
    • errorWhileUpdateSource

      public void errorWhileUpdateSource(Throwable error)
      notify to GuiLogManager
      Parameters:
      error - the reported error
    • errorWhileJson

      public void errorWhileJson(Throwable error)
    • isParentPropertyPane

      public boolean isParentPropertyPane()
    • getParentRepresentation

      public GuiRepresentation getParentRepresentation()
    • getParentPropertyPane

      public GuiReprPropertyPane getParentPropertyPane()
    • isParentValuePane

      public boolean isParentValuePane()
    • isReprValue

      public boolean isReprValue()
    • getReprValue

      public GuiReprValue getReprValue()
    • getParentValuePane

      public GuiReprValue getParentValuePane()
    • getParentCollectionTable

      public GuiReprCollectionTable getParentCollectionTable()
    • getParentCollectionElement

      public GuiReprCollectionElement getParentCollectionElement()
    • getParentSource

      public GuiMappingContext.GuiSourceValue getParentSource()
    • isReprAction

      public boolean isReprAction()
    • isReprActionList

      public boolean isReprActionList()
    • getReprAction

      public GuiReprAction getReprAction()
    • getReprActionList

      public GuiReprActionList getReprActionList()
    • isParentCollectionTable

      public boolean isParentCollectionTable()
    • isReprCollectionTable

      public boolean isReprCollectionTable()
    • getReprCollectionTable

      public GuiReprCollectionTable getReprCollectionTable()
    • isParentCollectionElement

      public boolean isParentCollectionElement()
    • isReprCollectionElement

      public boolean isReprCollectionElement()
    • getReprCollectionElement

      public GuiReprCollectionElement getReprCollectionElement()
    • isHistoryValueSupported

      public boolean isHistoryValueSupported()
    • isHistoryValueStored

      public boolean isHistoryValueStored(Object value)
    • getTaskRunner

      Returns:
      taskRunner taken from parent context or single thread executor in the root.
      See Also:
    • shutdown

      public void shutdown()
      call shutdownTaskRunner() and also close the target if the target is an AutoCloseable
    • shutdownAutoCloseable

      public void shutdownAutoCloseable()
    • shutdownAutoCloseableSubTree

      protected void shutdownAutoCloseableSubTree()
    • shutdownTaskRunner

      public void shutdownTaskRunner()
    • shutdownTaskRunnerSubTree

      protected void shutdownTaskRunnerSubTree()
    • execute

      public <T> T execute(Callable<T> task) throws Throwable
      run the task. used for wrapping tasks that execute type-element's actions
      Type Parameters:
      T - the returned type
      Parameters:
      task - the task to be executed
      Returns:
      the returned value of the task
      Throws:
      Throwable - an exception from the task
    • getDelayedTaskRunner

      public ScheduledTaskRunner<GuiMappingContext.DelayedTask> getDelayedTaskRunner()
      task runner for deferring frequent events and dispatching with accumulated events
      Returns:
      the runner created as a root or obtained from the parent
    • executeAccumulated

      public void executeAccumulated(List<GuiMappingContext.DelayedTask> list)
    • getPreferences

      public GuiPreferences getPreferences()
      Returns:
      obtains from the parent. a preference object occasionally cleared from the parent context. so it does not recommend to hold the returned instance.
    • clearPreferences

      public void clearPreferences()
    • setPreferences

      public void setPreferences(GuiPreferences preferences)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getChildByName

      public GuiMappingContext getChildByName(String name)
      Parameters:
      name - the name
      Returns:
      a child whose name is the name
    • getValue

      public Object getValue(GuiReprValue.ObjectSpecifier specifier)
      Parameters:
      specifier - the specifier for the value
      Returns:
      get current value of the associated property obtaining through GuiReprValue (can be checked by isReprValue()) from current value of the parent.
    • executeAction

      public Object executeAction(GuiReprValue.ObjectSpecifier targetSpecifier)
      execute the associated action through GuiReprAction (can be checked by isReprAction()) otherwise throw an exception. the method causes same effects by GUI operation, i.e. updating other components.
      Parameters:
      targetSpecifier - the specifier for the target object
      Returns:
      result of execution
    • setNotifiers

      public void setNotifiers(Object target)
      set appropriate notifiers to the target if defined
      Parameters:
      target - the target object obtained from the source of the context. nullable
      Since:
      1.2
    • setNotifier

      public void setNotifier(Object target, GuiTypeMemberPropertyNotifier notifier)
      set notifier to the target member of the target object, determined from the parameter of the annotation
      Parameters:
      target - the target object obtained from the source of the context
      notifier - the notifier property
      Since:
      1.2
    • getNotifierForTarget

      public Runnable getNotifierForTarget(boolean fromRoot)
      Parameters:
      fromRoot - true if the entire pane of the context
      Returns:
      a GuiMappingContext.ContextNotifier
      Since:
      1.2