use of com.servoy.j2db.server.ngclient.scripting.WebComponentFunction in project servoy-client by Servoy.
the class RuntimeWebComponent method get.
@Override
public Object get(final String name, final Scriptable start) {
if (specProperties != null && specProperties.contains(name)) {
PropertyDescription pd = webComponentSpec.getProperties().get(name);
if (WebFormComponent.isDesignOnlyProperty(pd))
return Scriptable.NOT_FOUND;
return NGConversions.INSTANCE.convertSabloComponentToRhinoValue(component.getProperty(name), pd, component, start);
}
if ("getFormName".equals(name)) {
return new Callable() {
@Override
public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
IWebFormUI parent = component.findParent(IWebFormUI.class);
if (parent != null) {
return parent.getController().getName();
}
return null;
}
};
}
if ("getDesignTimeProperty".equals(name) && component.getFormElement().getPersistIfAvailable() instanceof AbstractBase) {
return new Callable() {
@Override
public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
return Utils.parseJSExpression(((AbstractBase) component.getFormElement().getPersistIfAvailable()).getCustomDesignTimeProperty((String) args[0]));
}
};
}
if ("getDesignProperties".equals(name) && component.getFormElement().getPersistIfAvailable() instanceof AbstractBase) {
return new Callable() {
@Override
public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
Map<String, Object> designProperties = ((AbstractBase) component.getFormElement().getPersistIfAvailable()).getMergedCustomDesignTimeProperties();
Map<String, Object> parsedMap = new HashMap<String, Object>();
designProperties.entrySet().forEach(entry -> {
parsedMap.put(entry.getKey(), Utils.parseJSExpression(entry.getValue()));
});
return parsedMap;
}
};
}
final Function func = apiFunctions.get(name);
if (func != null && isApiFunctionEnabled(name)) {
final List<Pair<String, String>> oldVisibleForms = getVisibleForms();
return new BaseFunction() {
@Override
public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
Object retValue;
cx.putThreadLocal(SERVER_SIDE_SCRIPT_EXECUTE, Boolean.TRUE);
try {
retValue = func.call(cx, scope, thisObj, args);
} finally {
cx.removeThreadLocal(SERVER_SIDE_SCRIPT_EXECUTE);
}
if (!(func instanceof WebComponentFunction)) {
WebObjectFunctionDefinition def = webComponentSpec.getApiFunctions().get(name);
retValue = NGConversions.INSTANCE.convertServerSideRhinoToRhinoValue(retValue, def.getReturnType(), component, null);
}
updateVisibleContainers(oldVisibleForms);
return retValue;
}
};
}
// check if we have a setter/getter for this property
if (name != null && name.length() > 0) {
String uName = new StringBuffer(name.substring(0, 1).toUpperCase()).append(name.substring(1)).toString();
if (apiFunctions.containsKey("set" + uName) && apiFunctions.containsKey("get" + uName)) {
// call getter
Function propertyGetter = apiFunctions.get("get" + uName);
return propertyGetter.call(Context.getCurrentContext(), start, start, new Object[] {});
}
}
if ("svyMarkupId".equals(name)) {
String formName = null;
IWebFormUI parent = component.findParent(IWebFormUI.class);
if (parent != null) {
formName = parent.getController().getName();
} else {
formName = component.getFormElement().getForm().getName();
}
return ComponentFactory.getMarkupId(formName, component.getName());
}
// is this really needed? will not prototype be looked at automatically by Rhino code?
if (prototypeScope != null) {
return prototypeScope.get(name, start);
}
return Scriptable.NOT_FOUND;
}
Aggregations