Search in sources :

Example 1 with FormScope

use of com.servoy.j2db.scripting.FormScope in project servoy-client by Servoy.

the class DataAdapterList method getFormScope.

public FormScope getFormScope() {
    if (// can happen for a design component
    formController == null) {
        return null;
    }
    if (destroyed) {
        Debug.error("calling getFormScope on a destroyed DataAdapterList, formcontroller: " + formController + ", currentRecord: " + currentRecord, new RuntimeException());
        return null;
    }
    FormScope formScope = formController.getFormScope();
    if (formScope == null && formController.isDestroyed()) {
        Debug.error("calling getFormScope in none destroyed DataAdapterList (destroying it now) for a destroyed formcontroller: " + formController + ", currentRecord: " + currentRecord, new RuntimeException());
        destroy();
        return null;
    }
    return formScope;
}
Also used : FormScope(com.servoy.j2db.scripting.FormScope)

Example 2 with FormScope

use of com.servoy.j2db.scripting.FormScope in project servoy-client by Servoy.

the class DataAdapterList method valueChanged.

/*
	 * _____________________________________________________________ JavaScriptModificationListner
	 */
/**
 * listen for global var changes via own listener and state vars(mainly columns) via state listener if via javascript any var is changed it will be noted
 * here,and dispatched to refresh the displays
 */
public void valueChanged(ModificationEvent e) {
    if (destroyed) {
        Debug.error("Destroyed DataAdapterList " + formController + " was still attached to the record: " + e.getRecord() + ", removing it if possible, currentRecord: " + currentRecord, new RuntimeException());
        if (e.getRecord() != null)
            e.getRecord().removeModificationListener(this);
        else if (currentRecord != null)
            currentRecord.removeModificationListener(this);
        return;
    }
    if (formController != null && formController.isDestroyed()) {
        Debug.error("Destroying DataAdapterList of a destroyed " + formController, new RuntimeException());
        destroy();
        return;
    }
    FormScope formScope = getFormScope();
    if (visible && (currentRecord != null || (formScope != null && formScope.has(e.getName(), formScope)))) {
        for (IDataAdapter da : dataAdapters.values()) {
            // dataAdapter should call state.getValue if name from event is same as its dataProviderID
            da.valueChanged(e);
        }
        // check if a related adapter depends on he global
        if (e != null && e.getName() != null) {
            for (IDisplayRelatedData drd : relatedDataAdapters) {
                boolean depends = false;
                String[] allRelationNames = drd.getAllRelationNames();
                for (int a = 0; !depends && allRelationNames != null && a < allRelationNames.length; a++) {
                    Relation[] relations = application.getFlattenedSolution().getRelationSequence(allRelationNames[a]);
                    for (int r = 0; !depends && relations != null && r < relations.length; r++) {
                        try {
                            IDataProvider[] primaryDataProviders = relations[r].getPrimaryDataProviders(application.getFlattenedSolution());
                            for (int p = 0; !depends && primaryDataProviders != null && p < primaryDataProviders.length; p++) {
                                depends = e.getName().equals(primaryDataProviders[p].getDataProviderID());
                            }
                        } catch (RepositoryException ex) {
                            Debug.log(ex);
                        }
                    }
                }
                if (depends) {
                    // related adapter depends on the modified global
                    if (drd instanceof IDisplayDependencyData)
                        ((IDisplayDependencyData) drd).dependencyChanged(currentRecord);
                    else
                        drd.setRecord(currentRecord, true);
                }
            }
        }
        // inform servoy aware beans
        for (IServoyAwareBean drd : servoyAwareBeans) {
            if (drd instanceof IModificationListener) {
                try {
                    ((IModificationListener) drd).valueChanged(e);
                } catch (RuntimeException ex) {
                    // never make the app break on faulty beans
                    Debug.error(ex);
                }
            }
        }
    }
}
Also used : RepositoryException(com.servoy.j2db.persistence.RepositoryException) IDataProvider(com.servoy.j2db.persistence.IDataProvider) FormScope(com.servoy.j2db.scripting.FormScope) Relation(com.servoy.j2db.persistence.Relation) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean)

Example 3 with FormScope

use of com.servoy.j2db.scripting.FormScope in project servoy-client by Servoy.

the class JSForm method checkModification.

@Override
public final void checkModification() {
    // make copy if needed
    if (!isCopy) {
        setForm(application.getFlattenedSolution().createPersistCopy(getForm()));
        application.getFormManager().addForm(getForm(), false);
        // forms scope still uses the old copy of Script Providers
        Form oldform = getForm();
        List<IFormController> controllers = application.getFormManager().getCachedFormControllers(getForm());
        for (IFormController formController : controllers) {
            FormScope formScope = formController.getFormScope();
            formScope.updateProviderswithCopy(oldform, getForm());
        }
        isCopy = true;
    } else {
        application.getFlattenedSolution().flushFlattendFormCache(getForm(), true);
    }
    getForm().setLastModified(System.currentTimeMillis());
    application.getFlattenedSolution().registerChangedForm(getForm());
    useFormCache = false;
}
Also used : Form(com.servoy.j2db.persistence.Form) ISMForm(com.servoy.j2db.solutionmodel.ISMForm) IMobileSMForm(com.servoy.base.solutionmodel.mobile.IMobileSMForm) IFormController(com.servoy.j2db.IFormController) FormScope(com.servoy.j2db.scripting.FormScope)

Example 4 with FormScope

use of com.servoy.j2db.scripting.FormScope in project servoy-client by Servoy.

the class JSForm method refreshFromScopes.

private void refreshFromScopes() {
    List<IFormController> controllers = application.getFormManager().getCachedFormControllers(getForm());
    for (IFormController formController : controllers) {
        FormScope formScope = formController.getFormScope();
        formScope.updateProviderswithCopy(getForm(), getForm());
        formScope.reload();
    }
}
Also used : IFormController(com.servoy.j2db.IFormController) FormScope(com.servoy.j2db.scripting.FormScope)

Example 5 with FormScope

use of com.servoy.j2db.scripting.FormScope in project servoy-client by Servoy.

the class JSForm method removeVariableFromScopes.

private void removeVariableFromScopes(ScriptVariable var) {
    List<IFormController> controllers = application.getFormManager().getCachedFormControllers(getForm());
    for (IFormController formController : controllers) {
        FormScope formScope = formController.getFormScope();
        formScope.updateProviderswithCopy(getForm(), getForm());
        formScope.remove(var);
    }
}
Also used : IFormController(com.servoy.j2db.IFormController) FormScope(com.servoy.j2db.scripting.FormScope)

Aggregations

FormScope (com.servoy.j2db.scripting.FormScope)23 IFormController (com.servoy.j2db.IFormController)6 Form (com.servoy.j2db.persistence.Form)5 ArrayList (java.util.ArrayList)4 JSONObject (org.json.JSONObject)4 IRecord (com.servoy.j2db.dataprocessing.IRecord)3 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)3 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)3 GlobalScope (com.servoy.j2db.scripting.GlobalScope)3 IWebFormController (com.servoy.j2db.server.ngclient.IWebFormController)3 WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)3 ServoyException (com.servoy.j2db.util.ServoyException)3 JSONException (org.json.JSONException)3 Scriptable (org.mozilla.javascript.Scriptable)3 ApplicationException (com.servoy.j2db.ApplicationException)2 IServiceProvider (com.servoy.j2db.IServiceProvider)2 FindState (com.servoy.j2db.dataprocessing.FindState)2 IServoyAwareBean (com.servoy.j2db.dataui.IServoyAwareBean)2 IPersist (com.servoy.j2db.persistence.IPersist)2 RepositoryException (com.servoy.j2db.persistence.RepositoryException)2