Class FormModel

  • All Implemented Interfaces:
    Element.DualDomNode, Peer

    public class FormModel
    extends Model
    A class to represent the result of joining a template and data.
    • Constructor Detail

      • FormModel

        public FormModel​(Element parent,
                         Node prevSibling)
    • Method Detail

      • getFormModel

        public static FormModel getFormModel​(AppModel appModel,
                                             boolean bCreateIfNotFound)
        Returns the FormModel held within the AppModel.
        Parameters:
        appModel - the AppModel to search
        bCreateIfNotFound - if true, and the FormModel does not exist, then one will be created and returned; if false and the FormModel does not exist, null is returned
        Returns:
        the FormModel contained within appModel; null if not found and bCreateIfNotFound is false.
      • recurseConnectOnNode

        public static void recurseConnectOnNode​(Node node,
                                                java.lang.String strConnectionName,
                                                int eUsage,
                                                FormModel.ConnectHandler handler,
                                                java.lang.Object handlerData)
      • addUseNode

        public void addUseNode​(Element useNode)
        Description copied from class: Model
        add a new new node to the useNodeList
        Overrides:
        addUseNode in class Model
      • addUseHRefNode

        public void addUseHRefNode​(Element useHRefNode)
        Not supported on FormModel
        Overrides:
        addUseHRefNode in class Model
      • clearFocus

        public void clearFocus()
        Resets the focus. No field will have focus after but the form model will remember which field had the focus last.
      • mergeMode

        public int mergeMode()
        Indicates whether the current merge mode is globally consumptive (XFAEnum::CONSUME_DATA) or not (XFAEnum::MATCH_TEMPLATE).
      • createNode

        public Node createNode​(int eClassTag,
                               Element parent,
                               java.lang.String aNodeName,
                               java.lang.String aNS,
                               boolean bDoVersionCheck)
        Description copied from class: Model
        Create an element with the given tag, parent, name and uri.
        Specified by:
        createNode in class Model
        Parameters:
        eClassTag - the element's tag.
        parent - the element's parent.
        aNodeName - the element's name.
        aNS - the element's namespace.
        bDoVersionCheck - check the element's version.
        Returns:
        a new element.
        See Also:
        Model.createNode(int, Element, String, String, boolean)
      • createPanelOverlayData

        public void createPanelOverlayData​(int nPanel)
        Creates an overlayData section under dataSets. This method is for Form Server support.
        Parameters:
        nPanel - the panel to create the overlayData section for
      • eventOccurred

        public boolean eventOccurred​(java.lang.String sActivity,
                                     Obj container)
        Notifies event listeners that an event has occurred on a container. This method may fire additional events before and/or after firing the event.
        Parameters:
        sActivity - the name of the event
        container - the container on which the event occurs
        Returns:
        true if one or more events were dispatched.
      • exportConnectionData

        public void exportConnectionData​(java.lang.String strConnectionName,
                                         java.lang.String sDataDescriptionName)
      • getAdjustData

        public boolean getAdjustData()
        Determines whether the next remerge() operation will adjust the structure of the DataModel to match the TemplateModel. The default value is false.
        Returns:
        true if the next remerge() operation will adjust the structure of the DataModel to match the TemplateModel.
        See Also:
        remerge(), setAdjustData(boolean)
      • getAmbientLocale

        public java.lang.String getAmbientLocale()
        Gets the ambient locale override for the top level subform. This will be used when resolving locales for fields and subforms. If a field/subform does not have a locale specified, then they will inherit it from their ancestory hierarchy.
        Returns:
        the ambient locale (e.g. "en_US").
      • getCalculationsEnabled

        public boolean getCalculationsEnabled()
        Determines if calculations are enabled.
        Returns:
        true if calculations are enabled.
      • getDeltas

        public Obj getDeltas​(Element node)
      • getExecute

        public FormModel.Execute getExecute()
        Gets the Execute associated with this FormModel. May be null.
        Returns:
        the Execute.
      • getFocus

        public FormField getFocus()
        Gets the field that has focus for the FormModel.
        Returns:
        the field that has focus.
      • getFormStateRemoved

        public boolean getFormStateRemoved()
        Determines if the formState packet has been removed.
        Returns:
        true if the formState packet has been removed
      • getFriendlyName

        public java.lang.String getFriendlyName​(Element formNode)
        Gets the friendly name (to use in user-facing communication) for a form node
        Parameters:
        formNode - a FormSubform, FormField or FormExclGroup to get a user-friendly name for.
        Returns:
        a string containing a user-friendly name for the form node.
      • getOverlayDataMergeUsage

        public boolean getOverlayDataMergeUsage()
        Gets the OverlayDataMerge setting.
        Returns:
        true if OverlayDataMergeUsage must occur
      • getPanelToMergeAgainst

        public int getPanelToMergeAgainst()
        Gets the panel to merge against.
        Returns:
        the panel (second-level subform) to merge against
      • getRunScripts

        public int getRunScripts()
        Gets the runAt property that specifies where scripts should be executed (client, server or both). The default is both.
        Returns:
        one of: EnumAttr.RUNSCRIPTS_CLIENT, EnumAttr.RUNSCRIPTS_SERVER, EnumAttr.RUNSCRIPTS_BOTH or EnumAttr.RUNSCRIPTS_NONE
        See Also:
        setRunScripts(int)
      • getSubmit

        public FormModel.Submit getSubmit()
        Gets the Submit implementation associated with this FormModel.
        Returns:
        a pointer to a class derived from Submit.
      • getSubmitURL

        public java.lang.String getSubmitURL()
        Gets the submit URL override for the top level subform. This will be used to determine if we are submitting to FormServer.
        Returns:
        String, the submit URL.
      • getValidationsEnabled

        public boolean getValidationsEnabled()
        Determines whether validations are enabled.
        Returns:
        true if validations are enabled.
      • importConnectionData

        public void importConnectionData​(java.lang.String strConnectionName)
      • importNode

        public Element importNode​(ProtoableNode templateNode,
                                  Element formParent,
                                  boolean bFull)
        Imports a template node into this model, while resolving any global or dataRef fields. This will simply walk the template DOM and create a form node for each one it encounters. This will also set up the appropriate proto relationships
        Parameters:
        templateNode - the template node to import
        formParent - the parent we'll add the created form node too
        bFull - if true, do merge and process the children.
        Returns:
        the newly created Form node
      • initialize

        public boolean initialize()
        Fires the initialize event on all containers on the form, and fires the indexChange event on all subforms.
        Returns:
        true if one or more events were dispatched.
      • initializeNewContentNodes

        public boolean initializeNewContentNodes()
        Initializes the new content nodes
        Returns:
        true if one or more events were dispatched.
      • isCompatibleNS

        public boolean isCompatibleNS​(java.lang.String aNS)
        Description copied from class: Model
        Determine if a specified namespace string is compatible with the namespace of this model. Essentially this determines if the two namespaces are equivalent (though the strings that represent them may not be identical).
        Overrides:
        isCompatibleNS in class Model
        Parameters:
        aNS - The namespace to compare.
        See Also:
        Model.isCompatibleNS(String)
      • merge

        public void merge​(boolean bEmptyMerge,
                          boolean bAdjustData,
                          boolean bInitialize,
                          boolean bRestoreDeltas,
                          boolean bForceRestore)
        Merges the TemplateModel and the DataModel to create the FormModel. The first two parameters are implicitly used to call setEmptyMerge(boolean) and setAdjustData(boolean) respectively.
        Parameters:
        bEmptyMerge - if true then merge against an empty DataModel, if false use the DataModel found in the AppModel
        bAdjustData - if true adjust the structure of the DataModel to match the structure of the TemplateModel; if false don't modify the DataModel.
        bInitialize - if true all the initialize events will be fired; if false no initialization is performed
        bRestoreDeltas - if true and if the restoreState property on the form's root subform is "auto" (the default is "manual"), all deltas are restored from the form packet. The locale attribute is always restored from the form packet, regardless of the value of this parameter.
        bForceRestore - if true, restore the state regardless of the the restoreState property on the form's root subform.
      • merge

        public void merge​(boolean bEmptyMerge,
                          boolean bAdjustData,
                          java.lang.String sConnectionName,
                          boolean bInitialize,
                          boolean bRestoreDeltas,
                          boolean bForceRestore)
        Merges the TemplateModel and the DataModel to create the FormModel.
        Parameters:
        bEmptyMerge - if true then merge against an empty DataModel, if false use the DataModel found in the AppModel
        bAdjustData - if true, adjust the structure of the DataModel to match the structure of the TemplateModel; if false, don't modify the DataModel
        sConnectionName - if specified get all the data for the merge from the !connectionData.sConnectionName part of the DataModel. Also, use connect elements rather than bind elements of the TemplateModel
        bInitialize - if true, all the initialize events will be fired; if false, no initialization is performed
        bRestoreDeltas - if true and if the restoreState property on the form's root subform is "auto" (the default is "manual"), all deltas are restored from the form packet. The locale attribute is always restored from the form packet, regardless of the value of this parameter.
        bForceRestore - if true, restore the state regardless of the the restoreState property on the form's root subform.
      • mergeOverlayData

        public void mergeOverlayData​(Node formNode,
                                     Node overlayData)
        Merges overlayData with a subform (FormServer requirement)
        Parameters:
        formNode - The subform to merge with
        overlayData - The data to merge with
      • recalculate

        public boolean recalculate​(boolean bFullRecalculate,
                                   FormModel.Validate validate,
                                   boolean bIgnoreCalcEnabledFlag)
        Executes calculation and validation scripts. After a merge operation, a full recalculate must be done to ensure that all calculations and validations are done using current data values. If data values are changed, this should be called to re-run the calculations.

        The FormModel tracks changes to data values, so recalculation efficiency can be improved by setting the bFullRecalculate parameter to false to perform only those calculations and validations that are dependent on the changed data values.

        Parameters:
        bFullRecalculate - if true all calculations and validations are run. If false calculations and validations are run as needed (i.e. if values that the validate or calculate script are dependent on have changed since the last recalculate).
        validate - an object derived from Validate. If null the default Validate is used, and if the default Validate is also null, no validations are performed.
        bIgnoreCalcEnabledFlag - if true the calculations will be performed even if they are disabled on the host.
        Returns:
        true if any calculations were performed
        See Also:
        setDefaultValidate(Validate), getDefaultValidate()
      • registerNewEvents

        public boolean registerNewEvents​(boolean bAllow)
        Helper function to permit the temporary update the mbRegisterNewEvents setting This should call registerNewEvents(false) before cloning any form node to orphaned nodes being registered with the event model
        Parameters:
        bAllow - the new value of mbRegisterEvents
        Returns:
        the old value of mbRegisterEvents
      • remove

        public void remove()
        Removes a FormModel from its parents child list. Since a FormModel can't really exist outside of the context of an AppModel (i.e., because of connections between the form and data models), the form gets reset before it is removed.
        Overrides:
        remove in class Model
        See Also:
        Node.remove()
      • removeReferences

        public void removeReferences​(Node node)
        Recursively unmaps node from any DataNode it is mapped to.
        Overrides:
        removeReferences in class Model
        Parameters:
        node - the Node to be unmapped.
      • reset

        public void reset()
        Resets this FormModel to its initial state. All children are removed.
      • resetData

        public void resetData​(Obj container)
        Resets a container to its template default value. If container is a field it will reset it. If container is a subform it will recursively reset all the containers it contains. If container is null then it will reset the root subform, and therefore all fields in the form.
        Parameters:
        container - the container to be reset
      • resolveProtos

        public void resolveProtos​(boolean bForceExternalProtoResolve)
        Overrides:
        resolveProtos in class Model
      • restoreValidateDisableAll

        public void restoreValidateDisableAll​(Element formNode,
                                              Node delta)
        restore the validate.disableAll property for a form node
      • setAmbientLocale

        public void setAmbientLocale​(java.lang.String sLocale)
        Set the ambient locale override for the top level subform. This will be used when resolving locales for fields and subforms. If a field/subform does not have a locale specified, then they will inherit it from their ancestory hierarchy.
        Parameters:
        sLocale - the ambient locale (i.e. en_US).
      • setExcludedActivities

        public void setExcludedActivities​(java.lang.String sExclude)
        Sets event activites that are to be excluded from execution.
        Parameters:
        sExclude - a space-delimited list of activities.
      • setExecute

        public void setExecute​(FormModel.Execute execute)
        Associates an Execute object with this FormModel. This allows a client to execute a connection.
        Parameters:
        execute - an object derived from Execute. It will be cloned, so the original can be discarded. May be null.
      • setFocus

        public void setFocus​(FormField field)
        Lets the form model know which field has focus.
        Parameters:
        field - the field that has focus.
      • setPostMergeHandler

        public void setPostMergeHandler​(FormModel.PostMergeHandler handler,
                                        java.lang.Object clientData)
        Sets the callback method that is to be invoked after merge but before any initialize scripts are run.
        Parameters:
        handler - the PostMergeHandler implementation to be invoked after merge but before any initialize scripts are run.
        clientData - this value will be passed as the parameter to FormModel.PostMergeHandler.handlePostMerge(Object) when the callback method is invoked.
        See Also:
        getPostMergeHandler()
      • setRunScripts

        public void setRunScripts​(int eRunAtSetting)
        Sets the runAt property that specifies where scripts should be executed (client, server or both). The default is both.
        Parameters:
        eRunAtSetting - one of: EnumAttr.RUNSCRIPTS_CLIENT, EnumAttr.RUNSCRIPTS_SERVER, EnumAttr.RUNSCRIPTS_BOTH or EnumAttr.RUNSCRIPTS_NONE
        See Also:
        getRunScripts()
      • setServerExchange

        public void setServerExchange​(FormModel.ServerExchange serverExchange)
        Sets the ServerExchange implementation with this FormModel. This allows a form to invoke a web service.
        Parameters:
        serverExchange - an implementation ServerExchange. It will be cloned, so the original can be discarded. May be null.
        See Also:
        getServerExchange()
      • setSubmit

        public void setSubmit​(FormModel.Submit submit)
        Associates a Submit object with this FormModel. This allows a client to submit data to the server.
        Parameters:
        submit - an object derived from Submit. It will be cloned, so the original can be discarded. May be null.
      • setSubmitURL

        public void setSubmitURL​(java.lang.String sSubmitURL)
        Sets the submit URL from the config. This will be used to determine if we are submitting to FormServer.
        Parameters:
        sSubmitURL - the submit URL.
      • setValidateBeforeExecute

        public void setValidateBeforeExecute​(boolean bValidate)
        Sets the flag for performing validations before executing.
        Parameters:
        bValidate - if true, validate before executing, don't validate otherwise.
      • setValidateBeforeSubmit

        public void setValidateBeforeSubmit​(boolean bValidate)
        Sets the flag for performing validations before submitting.
        Parameters:
        bValidate - if true, validate before submitting, don't validate otherwise.
      • wasIncrementalMerge

        public boolean wasIncrementalMerge()
        Returns true if the last merge was an incremental merge.
      • setDisableFormRemerge

        public void setDisableFormRemerge​(boolean bDisable)
        Disable/enable calls to remerge()
      • getDisableFormRemerge

        public boolean getDisableFormRemerge()
        Disable/enable calls to remerge()
      • setGlobalConsumption

        public void setGlobalConsumption​(java.lang.Boolean bVal)