use of com.servoy.j2db.server.ngclient.FormElement in project servoy-client by Servoy.
the class FormTemplateObjectWrapper method wrap.
@Override
public TemplateModel wrap(Object obj) throws TemplateModelException {
TemplateModel model = wrapperCache.get(obj);
if (model != null)
return model;
Object wrapped;
if (obj instanceof Form) {
wrapped = getFormWrapper((Form) obj);
} else if (obj instanceof Object[]) {
this.flattenedForm = context.getSolution().getFlattenedForm((Form) ((Object[]) obj)[0]);
wrapped = new FormWrapper(flattenedForm, (String) ((Object[]) obj)[1], useControllerProvider, context, design, runtimeProperties != null ? runtimeProperties.getJSONObject("") : null);
} else if (obj == DefaultNavigator.INSTANCE) {
wrapped = new FormElement(DefaultNavigator.INSTANCE, context.getSolution(), new PropertyPath(), design);
JSONObject object = runtimeProperties != null ? runtimeProperties.optJSONObject(((FormElement) wrapped).getName()) : null;
if (object != null) {
wrapped = new FormElementContext((FormElement) wrapped, context, object);
}
} else if (obj instanceof Part) {
wrapped = new PartWrapper((Part) obj, flattenedForm, context, design);
} else if (obj instanceof IFormElement) {
FormElement fe = null;
if (formUI != null) {
List<FormElement> cachedFormElements = formUI.getFormElements();
for (FormElement cachedFE : cachedFormElements) {
if (Utils.equalObjects(cachedFE.getPersistIfAvailable(), obj)) {
fe = cachedFE;
break;
}
}
if (fe == null) {
Form parentForm = (Form) ((IFormElement) obj).getAncestor(IRepository.FORMS);
if (parentForm != null && parentForm.isFormComponent()) {
for (WebComponent webComponent : formUI.getAllComponents()) {
if (webComponent instanceof WebFormComponent) {
FormElement cachedFE = ((WebFormComponent) webComponent).getFormElement();
if (Utils.equalObjects(cachedFE.getPersistIfAvailable(), obj)) {
fe = cachedFE;
break;
}
}
}
}
}
}
FormElement formElement = fe != null ? fe : FormElementHelper.INSTANCE.getFormElement((IFormElement) obj, context.getSolution(), null, false);
JSONObject object = runtimeProperties != null ? runtimeProperties.optJSONObject(formElement.getName()) : null;
wrapped = new FormElementContext(formElement, context, object);
} else {
wrapped = obj;
}
TemplateModel wrap = super.wrap(wrapped);
wrapperCache.put(obj, wrap);
return wrap;
}
use of com.servoy.j2db.server.ngclient.FormElement 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.FormElement in project servoy-client by Servoy.
the class FormWrapper method getCSSPositionElementNames.
private Map<String, Boolean> getCSSPositionElementNames() {
Map<String, Boolean> names = new HashMap<String, Boolean>();
names.putAll(formComponentCSSPositionElementNames);
List<IFormElement> persists = form.getFlattenedObjects(null);
for (IFormElement persist : persists) {
if (form.getUseCssPosition().booleanValue() || CSSPositionUtils.isInAbsoluteLayoutMode(persist)) {
FormElement formElement = FormElementHelper.INSTANCE.getFormElement(persist, context.getSolution(), null, design);
String name = formElement.getDesignId() != null ? formElement.getDesignId() : formElement.getName();
if (!names.containsKey(name))
names.put(name, Boolean.TRUE);
}
}
return names;
}
use of com.servoy.j2db.server.ngclient.FormElement in project servoy-client by Servoy.
the class CSSPositionPropertyType method toJSON.
public JSONWriter toJSON(JSONWriter writer, String key, CSSPosition object, PropertyDescription pd, DataConversion clientConversion, IBrowserConverterContext dataConverterContext) throws JSONException {
FormElement fe = null;
if (dataConverterContext != null && dataConverterContext.getWebObject() instanceof WebFormComponent) {
fe = ((WebFormComponent) dataConverterContext.getWebObject()).getFormElement();
}
FlattenedSolution fs = null;
Form form = null;
if (dataConverterContext != null && dataConverterContext.getWebObject() instanceof IContextProvider) {
fs = ((IContextProvider) dataConverterContext.getWebObject()).getDataConverterContext().getApplication().getFlattenedSolution();
if (((IContextProvider) dataConverterContext.getWebObject()).getDataConverterContext().getForm() != null) {
form = ((IContextProvider) dataConverterContext.getWebObject()).getDataConverterContext().getForm().getForm();
}
}
return toJSON(writer, key, object, pd, clientConversion, fe, fs, form);
}
use of com.servoy.j2db.server.ngclient.FormElement 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;
}
Aggregations