use of com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache in project servoy-client by Servoy.
the class FormComponentSabloValue method getCache.
public FormComponentCache getCache() {
Container parent = component.findParent(WebFormUI.class);
if (parent instanceof WebFormUI) {
// cache it on the FormUI object, because FormElementHelper can only cache when it is not solution model, but then the cache is constantly changing..
FormComponentCache fcc = ((WebFormUI) parent).getFormComponentCache(component);
if (fcc != null)
return fcc;
fcc = FormElementHelper.INSTANCE.getFormComponentCache(formElement, pd, formElementValue, form, dal.getApplication().getFlattenedSolution());
((WebFormUI) parent).cacheFormComponentCache(component, fcc);
return fcc;
}
return FormElementHelper.INSTANCE.getFormComponentCache(formElement, pd, formElementValue, form, dal.getApplication().getFlattenedSolution());
}
use of com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache in project servoy-client by Servoy.
the class FormComponentSabloValue method getComponents.
private ComponentTypeSabloValue[] getComponents() {
FormComponentCache formComponentCache = getCache();
if (currentFormComponentCache != formComponentCache) {
List<FormElement> elements = formComponentCache.getFormComponentElements();
List<ComponentTypeSabloValue> componentsList = new ArrayList<ComponentTypeSabloValue>(elements.size());
PropertyPath path = new PropertyPath();
path.add(component.getName());
path.add("containedForm");
path.add("childElements");
JSONObject tags = new JSONObject();
tags.put(ComponentTypeSabloValue.TAG_ADD_TO_ELEMENTS_SCOPE, true);
PropertyDescription compPd = new PropertyDescriptionBuilder().withName(pd.getName()).withType(ComponentPropertyType.INSTANCE).withConfig(pd.getConfig()).withTags(tags).build();
int j = 0;
for (FormElement element : elements) {
path.add(j);
ComponentTypeFormElementValue elementValue = ComponentPropertyType.INSTANCE.getFormElementValue(null, compPd, path, element, dal.getApplication().getFlattenedSolution());
ComponentTypeSabloValue ctsv = ComponentPropertyType.INSTANCE.toSabloComponentValue(elementValue, compPd, element, component, dal);
if (ctsv != null) {
// if it is null then it is probably a child component that was blocked by security (visibility == false); in that case just ignore it (similar to what portal does through .spec setting on comp. array to ignore null values at runtime)
j++;
componentsList.add(ctsv);
}
path.backOneLevel();
if (element.getWebComponentSpec() != null) {
Collection<PropertyDescription> properties = element.getWebComponentSpec().getProperties(FormComponentPropertyType.INSTANCE);
if (properties.size() > 0) {
for (PropertyDescription pd : properties) {
Object propertyValue = element.getPropertyValue(pd.getName());
Form frm = FormComponentPropertyType.INSTANCE.getForm(propertyValue, dal.getApplication().getFlattenedSolution());
if (frm == null)
continue;
FormComponentCache innerCache = FormElementHelper.INSTANCE.getFormComponentCache(element, pd, (JSONObject) propertyValue, frm, dal.getApplication().getFlattenedSolution());
List<FormElement> innerElements = innerCache.getFormComponentElements();
for (FormElement innerElement : innerElements) {
path.add(j);
elementValue = ComponentPropertyType.INSTANCE.getFormElementValue(null, compPd, path, innerElement, dal.getApplication().getFlattenedSolution());
// use main property
ctsv = ComponentPropertyType.INSTANCE.toSabloComponentValue(elementValue, compPd, innerElement, component, dal);
if (ctsv != null) {
// if it is null then it is probably a child component that was blocked by security (visibility == false); in that case just ignore it (similar to what portal does through .spec setting on comp. array to ignore null values at runtime)
j++;
componentsList.add(ctsv);
}
path.backOneLevel();
}
}
}
}
}
// re-attach
if (currentFormComponentCache != null && changeMonitor != null && webObjectContext != null) {
for (ComponentTypeSabloValue componentTypeSabloValue : componentsList) {
componentTypeSabloValue.attachToBaseObject(changeMonitor, webObjectContext);
}
}
currentFormComponentCache = formComponentCache;
components = componentsList.toArray(new ComponentTypeSabloValue[0]);
}
return components;
}
use of com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache in project servoy-client by Servoy.
the class FormWrapper method checkFormComponents.
private void checkFormComponents(List<IFormElement> components, FormElement formComponentFormElement, Set<String> recursiveCheck) {
// if it's not a form component then .spec will not contain properties of type FormComponentPropertyType.INSTANCE and nothing will happen below
WebObjectSpecification spec = formComponentFormElement.getWebComponentSpec();
if (spec != null) {
Collection<PropertyDescription> properties = spec.getProperties(FormComponentPropertyType.INSTANCE);
if (properties.size() > 0) {
for (PropertyDescription pd : properties) {
Object config = pd.getConfig();
boolean isRepeating = config instanceof ComponentTypeConfig && ((ComponentTypeConfig) config).forFoundset != null;
Object propertyValue = formComponentFormElement.getPropertyValue(pd.getName());
Form frm = FormComponentPropertyType.INSTANCE.getForm(propertyValue, context.getSolution());
if (frm == null)
continue;
if (!recursiveCheck.add(frm.getName())) {
// $NON-NLS-1$
Debug.error("recursive reference found between (List)FormComponents: " + recursiveCheck);
continue;
}
FormComponentCache cache = FormElementHelper.INSTANCE.getFormComponentCache(formComponentFormElement, pd, (JSONObject) propertyValue, frm, context.getSolution());
Dimension frmSize = frm.getSize();
for (FormElement element : cache.getFormComponentElements()) {
IFormElement persistOfElement = (IFormElement) element.getPersistIfAvailable();
if ((!isRepeating || design))
components.add(persistOfElement);
formComponentParentSizes.put(element.getName(), frmSize);
if (!frm.isResponsiveLayout()) {
formComponentsLayout.put(element.getName(), Boolean.TRUE);
}
if (frm.getUseCssPosition()) {
String name = element.getDesignId() != null ? element.getDesignId() : element.getName();
if (!formComponentCSSPositionElementNames.containsKey(name)) {
formComponentCSSPositionElementNames.put(name, Boolean.TRUE);
}
}
checkFormComponents(components, element, recursiveCheck);
}
formComponentTemplates.put(cache.getHtmlTemplateUUIDForAngular(), cache.getTemplate());
recursiveCheck.remove(frm.getName());
}
}
}
}
use of com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache in project servoy-client by Servoy.
the class FormComponentPropertyType method toSabloComponentValue.
@Override
public Object toSabloComponentValue(Object formElementValue, PropertyDescription pd, INGFormElement formElement, WebFormComponent component, DataAdapterList dataAdapterList) {
Form form = getForm(formElementValue, dataAdapterList.getApplication().getFlattenedSolution());
if (form != null) {
if (pd.getConfig() instanceof ComponentTypeConfig && ((ComponentTypeConfig) pd.getConfig()).forFoundset != null) {
return new FormComponentSabloValue(formElement, (JSONObject) formElementValue, pd, dataAdapterList, component, form);
} else {
FormComponentCache formComponentCache = FormElementHelper.INSTANCE.getFormComponentCache(formElement, pd, (JSONObject) formElementValue, form, dataAdapterList.getApplication().getFlattenedSolution());
List<FormElement> elements = formComponentCache.getFormComponentElements();
IWebFormUI formUI = component.findParent(IWebFormUI.class);
for (FormElement element : elements) {
WebFormComponent child = ComponentFactory.createComponent(dataAdapterList.getApplication(), dataAdapterList, element, component.getParent(), dataAdapterList.getForm().getForm());
formUI.contributeComponentToElementsScope(element, element.getWebComponentSpec(), child);
}
}
}
return formElementValue;
}
use of com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache in project servoy-client by Servoy.
the class FormComponentPropertyType method toRhinoValue.
@Override
public Object toRhinoValue(Object webComponentValue, PropertyDescription pd, IWebObjectContext componentOrService, Scriptable startScriptable) {
Scriptable newObject = DefaultScope.newObject(startScriptable);
WebFormComponent webFormComponent = (WebFormComponent) componentOrService;
FlattenedSolution fs = webFormComponent.getDataConverterContext().getSolution();
FormComponentCache cache = null;
if (webComponentValue instanceof FormComponentSabloValue) {
cache = ((FormComponentSabloValue) webComponentValue).getCache();
} else {
Form form = getForm(webComponentValue, fs);
if (form == null)
return null;
// TODO return here a NativeScriptable object that understand the full hiearchy?
cache = FormElementHelper.INSTANCE.getFormComponentCache(webFormComponent.getFormElement(), pd, (JSONObject) webComponentValue, form, fs);
}
IWebFormUI formUI = webFormComponent.findParent(IWebFormUI.class);
String prefix = FormElementHelper.getStartElementName(webFormComponent.getFormElement(), pd);
for (FormElement fe : cache.getFormComponentElements()) {
String name = fe.getName();
if (name != null && !name.startsWith(FormElement.SVY_NAME_PREFIX)) {
RuntimeWebComponent webComponent = formUI.getRuntimeWebComponent(fe.getRawName());
if (webComponent != null) {
newObject.put(name.substring(prefix.length()), newObject, webComponent);
}
}
}
return newObject;
}
Aggregations