use of com.servoy.j2db.dataprocessing.ViewFoundSet in project servoy-client by Servoy.
the class BasicFormController method executeFunction.
/**
* call a scriptMethod (== function)
*
* @param cmd be the the id from the method or the name
* @param methodKey
*/
public Object executeFunction(String cmd, Object[] args, boolean saveData, Object src, boolean focusEvent, String methodKey, boolean allowFoundsetMethods, boolean executeWhenFieldValidationFailed, boolean throwException) throws Exception {
Object function = null;
Scriptable scope = formScope;
String name = cmd;
int id = Utils.getAsInteger(cmd);
if (id > 0) {
name = formScope.getFunctionName(new Integer(id));
}
Pair<String, String> nameScope = ScopesUtils.getVariableScope(name);
boolean global = nameScope != null && nameScope.getLeft() != null;
if (id <= 0 && global) {
name = nameScope.getRight();
} else {
function = formScope.getFunctionByName(name);
}
if (// TODO foundset methods for ViewFoundSet?
allowFoundsetMethods && !global && function == null && formModel instanceof FoundSet) {
// try foundset method
ScriptMethod scriptMethod = application.getFlattenedSolution().getScriptMethod(id);
if (scriptMethod != null) {
name = scriptMethod.getName();
}
if (name != null) {
scope = (FoundSet) formModel;
function = scope.getPrototype().get(name, scope);
}
}
if (function == null || function == Scriptable.NOT_FOUND) {
GlobalScope globalScope = null;
if (id > 0) {
ScriptMethod scriptMethod = application.getFlattenedSolution().getScriptMethod(id);
if (scriptMethod != null) {
globalScope = application.getScriptEngine().getScopesScope().getGlobalScope(scriptMethod.getScopeName());
}
} else if (nameScope != null) {
globalScope = application.getScriptEngine().getScopesScope().getGlobalScope(nameScope.getLeft());
}
if (globalScope != null) {
scope = globalScope;
if (id > 0) {
name = globalScope.getFunctionName(new Integer(id));
}
function = globalScope.getFunctionByName(name);
}
}
Function f;
if (function instanceof Function) /* else null or UniqueTag.NOT_FOUND */
{
f = (Function) function;
} else {
if (cmd != null) {
if (throwException) {
throw new IllegalArgumentException("Could not find function '" + cmd + "' for form " + getName());
} else {
application.reportJSError("Could not find function '" + cmd + "' for form " + getName() + " , invoked by Object:", src);
}
return null;
}
// sometimes executeFunction is called with cmd=null just to trigger field validation, see BaseEventExecutor.fireEventCommand()
f = null;
}
if (throwException) {
return executeFunction(// $NON-NLS-1$
f, // $NON-NLS-1$
args, // $NON-NLS-1$
scope, // $NON-NLS-1$
scope, // $NON-NLS-1$
saveData, // $NON-NLS-1$
src, // $NON-NLS-1$
f == null || !Utils.getAsBoolean(f.get("_AllowToRunInFind_", f)), focusEvent, methodKey, executeWhenFieldValidationFailed, false, true);
}
try {
return executeFunction(// $NON-NLS-1$
f, // $NON-NLS-1$
args, // $NON-NLS-1$
scope, // $NON-NLS-1$
scope, // $NON-NLS-1$
saveData, // $NON-NLS-1$
src, // $NON-NLS-1$
f == null || !Utils.getAsBoolean(f.get("_AllowToRunInFind_", f)), focusEvent, methodKey, executeWhenFieldValidationFailed, false, false);
} catch (ApplicationException ex) {
application.reportError(ex.getMessage(), null);
} catch (Exception ex) {
// this.requestFocus();
// $NON-NLS-1$ //$NON-NLS-2$
application.reportError(application.getI18NMessage("servoy.formPanel.error.executingMethod", new Object[] { getName() + "." + name }), ex);
}
return null;
}
use of com.servoy.j2db.dataprocessing.ViewFoundSet in project servoy-client by Servoy.
the class BasicFormController method executeFormMethod.
public Object executeFormMethod(TypedProperty<Integer> methodProperty, Object[] args, Boolean testFindMode, boolean saveData, boolean allowFoundsetMethods) {
Object ret = null;
Integer id = ((Integer) form.getProperty(methodProperty.getPropertyName()));
if (id.intValue() > 0 && formScope != null) {
FormExecutionState formExecutionState = null;
if (getFormUI() instanceof ISupportFormExecutionState) {
formExecutionState = ((ISupportFormExecutionState) getFormUI()).formMethodExecution();
}
String sName = null;
try {
Object function = null;
Scriptable scope = formScope;
// try form method
sName = formScope.getFunctionName(id);
if (sName != null) {
function = formScope.getFunctionByName(sName);
}
if (!(function instanceof Function)) {
// try global method
ScriptMethod scriptMethod = application.getFlattenedSolution().getScriptMethod(id.intValue());
if (scriptMethod != null) {
GlobalScope globalScope = application.getScriptEngine().getScopesScope().getGlobalScope(scriptMethod.getScopeName());
if (globalScope != null) {
scope = globalScope;
sName = globalScope.getFunctionName(id);
if (sName != null) {
function = globalScope.getFunctionByName(sName);
}
}
if (// TODO foundset methods for ViewFoundSet?
allowFoundsetMethods && !(function instanceof Function) && formModel instanceof FoundSet) {
scope = (FoundSet) formModel;
function = scope.getPrototype().get(scriptMethod.getName(), scope);
}
}
}
if (function instanceof Function) {
if (testFindMode == null) {
// $NON-NLS-1$
testFindMode = Boolean.valueOf(!Utils.getAsBoolean(((Function) function).get("_AllowToRunInFind_", (Function) function)));
}
ret = executeFunction((Function) function, Utils.arrayMerge(args, Utils.parseJSExpressions(form.getFlattenedMethodArguments(methodProperty.getPropertyName()))), scope, scope, saveData, null, testFindMode.booleanValue(), false, methodProperty.getPropertyName(), false, true, false);
}
} catch (Exception ex) {
// $NON-NLS-1$
application.reportError(application.getI18NMessage("servoy.formPanel.error.executeMethod", new Object[] { sName }), ex);
} finally {
if (formExecutionState != null && getFormUI() instanceof ISupportFormExecutionState) {
((ISupportFormExecutionState) getFormUI()).formMethodExecuted(formExecutionState);
}
}
}
return ret;
}
Aggregations