use of com.servoy.j2db.persistence.IScriptProvider 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.IScriptProvider in project servoy-client by Servoy.
the class LazyCompilationScope method createScriptProviders.
// final because called from constructor
protected final void createScriptProviders(boolean overwriteInitialValue) {
Iterator<? extends IScriptProvider> it = scriptLookup.getScriptMethods(false);
while (it.hasNext()) {
IScriptProvider sm = it.next();
put(sm, sm, overwriteInitialValue);
}
}
use of com.servoy.j2db.persistence.IScriptProvider in project servoy-client by Servoy.
the class LazyCompilationScope method getImpl.
protected final Object getImpl(String name, Scriptable start) {
IScriptProvider sp = getScriptProvider(name);
if (sp != null) {
try {
Scriptable compileScope = functionParent;
Scriptable functionSuper = getFunctionSuper(sp);
if (functionSuper != null) {
compileScope = new DefaultScope(functionParent) {
@Override
public String getClassName() {
// $NON-NLS-1$
return "RunScope";
}
};
compileScope.setPrototype(functionParent);
// _formname_ is used in a lot of plugins (getParent of a function object, see FunctionDef) to get the form name
// $NON-NLS-1$ //$NON-NLS-2$
compileScope.put("_formname_", compileScope, functionParent.get("_formname_", functionParent));
// $NON-NLS-1$
compileScope.put("_super", compileScope, functionSuper);
}
Function function = scriptEngine.compileFunction(sp, compileScope);
// replace to prevent more compiles
put(name, start, function);
} catch (Exception e) {
Debug.error(e);
}
}
return super.get(name, start);
}
use of com.servoy.j2db.persistence.IScriptProvider in project servoy-client by Servoy.
the class DebugUtils method getScopesAndFormsToReload.
public static Set<IFormController>[] getScopesAndFormsToReload(final ClientState clientState, Collection<IPersist> changes) {
Set<IFormController> scopesToReload = new HashSet<IFormController>();
final Set<IFormController> formsToReload = new HashSet<IFormController>();
final SpecProviderState specProviderState = WebComponentSpecProvider.getSpecProviderState();
final Set<Form> formsUpdated = new HashSet<Form>();
for (IPersist persist : changes) {
clientState.getFlattenedSolution().updatePersistInSolutionCopy(persist);
if (persist instanceof ScriptMethod) {
if (persist.getParent() instanceof Form) {
Form form = (Form) persist.getParent();
List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers(form);
for (IFormController formController : cachedFormControllers) {
scopesToReload.add(formController);
}
} else if (persist.getParent() instanceof Solution) {
LazyCompilationScope scope = clientState.getScriptEngine().getScopesScope().getGlobalScope(((ScriptMethod) persist).getScopeName());
scope.remove((IScriptProvider) persist);
scope.put((IScriptProvider) persist, (IScriptProvider) persist);
} else if (persist.getParent() instanceof TableNode) {
clientState.getFoundSetManager().reloadFoundsetMethod(((TableNode) persist.getParent()).getDataSource(), (IScriptProvider) persist);
}
if (clientState instanceof DebugJ2DBClient) {
// ((DebugJ2DBClient)clientState).clearUserWindows(); no need for this as window API was refactored and it allows users to clean up dialogs
((DebugSwingFormMananger) ((DebugJ2DBClient) clientState).getFormManager()).fillScriptMenu();
}
} else if (persist instanceof ScriptVariable) {
ScriptVariable sv = (ScriptVariable) persist;
if (persist.getParent() instanceof Solution) {
clientState.getScriptEngine().getScopesScope().getGlobalScope(sv.getScopeName()).put(sv);
}
if (persist.getParent() instanceof Form) {
Form form = (Form) persist.getParent();
List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers(form);
for (IFormController formController : cachedFormControllers) {
FormScope scope = formController.getFormScope();
scope.put(sv);
}
}
} else if (persist.getAncestor(IRepository.FORMS) != null) {
final Form form = (Form) persist.getAncestor(IRepository.FORMS);
if (form != null && form.isFormComponent().booleanValue()) {
// if the changed form is a reference form we need to check if that is referenced by a loaded form..
List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers();
for (IFormController fc : cachedFormControllers) {
fc.getForm().acceptVisitor(new IPersistVisitor() {
@Override
public Object visit(IPersist o) {
if (o instanceof WebComponent) {
WebComponent wc = (WebComponent) o;
WebObjectSpecification spec = FormTemplateGenerator.getWebObjectSpecification(wc);
Collection<PropertyDescription> properties = spec != null ? spec.getProperties(FormComponentPropertyType.INSTANCE) : null;
if (properties != null && properties.size() > 0) {
Form persistForm = (Form) wc.getAncestor(IRepository.FORMS);
for (PropertyDescription pd : properties) {
Form frm = FormComponentPropertyType.INSTANCE.getForm(wc.getProperty(pd.getName()), clientState.getFlattenedSolution());
if (frm != null && (form.equals(frm) || FlattenedForm.hasFormInHierarchy(frm, form) || isReferenceFormUsedInForm(clientState, form, frm)) && !formsUpdated.contains(persistForm)) {
formsUpdated.add(persistForm);
List<IFormController> cfc = clientState.getFormManager().getCachedFormControllers(persistForm);
for (IFormController formController : cfc) {
formsToReload.add(formController);
}
}
}
}
}
return IPersistVisitor.CONTINUE_TRAVERSAL;
}
});
}
} else if (!formsUpdated.contains(form)) {
formsUpdated.add(form);
List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers(form);
for (IFormController formController : cachedFormControllers) {
formsToReload.add(formController);
}
}
if (persist instanceof Form && clientState.getFormManager() instanceof DebugUtils.DebugUpdateFormSupport) {
((DebugUtils.DebugUpdateFormSupport) clientState.getFormManager()).updateForm((Form) persist);
}
} else if (persist instanceof ScriptCalculation) {
ScriptCalculation sc = (ScriptCalculation) persist;
if (((RemoteDebugScriptEngine) clientState.getScriptEngine()).recompileScriptCalculation(sc)) {
List<String> al = new ArrayList<String>();
al.add(sc.getDataProviderID());
try {
String dataSource = clientState.getFoundSetManager().getDataSource(sc.getTable());
((FoundSetManager) clientState.getFoundSetManager()).getRowManager(dataSource).clearCalcs(null, al);
((FoundSetManager) clientState.getFoundSetManager()).flushSQLSheet(dataSource);
} catch (Exception e) {
Debug.error(e);
}
}
// if (clientState instanceof DebugJ2DBClient)
// {
// ((DebugJ2DBClient)clientState).clearUserWindows(); no need for this as window API was refactored and it allows users to clean up dialogs
// }
} else if (persist instanceof Relation) {
((FoundSetManager) clientState.getFoundSetManager()).flushSQLSheet((Relation) persist);
List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers();
try {
String primary = ((Relation) persist).getPrimaryDataSource();
for (IFormController formController : cachedFormControllers) {
if (primary.equals(formController.getDataSource())) {
final IFormController finalController = formController;
final Relation finalRelation = (Relation) persist;
formController.getForm().acceptVisitor(new IPersistVisitor() {
@Override
public Object visit(IPersist o) {
if (o instanceof Tab && Utils.equalObjects(finalRelation.getName(), ((Tab) o).getRelationName())) {
formsToReload.add(finalController);
return o;
}
if (o instanceof Field && ((Field) o).getValuelistID() > 0) {
ValueList vl = clientState.getFlattenedSolution().getValueList(((Field) o).getValuelistID());
if (vl != null && Utils.equalObjects(finalRelation.getName(), vl.getRelationName())) {
formsToReload.add(finalController);
return o;
}
}
if (o instanceof WebComponent) {
WebComponent webComponent = (WebComponent) o;
WebObjectSpecification spec = specProviderState == null ? null : specProviderState.getWebComponentSpecification(webComponent.getTypeName());
if (spec != null) {
Collection<PropertyDescription> properties = spec.getProperties(RelationPropertyType.INSTANCE);
for (PropertyDescription pd : properties) {
if (Utils.equalObjects(webComponent.getFlattenedJson().opt(pd.getName()), finalRelation.getName())) {
formsToReload.add(finalController);
return o;
}
}
}
}
return CONTINUE_TRAVERSAL;
}
});
}
}
} catch (Exception e) {
Debug.error(e);
}
} else if (persist instanceof ValueList) {
ComponentFactory.flushValueList(clientState, (ValueList) persist);
List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers();
for (IFormController formController : cachedFormControllers) {
final IFormController finalController = formController;
final ValueList finalValuelist = (ValueList) persist;
formController.getForm().acceptVisitor(new IPersistVisitor() {
@Override
public Object visit(IPersist o) {
if (o instanceof Field && ((Field) o).getValuelistID() > 0 && ((Field) o).getValuelistID() == finalValuelist.getID()) {
formsToReload.add(finalController);
return o;
}
if (o instanceof WebComponent) {
WebComponent webComponent = (WebComponent) o;
WebObjectSpecification spec = specProviderState == null ? null : specProviderState.getWebComponentSpecification(webComponent.getTypeName());
if (spec != null) {
Collection<PropertyDescription> properties = spec.getProperties(ValueListPropertyType.INSTANCE);
for (PropertyDescription pd : properties) {
if (Utils.equalObjects(webComponent.getFlattenedJson().opt(pd.getName()), finalValuelist.getUUID().toString())) {
formsToReload.add(finalController);
return o;
}
}
}
}
return CONTINUE_TRAVERSAL;
}
});
}
} else if (persist instanceof Style) {
ComponentFactory.flushStyle(null, ((Style) persist));
List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers();
String styleName = ((Style) persist).getName();
for (IFormController formController : cachedFormControllers) {
if (styleName.equals(formController.getForm().getStyleName())) {
formsToReload.add(formController);
}
}
}
}
return new Set[] { scopesToReload, formsToReload };
}
Aggregations