Search in sources :

Example 1 with ClientPluginAccessProvider

use of com.servoy.j2db.plugins.ClientPluginAccessProvider in project servoy-client by Servoy.

the class FunctionDefinition method exists.

/**
 * Test if the given methodName or formName do exist. Will return one of the {@link Exist} enums.
 * @since 5.2
 */
public Exist exists(IClientPluginAccess access) {
    final Exist[] retVal = new Exist[] { Exist.METHOD_NOT_FOUND };
    if (access instanceof ClientPluginAccessProvider) {
        final IApplication application = ((ClientPluginAccessProvider) access).getApplication();
        application.invokeAndWait(new Runnable() {

            public void run() {
                if (application.getSolution() != null) {
                    if (contextName.startsWith(ScriptVariable.SCOPES_DOT_PREFIX)) {
                        GlobalScope gs = application.getScriptEngine().getScopesScope().getGlobalScope(contextName.substring(ScriptVariable.SCOPES_DOT_PREFIX.length()));
                        if (gs != null && gs.get(methodName) instanceof Function) {
                            retVal[0] = Exist.METHOD_FOUND;
                        }
                    } else {
                        IFormController fp = application.getFormManager().leaseFormPanel(contextName);
                        if (fp == null) {
                            retVal[0] = Exist.FORM_NOT_FOUND;
                        } else if (fp.getFormScope().get(methodName, fp.getFormScope()) instanceof Function) {
                            retVal[0] = Exist.METHOD_FOUND;
                        }
                    }
                } else {
                    retVal[0] = Exist.NO_SOLUTION;
                }
            }
        });
    }
    return retVal[0];
}
Also used : ClientPluginAccessProvider(com.servoy.j2db.plugins.ClientPluginAccessProvider) Function(org.mozilla.javascript.Function) IApplication(com.servoy.j2db.IApplication) IFormController(com.servoy.j2db.IFormController)

Aggregations

IApplication (com.servoy.j2db.IApplication)1 IFormController (com.servoy.j2db.IFormController)1 ClientPluginAccessProvider (com.servoy.j2db.plugins.ClientPluginAccessProvider)1 Function (org.mozilla.javascript.Function)1