use of com.servoy.j2db.persistence.ISupportScriptProviders in project servoy-client by Servoy.
the class FoundSet method getPrototype.
public Scriptable getPrototype() {
if (prototypeScope == null) {
LazyCompilationScope scope = new LazyCompilationScope(this, fsm.getApplication().getScriptEngine(), new ISupportScriptProviders() {
public Iterator<? extends IScriptProvider> getScriptMethods(boolean sort) {
List<ScriptMethod> methods = null;
Iterator<TableNode> tableNodes = fsm.getApplication().getFlattenedSolution().getTableNodes(getTable());
while (tableNodes.hasNext()) {
TableNode tn = tableNodes.next();
Iterator<ScriptMethod> fsMethods = tn.getFoundsetMethods(sort);
if (methods == null) {
if (!tableNodes.hasNext()) {
// just 1
return fsMethods;
}
methods = new ArrayList<ScriptMethod>();
}
while (fsMethods.hasNext()) {
methods.add(fsMethods.next());
}
}
return methods == null ? Collections.<ScriptMethod>emptyList().iterator() : methods.iterator();
}
public Iterator<ScriptVariable> getScriptVariables(boolean b) {
return Collections.<ScriptVariable>emptyList().iterator();
}
public ScriptMethod getScriptMethod(int methodId) {
// not called by LCS
return null;
}
}) {
@Override
public String getClassName() {
// $NON-NLS-1$
return "FoundSetScope";
}
@Override
public String getScopeName() {
return getDataSource();
}
};
// make sure functions like getSize cannot be overridden
scope.setFunctionParentScriptable(this);
prototypeScope = scope;
}
return prototypeScope;
}
use of com.servoy.j2db.persistence.ISupportScriptProviders in project servoy-client by Servoy.
the class ScriptEngine method getTableScope.
public Scriptable getTableScope(final ITable table) {
if (tableScopes == null)
tableScopes = new HashMap<ITable, Scriptable>();
Scriptable tableScope = null;
synchronized (table) {
tableScope = tableScopes.get(table);
if (tableScope == null) {
Context.enter();
try {
tableScope = new TableScope(solutionScope, this, table, application.getFlattenedSolution(), new ISupportScriptProviders() {
public Iterator<? extends IScriptProvider> getScriptMethods(boolean sort) {
return application.getFlattenedSolution().getScriptCalculations(table, false);
}
public Iterator<ScriptVariable> getScriptVariables(boolean b) {
return Collections.<ScriptVariable>emptyList().iterator();
}
public ScriptMethod getScriptMethod(int methodId) {
// is not used for calculations
return null;
}
});
tableScopes.put(table, tableScope);
} finally {
Context.exit();
}
}
}
return tableScope;
}
use of com.servoy.j2db.persistence.ISupportScriptProviders in project servoy-client by Servoy.
the class BasicFormController method initForJSUsage.
/**
* Initialize this FormController(or related classes/methods) to be used in javascript
*/
public synchronized JSForm initForJSUsage(CreationalPrototype creationalPrototype) {
if (formScope == null) {
try {
// make scope for state delegation via prototype mechanism
List<Form> forms = application.getFlattenedSolution().getFormHierarchy(form);
List<ISupportScriptProviders> scriptProviders = new ArrayList<ISupportScriptProviders>();
for (Form frm : forms) {
scriptProviders.add(new RuntimeSupportScriptProviders(application, frm));
}
formScope = new FormScope(this, scriptProviders.toArray(new ISupportScriptProviders[scriptProviders.size()]));
if (formModel != null) {
ITable formTable = application.getFoundSetManager().getTable(form.getDataSource());
formScope.setPrototype(new SelectedRecordScope(this, formTable == null ? null : application.getScriptEngine().getTableScope(formTable)));
// $NON-NLS-1$
formScope.putWithoutFireChange("foundset", formModel);
}
// create JS place holder for this object
scriptableForm = new BasicFormController.JSForm(this);
// set parent scope
NativeJavaObject formObject = new NativeJavaObject(formScope, scriptableForm, ScriptObjectRegistry.getJavaMembers(FormController.JSForm.class, formScope));
// $NON-NLS-1$
formScope.putWithoutFireChange("controller", formObject);
// register the place holder 'scriptableForm' in CreationalPrototype scope
creationalPrototype.setLocked(false);
// $NON-NLS-1$
creationalPrototype.put(((Integer) creationalPrototype.get("length", creationalPrototype)).intValue(), creationalPrototype, formScope);
creationalPrototype.put(getName(), creationalPrototype, formScope);
creationalPrototype.setLocked(true);
formScope.createVars();
} catch (Exception ex) {
// $NON-NLS-1$
application.reportError(application.getI18NMessage("servoy.formPanel.error.initFormScope") + ": " + getName(), ex);
return null;
}
}
return scriptableForm;
}
Aggregations