Package sc.bind

Class Bind


  • public class Bind
    extends java.lang.Object
    This is the main entry point for 'data binding'. It contains static methods which you can use to create bindings on objects and properties from the API. These static methods are used in the generated code to implement all bindings so it's easy to find examples by looking at the generated source. To create a simple binding use the Bind.bind() method. You provide the destination object (i.e. the lhs), the name or property mapper for the destination property, the srcObject (if any) used in mapping the binding, and the list of properties in the chain (i.e. "a" and "b" in an a.b binding). Each binding can either be specified as the String name of the property or you can find the IBeanMapper and pass that in. When you use the IBeanMapper, lookups will be faster since an integer index is used rather than the String to do a hashtable lookup. You also specify the BindingDirection - forward, reverse or bidirectional.

    The other types of bindings - method, arithmetic, cast, unary, condition, ternary, arrayElement, new and newArray. There's also a constant binding you can use when you need to substitute a constant in an expression. Finally there's an assignment binding which is used most commonly in reverse-only bindings to perform an assignment when the binding is fired.

    SC developers note: When you add new code to the core runtime (i.e. used by GWT or other non-reflective runtimes), you must add the package name to the jarPackages. You also must change the Bind's CompilerSettings in the full runtime and the StrataCode.gwt.xml file in the core src root folder.

    • Field Detail

      • INACTIVE

        public static int INACTIVE
        These are option flags you can combine in the flags argument to various calls to create bindings. Settable via @Bindable using code-generation
      • TRACE

        public static int TRACE
        These are option flags you can combine in the flags argument to various calls to create bindings. Settable via @Bindable using code-generation
      • VERBOSE

        public static int VERBOSE
        These are option flags you can combine in the flags argument to various calls to create bindings. Settable via @Bindable using code-generation
      • QUEUED

        public static int QUEUED
        These are option flags you can combine in the flags argument to various calls to create bindings. Settable via @Bindable using code-generation
      • IMMEDIATE

        public static int IMMEDIATE
        These are option flags you can combine in the flags argument to various calls to create bindings. Settable via @Bindable using code-generation
      • CROSS_SCOPE

        public static int CROSS_SCOPE
        These are option flags you can combine in the flags argument to various calls to create bindings. Settable via @Bindable using code-generation
      • DO_LATER

        public static int DO_LATER
        These are option flags you can combine in the flags argument to various calls to create bindings. Settable via @Bindable using code-generation
      • HISTORY

        public static int HISTORY
        These are option flags you can combine in the flags argument to various calls to create bindings. Settable via @Bindable using code-generation
      • ORIGIN

        public static int ORIGIN
        These are option flags you can combine in the flags argument to various calls to create bindings. Settable via @Bindable using code-generation
      • SKIP_NULL

        public static int SKIP_NULL
        These are option flags you can combine in the flags argument to various calls to create bindings. Settable via @Bindable using code-generation
      • bindingContainerRegistry

        public static final java.util.Map<java.lang.Object,​java.util.List<DestinationListener>> bindingContainerRegistry
        For objects which do not implement IBindingContainer, stores the list of bindings set on that instance for each property in a list. This includes forward, bi-directional, and reverse bindings. We do not order the list, so in order to see which property a given binding is set on, you look at the DestinationListener's destination property.
      • bindingListenerRegistry

        public static final java.util.Map<java.lang.Object,​sc.bind.Bind.BindingListenerEntry> bindingListenerRegistry
        Stores a linked list of binding listeners for a given object. The BindingListenerEntry has the array of listeners which is indexed by the property position
      • trace

        public static boolean trace
      • traceAll

        public static boolean traceAll
      • info

        public static boolean info
      • NO_VALUE_EVENT_DETAIL

        public static java.lang.Object NO_VALUE_EVENT_DETAIL
    • Constructor Detail

      • Bind

        public Bind()
    • Method Detail

      • removeListenerOfType

        public static void removeListenerOfType​(java.lang.Object inst,
                                                IBeanMapper prop,
                                                java.lang.Object listenerType,
                                                int valueChangedMask)
      • bind

        public static java.lang.Object bind​(java.lang.Object dstObj,
                                            java.lang.String dstProp,
                                            java.lang.Object srcObj,
                                            java.lang.Object[] boundProps,
                                            BindingDirection dir,
                                            int flags,
                                            BindOptions opts)
        Add a simple binding onto dstProp in dstObj. Returns the initial value of the binding. Takes an optional srcObj to refer to a constant object which starts the "a.b" chain of expressions. Then it takes a list of boundProps - either String names of properties in the chain or IBeanMapper instances or nested bindings using the IBinding implementation (created with the bindP, methodP, etc. method calls). The final parameter is the direction which can be forward, reverse or bi-directional.
      • bind

        public static java.lang.Object bind​(java.lang.Object dstObj,
                                            IBinding dstProp,
                                            java.lang.Object srcObj,
                                            java.lang.Object[] boundProps,
                                            BindingDirection dir,
                                            int flags,
                                            BindOptions opts)
      • bindInt

        public static int bindInt​(java.lang.Object dstObj,
                                  IBinding dstProp,
                                  java.lang.Object srcObj,
                                  java.lang.Object[] boundProps,
                                  BindingDirection dir,
                                  int flags,
                                  BindOptions opts)
      • method

        public static java.lang.Object method​(java.lang.Object dstObj,
                                              java.lang.String dstProp,
                                              java.lang.Object method,
                                              IBinding[] boundArgs,
                                              BindingDirection dir,
                                              int flags,
                                              BindOptions opts)
        Implements a top-level method binding
      • method

        public static java.lang.Object method​(java.lang.Object dstObj,
                                              java.lang.String dstProp,
                                              java.lang.Object methObj,
                                              java.lang.Object method,
                                              IBinding[] boundArgs,
                                              BindingDirection dir,
                                              int flags,
                                              BindOptions opts)
        This variant is used when the method specified is not on the destination object.
      • method

        public static java.lang.Object method​(java.lang.Object dstObj,
                                              IBinding dstProp,
                                              java.lang.Object methObj,
                                              java.lang.Object method,
                                              IBinding[] args,
                                              BindingDirection dir,
                                              int flags,
                                              BindOptions opts)
      • arith

        public static java.lang.Object arith​(java.lang.Object dstObj,
                                             java.lang.String dstProp,
                                             java.lang.String operator,
                                             IBinding[] boundArgs,
                                             BindingDirection dir,
                                             int flags,
                                             BindOptions opts)
      • condition

        public static java.lang.Object condition​(java.lang.Object dstObj,
                                                 java.lang.String dstProp,
                                                 java.lang.String operator,
                                                 IBinding[] boundArgs,
                                                 BindingDirection dir,
                                                 int flags,
                                                 BindOptions opts)
      • unary

        public static java.lang.Object unary​(java.lang.Object dstObj,
                                             java.lang.String dstProp,
                                             java.lang.String operator,
                                             IBinding[] boundArgs,
                                             BindingDirection dir,
                                             int flags,
                                             BindOptions opts)
      • ternary

        public static java.lang.Object ternary​(java.lang.Object dstObj,
                                               java.lang.String dstProp,
                                               IBinding[] boundArgs,
                                               BindingDirection dir,
                                               int flags,
                                               BindOptions opts)
      • arrayElement

        public static java.lang.Object arrayElement​(java.lang.Object dstObj,
                                                    java.lang.String dstProp,
                                                    java.lang.Object srcObj,
                                                    java.lang.Object[] boundArgs,
                                                    IBinding[] arrayDims,
                                                    BindingDirection dir,
                                                    int flags,
                                                    BindOptions opts)
      • arrayElement

        public static java.lang.Object arrayElement​(java.lang.Object dstObj,
                                                    IBinding dstProp,
                                                    java.lang.Object srcObj,
                                                    java.lang.Object[] args,
                                                    IBinding[] arrayDims,
                                                    BindingDirection dir,
                                                    int flags,
                                                    BindOptions opts)
      • cast

        public static java.lang.Object cast​(java.lang.Object dstObj,
                                            java.lang.String dstProp,
                                            java.lang.Class theClass,
                                            IBinding boundArg,
                                            BindingDirection dir,
                                            int flags,
                                            BindOptions opts)
      • selector

        public static java.lang.Object selector​(java.lang.Object dstObj,
                                                java.lang.String dstProp,
                                                java.lang.Object[] boundProps,
                                                BindingDirection dir,
                                                int flags,
                                                BindOptions opts)
      • selector

        public static java.lang.Object selector​(java.lang.Object dstObj,
                                                IBinding dstProp,
                                                java.lang.Object[] boundProps,
                                                BindingDirection dir,
                                                int flags,
                                                BindOptions opts)
      • bindNew

        public static java.lang.Object bindNew​(java.lang.Object dstObj,
                                               java.lang.String dstProp,
                                               java.lang.Object newType,
                                               java.lang.String paramSig,
                                               IBinding[] boundArgs,
                                               BindingDirection dir,
                                               int flags,
                                               BindOptions opts)
      • bindNew

        public static java.lang.Object bindNew​(java.lang.Object dstObj,
                                               IBinding dstProp,
                                               java.lang.Object newType,
                                               java.lang.String paramSig,
                                               IBinding[] args,
                                               BindingDirection dir,
                                               int flags,
                                               BindOptions opts)
      • newArray

        public static java.lang.Object newArray​(java.lang.Object dstObj,
                                                java.lang.String dstProp,
                                                java.lang.Object compType,
                                                IBinding[] boundArgs,
                                                BindingDirection dir,
                                                int flags,
                                                BindOptions opts)
      • assign

        public static java.lang.Object assign​(java.lang.Object dstObj,
                                              java.lang.String dstProp,
                                              java.lang.Object srcObj,
                                              IBinding lhsBinding,
                                              java.lang.Object rhs,
                                              BindingDirection dir,
                                              int flags,
                                              BindOptions opts)
      • assign

        public static java.lang.Object assign​(java.lang.Object dstObj,
                                              IBinding dstProp,
                                              java.lang.Object srcObj,
                                              IBinding lhsBinding,
                                              java.lang.Object rhs,
                                              BindingDirection dir,
                                              int flags,
                                              BindOptions opts)
      • constant

        public static java.lang.Object constant​(java.lang.Object dstObj,
                                                java.lang.String dstProp,
                                                java.lang.Object value,
                                                BindingDirection dir,
                                                int flags,
                                                BindOptions opts)
      • constant

        public static java.lang.Object constant​(java.lang.Object dstObj,
                                                IBinding dstProp,
                                                java.lang.Object value,
                                                BindingDirection dir,
                                                int flags,
                                                BindOptions opts)
      • removePropertyBindings

        public static int removePropertyBindings​(java.lang.Object dstObj,
                                                 java.lang.String propName,
                                                 boolean removeForward,
                                                 boolean removeReverse)
        Removes the bindings on the object specified for the property specified. You may remove just the forward, just the reverse or all types of bindings on this property
      • removePropertyBindings

        public static int removePropertyBindings​(java.lang.Object dstObj,
                                                 IBinding dstProp,
                                                 boolean removeForward,
                                                 boolean removeReverse)
      • bindP

        public static IBinding bindP​(java.lang.Object srcObj,
                                     java.lang.Object[] boundProps)
      • methodP

        public static IBinding methodP​(java.lang.Object method,
                                       IBinding[] boundArgs)
      • methodP

        public static IBinding methodP​(java.lang.Object methObj,
                                       java.lang.Object method,
                                       IBinding[] boundArgs)
      • arithP

        public static IBinding arithP​(java.lang.String operator,
                                      IBinding[] boundArgs)
      • conditionP

        public static IBinding conditionP​(java.lang.String operator,
                                          IBinding[] boundArgs)
      • unaryP

        public static IBinding unaryP​(java.lang.String operator,
                                      IBinding[] boundArgs)
      • arrayElementP

        public static IBinding arrayElementP​(java.lang.Object srcObj,
                                             java.lang.Object[] boundArgs,
                                             IBinding[] arrayDims)
      • castP

        public static IBinding castP​(java.lang.Class theClass,
                                     IBinding boundArg)
      • selectorP

        public static IBinding selectorP​(java.lang.Object[] boundProps)
      • constantP

        public static IBinding constantP​(java.lang.Object value)
      • bindNewP

        public static IBinding bindNewP​(java.lang.Object newClass,
                                        java.lang.String paramSig,
                                        IBinding[] boundProps)
      • newArrayP

        public static IBinding newArrayP​(java.lang.Object newClass,
                                         IBinding[] boundProps)
      • assignP

        public static IBinding assignP​(java.lang.Object srcObj,
                                       IBinding lhsBinding,
                                       java.lang.Object rhsValue)
      • removeBindings

        public static void removeBindings​(java.lang.Object dstObj)
      • removeBindings

        public static void removeBindings​(java.lang.Object dstObj,
                                          boolean removeChildren)
      • refreshBindings

        public static int refreshBindings​(java.lang.Object dstObj)
      • refreshBindings

        public static int refreshBindings​(java.lang.Object dstObj,
                                          boolean refreshChildren)
      • accessBindings

        public static void accessBindings​(java.lang.Object dstObj,
                                          boolean doChildren)
      • refreshBinding

        public static int refreshBinding​(java.lang.Object dstObj,
                                         java.lang.String propName)
        Refreshes the bindings attached to a single named property of the supplied destination object. You can use this to force a specific binding to be re-validated. If the bound value has changed, the destination object's property is updated to the new value.
      • addDynamicListener

        public static void addDynamicListener​(java.lang.Object obj,
                                              java.lang.Object typeObj,
                                              java.lang.String propName,
                                              IListener listener,
                                              int eventMask)
        Like addDynamicListener but takes an explicit type to use for this object. In the case where you might select and retrieve the static properties for a subtype and want to add a listener for those values, you pass in the subtype.
      • addDynamicListener

        public static void addDynamicListener​(java.lang.Object obj,
                                              java.lang.String propName,
                                              IListener listener,
                                              int eventMask)
      • addListener

        public static void addListener​(java.lang.Object obj,
                                       java.lang.Object propObj,
                                       IListener listener,
                                       int eventMask)
      • addListener

        public static void addListener​(java.lang.Object obj,
                                       java.lang.Object propObj,
                                       IListener listener,
                                       int eventMask,
                                       int priority)
      • removeDynamicListener

        public static void removeDynamicListener​(java.lang.Object obj,
                                                 java.lang.String propName,
                                                 IListener listener,
                                                 int eventMask)
      • removeDynamicListener

        public static void removeDynamicListener​(java.lang.Object obj,
                                                 java.lang.Object typeObj,
                                                 java.lang.String propName,
                                                 IListener listener,
                                                 int eventMask)
      • removeListener

        public static void removeListener​(java.lang.Object obj,
                                          java.lang.Object propObj,
                                          IListener listener,
                                          int eventMask)
      • getBindingListeners

        public static BindingListener[] getBindingListeners​(java.lang.Object obj)
      • sendDynamicEvent

        public static void sendDynamicEvent​(int event,
                                            java.lang.Object obj,
                                            java.lang.String propName)
      • sendChangedEvent

        public static void sendChangedEvent​(java.lang.Object obj,
                                            java.lang.String propName)
        The easiest method to send a change event for a given property on a given object. If the property is null, the default event for that object is sent instead. The property supplied must refer to an actual defined property on the object.
      • sendChange

        public static void sendChange​(java.lang.Object obj,
                                      java.lang.String propName,
                                      java.lang.Object val)
        like sendChangedEvent but a shorter name for less JS code. Also takes the value for nice logging.
      • sendInvalidate

        public static void sendInvalidate​(java.lang.Object obj,
                                          java.lang.String propName,
                                          java.lang.Object val)
      • sendValidate

        public static void sendValidate​(java.lang.Object obj,
                                        java.lang.String propName,
                                        java.lang.Object val)
      • sendChange

        public static void sendChange​(java.lang.Object obj,
                                      IBeanMapper prop,
                                      java.lang.Object val)
      • sendEvent

        public static void sendEvent​(int event,
                                     java.lang.Object obj,
                                     java.lang.Object prop)
        Sends the specified event, e.g. value changed to the property of the given object. The event property contains a bit mask of the events to send, constants on the IListener interface, e.g. IListener.VALUE_CHANGED The event mask can contain more than one event. ValueChanged for example sends both value-invalidated and value-validated events. This two pass approach can greatly reduce the number of bindings in complex situations and improves the consistency, getting rid of "validates" that occur with stale values. This variant does not send a "detail value" (used mainly for logging when it's present) For array element changes, you need the location as the detail but the value typically is computed from the binding.
      • sendCompiledChangedEvent

        public static void sendCompiledChangedEvent​(java.lang.Object obj,
                                                    IBeanMapper prop)
        Sends the most common type of event to the object passed. If you provide prop as "null", it acts like the default event for that object.
      • getIndentLevel

        public static int getIndentLevel()
      • logBindingMessage

        public static boolean logBindingMessage​(java.lang.String prefix,
                                                IBinding binding,
                                                java.lang.Object obj,
                                                java.lang.Object val,
                                                java.lang.Object src)
      • logMessage

        public static void logMessage​(java.lang.String prefix,
                                      java.lang.Object obj,
                                      IBeanMapper prop,
                                      java.lang.Object val)
      • logPropMessage

        public static boolean logPropMessage​(java.lang.String prefix,
                                             java.lang.Object obj,
                                             IBeanMapper prop,
                                             java.lang.Object val)
      • endPropMessage

        public static void endPropMessage()
      • sendEvent

        public static void sendEvent​(int event,
                                     java.lang.Object obj,
                                     java.lang.String prop,
                                     java.lang.Object eventDetail)
      • sendEvent

        public static void sendEvent​(int event,
                                     java.lang.Object obj,
                                     IBeanMapper prop,
                                     java.lang.Object eventDetail)
      • sendAllEvents

        public static void sendAllEvents​(int event,
                                         java.lang.Object obj)
        Used to send change events to all properties on "obj"
      • getNestedBindingCount

        public static int getNestedBindingCount()
      • getClassForInstance

        public static java.lang.Class getClassForInstance​(java.lang.Object dstObj)
      • getBinding

        public static DestinationListener getBinding​(java.lang.Object obj,
                                                     java.lang.String prop)
      • hasBindingListeners

        public static boolean hasBindingListeners​(java.lang.Object obj,
                                                  java.lang.String prop)
      • hasBindingListeners

        public static boolean hasBindingListeners​(java.lang.Object obj,
                                                  IBeanMapper prop)
        Returns true for an object and property where there is one or more bindings that listen for changes on that property. If prop is null, we return true if there are listeners for the default value event listener. For static properties, obj should be a class or TypeDeclaration.
      • getPropListeners

        public static BindingListener getPropListeners​(java.lang.Object obj,
                                                       IBeanMapper prop)
        Returns the list of property listeners for a given bean mapper
      • getPropListeners

        public static BindingListener getPropListeners​(java.lang.Object obj,
                                                       BindingListener[] listeners,
                                                       IBeanMapper prop)
        Use this version when you have already called getBindingListeners and so have the array of listeners to get the list of listeners for more than one property in the object more efficiently.
      • destinationListenerArrayToString

        public static java.lang.String destinationListenerArrayToString​(java.lang.Object theObj,
                                                                        DestinationListener[] bindingListeners)
      • listenerArrayToString

        public static java.lang.String listenerArrayToString​(java.lang.Object theObj,
                                                             BindingListener[] bindingListeners)
      • printBindings

        public static void printBindings​(java.lang.Object obj)
      • printAllBindings

        public static void printAllBindings()
      • indent

        public static java.lang.String indent​(int n)
      • arrayToString

        public static java.lang.String arrayToString​(java.lang.Object[] list)
      • setBindingParent

        public static void setBindingParent​(java.lang.Object prop,
                                            IBinding parent,
                                            BindingDirection dir)
      • activate

        public static void activate​(java.lang.Object prop,
                                    boolean state,
                                    java.lang.Object bindingParent,
                                    boolean chained)
      • applyReverseBinding

        public static void applyReverseBinding​(java.lang.Object obj,
                                               java.lang.Object prop,
                                               java.lang.Object value,
                                               java.lang.Object src)
      • applyBinding

        public static void applyBinding​(java.lang.Object obj,
                                        java.lang.Object prop,
                                        java.lang.Object value,
                                        IBinding src)
      • parentBindingChanged

        public static void parentBindingChanged​(java.lang.Object prop)