Search in sources :

Example 6 with IExecutingEnviroment

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

the class FoundSetManager method getTriggerFunctions.

private List<TriggerFunction> getTriggerFunctions(ITable table, TypedProperty<Integer> property, Scriptable foundsetScope) {
    FlattenedSolution solutionRoot = getApplication().getFlattenedSolution();
    IExecutingEnviroment scriptEngine = getApplication().getScriptEngine();
    return stream(solutionRoot.getTableNodes(table)).map(tableNode -> {
        Object function = null;
        Scriptable scope = null;
        ScriptMethod scriptMethod = solutionRoot.getScriptMethod(((Integer) tableNode.getProperty(property.getPropertyName())).intValue());
        if (scriptMethod != null) {
            if (scriptMethod.getParent() instanceof Solution) {
                // global method
                GlobalScope gs = scriptEngine.getScopesScope().getGlobalScope(scriptMethod.getScopeName());
                if (gs != null) {
                    scope = gs;
                    function = gs.get(scriptMethod.getName());
                }
            } else if (foundsetScope != null) {
                // foundset method
                scope = foundsetScope;
                function = scope.getPrototype().get(scriptMethod.getName(), scope);
            }
        }
        if (function instanceof Function) {
            return new TriggerFunction((Function) function, scope, tableNode);
        }
        return null;
    }).filter(Objects::nonNull).collect(toList());
}
Also used : GlobalScope(com.servoy.j2db.scripting.GlobalScope) Function(org.mozilla.javascript.Function) IExecutingEnviroment(com.servoy.j2db.scripting.IExecutingEnviroment) FlattenedSolution(com.servoy.j2db.FlattenedSolution) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) Scriptable(org.mozilla.javascript.Scriptable) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution)

Example 7 with IExecutingEnviroment

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

the class ViewFoundSet method sort.

/**
 * Sorts the foundset based on the given record comparator function.
 * Tries to preserve selection based on primary key. If first record is selected or cannot select old record it will select first record after sort.
 * The comparator function is called to compare
 * two records, that are passed as arguments, and
 * it will return -1/0/1 if the first record is less/equal/greater
 * then the second record.
 *
 * The function based sorting does not work with printing.
 * It is just a temporary in-memory sort.
 *
 * NOTE: starting with 7.2 release this function doesn't save the data anymore
 *
 * @sample
 * %%prefix%%foundset.sort(mySortFunction);
 *
 * function mySortFunction(r1, r2)
 * {
 *	var o = 0;
 *	if(r1.id < r2.id)
 *	{
 *		o = -1;
 *	}
 *	else if(r1.id > r2.id)
 *	{
 *		o = 1;
 *	}
 *	return o;
 * }
 *
 * @param recordComparisonFunction record comparator function
 */
@JSFunction
@JSSignature(arguments = { Function.class })
public void sort(Object recordComparisonFunction) {
    if (recordComparisonFunction instanceof Function) {
        final Function func = (Function) recordComparisonFunction;
        final IExecutingEnviroment scriptEngine = manager.getApplication().getScriptEngine();
        final Scriptable recordComparatorScope = func.getParentScope();
        sort(new Comparator<Object[]>() {

            public int compare(Object[] o1, Object[] o2) {
                try {
                    Object compareResult = scriptEngine.executeFunction(func, recordComparatorScope, recordComparatorScope, new Object[] { getRecord(o1), getRecord(o2) }, false, true);
                    double cmp = Utils.getAsDouble(compareResult, true);
                    return cmp < 0 ? -1 : cmp > 0 ? 1 : 0;
                } catch (Exception ex) {
                    Debug.error(ex);
                }
                return 0;
            }
        });
    }
}
Also used : JSFunction(org.mozilla.javascript.annotations.JSFunction) Function(org.mozilla.javascript.Function) IExecutingEnviroment(com.servoy.j2db.scripting.IExecutingEnviroment) IConstantsObject(com.servoy.j2db.scripting.IConstantsObject) Scriptable(org.mozilla.javascript.Scriptable) RemoteException(java.rmi.RemoteException) ServoyException(com.servoy.j2db.util.ServoyException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) JSSignature(com.servoy.j2db.scripting.annotations.JSSignature) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 8 with IExecutingEnviroment

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

the class FormManager method setCurrentContainer.

/**
 * @param mainContainer
 */
public void setCurrentContainer(IMainContainer mainContainer, String name) {
    if (mainContainer != null) {
        currentContainer = mainContainer;
        if (name != null) {
            // reset it in the containers (must be done for the webclient)
            containers.put(name, mainContainer);
        }
    } else {
        currentContainer = getMainContainer(null);
    }
    enableCmds(true);
    FormController formController = currentContainer.getController();
    if (formController != null) {
        IExecutingEnviroment scriptEngine = application.getScriptEngine();
        if (scriptEngine != null) {
            SolutionScope ss = scriptEngine.getSolutionScope();
            Context.enter();
            try {
                // $NON-NLS-1$
                ss.put("currentcontroller", ss, new NativeJavaObject(ss, formController.initForJSUsage(), new InstanceJavaMembers(ss, JSForm.class)));
            } finally {
                Context.exit();
            }
        }
    }
    application.getRuntimeWindowManager().setCurrentWindowName(name);
}
Also used : InstanceJavaMembers(com.servoy.j2db.scripting.InstanceJavaMembers) IExecutingEnviroment(com.servoy.j2db.scripting.IExecutingEnviroment) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) SolutionScope(com.servoy.j2db.scripting.SolutionScope)

Example 9 with IExecutingEnviroment

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

the class DebugNGClient method getStackFrame.

/**
 * @return
 */
private DBGPDebugFrame getStackFrame() {
    IExecutingEnviroment engine = getScriptEngine();
    if (engine instanceof RemoteDebugScriptEngine && ((RemoteDebugScriptEngine) engine).getDebugger() != null) {
        DBGPDebugger debugger = ((RemoteDebugScriptEngine) engine).getDebugger();
        DBGPStackManager stackManager = debugger.getStackManager();
        if (stackManager != null) {
            return debugger.getStackManager().getStackFrame(0);
        }
    }
    return null;
}
Also used : DBGPDebugger(org.eclipse.dltk.rhino.dbgp.DBGPDebugger) IExecutingEnviroment(com.servoy.j2db.scripting.IExecutingEnviroment) DBGPStackManager(org.eclipse.dltk.rhino.dbgp.DBGPStackManager)

Example 10 with IExecutingEnviroment

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

the class DataAdapterList method destroy.

public void destroy() {
    if (record != null) {
        setRecord(null, false);
    }
    if (formController != null && formController.getFormScope() != null) {
        formController.getFormScope().getModificationSubject().removeModificationListener(this);
    }
    if (formController != null && formController.getApplication() != null && formController.getApplication().getScriptEngine() != null) {
        IExecutingEnviroment er = formController.getApplication().getScriptEngine();
        if (er.getScopesScope() != null) {
            er.getScopesScope().getModificationSubject().removeModificationListener(this);
        }
    }
    dataProviderToLinkedComponentProperty.clear();
    allComponentPropertiesLinkedToData.clear();
    findModeAwareProperties.clear();
    parentRelatedForms.clear();
    visibleChildForms.clear();
}
Also used : IExecutingEnviroment(com.servoy.j2db.scripting.IExecutingEnviroment)

Aggregations

IExecutingEnviroment (com.servoy.j2db.scripting.IExecutingEnviroment)12 ServoyException (com.servoy.j2db.util.ServoyException)5 Scriptable (org.mozilla.javascript.Scriptable)5 RepositoryException (com.servoy.j2db.persistence.RepositoryException)4 SolutionScope (com.servoy.j2db.scripting.SolutionScope)3 RemoteException (java.rmi.RemoteException)3 Function (org.mozilla.javascript.Function)3 ApplicationException (com.servoy.j2db.ApplicationException)2 JSSignature (com.servoy.j2db.scripting.annotations.JSSignature)2 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)2 NativeJavaObject (org.mozilla.javascript.NativeJavaObject)2 JSFunction (org.mozilla.javascript.annotations.JSFunction)2 FlattenedSolution (com.servoy.j2db.FlattenedSolution)1 IServoyAwareBean (com.servoy.j2db.dataui.IServoyAwareBean)1 MethodArgument (com.servoy.j2db.persistence.MethodArgument)1 MethodTemplate (com.servoy.j2db.persistence.MethodTemplate)1 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)1 Solution (com.servoy.j2db.persistence.Solution)1 GlobalScope (com.servoy.j2db.scripting.GlobalScope)1 IConstantsObject (com.servoy.j2db.scripting.IConstantsObject)1