Package sc.bind

Class VariableBinding

  • All Implemented Interfaces:
    IBinding, IListener
    Direct Known Subclasses:

    public class VariableBinding
    extends DestinationListener
    VariableBinding manages an instance of a binding expression like "a.b.c". It has a direction attribute - for which way to apply the binding: forward, reverse, or bi-directional. It has a list of the properties "a.b.c" in the binding. It computes the current array of intermediate or last known values of the binding and stores them in the bound values. The dstObj is the object who "owns" the binding - the one which defined it. If this is the top-level binding in an expression, the dstObj is the object which defined the expression. If not, the dstObj is the parent object in the binding expression. In this case, the dstProp==dstObj. The binding is applied to the destination property which we store both in terms of its property id and the index of that property in the property table of the dstObj's type.

    The bound parent is the evaluated parent of the leaf reference. It is not the value of the binding, but the object whose property is being bound to. If we are evaluating the reverse binding, we are setting a property on the bound parent. The bound value is the current value of the binding.

    If any node along the binding chain evaluated to null, the bound value is null.

    As intermediate nodes change, we have to remove and re-add our listeners on the intermediate objects. If the binding is a forward binding, we add listeners onto the boundProps and cache the binding's current state in the boundValues array. If the binding is reverse only, we do not cache the values - instead they are evaluated each time the binding fires.

    • Constructor Detail

      • VariableBinding

        public VariableBinding​(java.lang.Object srcObject,
                               java.lang.Object[] boundProperties)
        Use this form for chaining together this binding with another binding
      • VariableBinding

        public VariableBinding​(java.lang.Object dstObject,
                               IBinding dstProperty,
                               java.lang.Object srcObject,
                               java.lang.Object[] boundProperties,
                               BindingDirection bindingDirection,
                               int flags,
                               BindOptions opts)
        Use this form for a top level binding
    • Method Detail

      • setBindingParent

        public void setBindingParent​(IBinding parent,
                                     BindingDirection dir)
        Called by the parent when this is a hierarchical binding - i.e. one expression in another
      • initializeBinding

        public java.lang.Object initializeBinding()
        Called to initialize and retrieve the value of a top-level binding
      • initBinding

        protected void initBinding()
      • cacheValue

        protected boolean cacheValue()
      • reactivate

        protected void reactivate​(java.lang.Object obj)
      • getNumInChain

        public int getNumInChain()
        Number of properties in the binding - e.g. a.b.c = 3
      • getChainElement

        public java.lang.Object getChainElement​(int ix)
        Returns the String property name, IBinding, or IBeanMapper
      • getBoundProperty

        protected java.lang.Object getBoundProperty()
        Returns the last property in the chain
      • getBoundParent

        protected java.lang.Object getBoundParent()
        Returns the parent of the last value
      • getBoundValue

        protected java.lang.Object getBoundValue​(boolean pendingChild)
      • removeListener

        public void removeListener()
      • valueRequested

        public void valueRequested​(java.lang.Object obj,
                                   IBeanMapper prop)
      • getBoundProperty

        protected java.lang.Object getBoundProperty​(java.lang.Object bindingParent,
                                                    int i)
      • validateBinding

        protected boolean validateBinding()
      • validateBinding

        protected boolean validateBinding​(int validateTo)
      • bindingInvalidated

        protected void bindingInvalidated​(boolean apply)
      • sameValues

        protected boolean sameValues​(int index,
                                     java.lang.Object newValue)
      • equalValues

        protected boolean equalValues​(int index,
                                      java.lang.Object newValue)
      • applyReverseBinding

        protected boolean applyReverseBinding()
      • getReads

        public ISet<java.lang.Object> getReads()
      • getWrites

        public ISet<java.lang.Object> getWrites()
      • invalidateBinding

        public void invalidateBinding​(java.lang.Object obj,
                                      boolean sendEvent,
                                      int event,
                                      boolean includeParams)
      • applyBinding

        public boolean applyBinding​(java.lang.Object obj,
                                    java.lang.Object value,
                                    IBinding src,
                                    boolean refresh,
                                    boolean pendingChild)
      • applyReverseBinding

        public void applyReverseBinding​(java.lang.Object obj,
                                        java.lang.Object value,
                                        java.lang.Object src)
      • getPropertyValue

        public java.lang.Object getPropertyValue​(java.lang.Object obj,
                                                 boolean getField,
                                                 boolean pendingChild)
        Description copied from interface: IBinding
        Retrieves the current value of the binding given the current object. Use getField = true to force use of the field, rather than the getX method if one exists. Use pendingChild = true for a special case where we are getting the property value of a binding that is part of a reverse binding but where the cached value is up-to-update because we are updating a child remote property.
      • addBindingListener

        public void addBindingListener​(java.lang.Object eventObject,
                                       IListener listener,
                                       int event)
        These are implemented for VariableBindings but not for AbstractMethodBindings. These listeners are invoked when the previous binding in the chain's value changes. Since the bound props of the variable binding depend on the value of the previous value, we need to remove/re-add them on any upstream change. Method parameters listeners do not respond to changes in the previous value so they don't implement this method.
      • removeBindingListener

        public void removeBindingListener​(java.lang.Object eventObject,
                                          IListener listener,
                                          int event)
      • isConstant

        public boolean isConstant()
      • toString

        public java.lang.String toString​(java.lang.String operation,
                                         boolean displayValue)
        toString in class DestinationListener
      • activate

        public void activate​(boolean state,
                             java.lang.Object obj,
                             boolean chained)
        Description copied from interface: IBinding
        Called to deactive/re-activate a child binding for a condition or ternary expression
        Specified by:
        activate in interface IBinding
        activate in class AbstractListener
      • isReversible

        public boolean isReversible()