use of com.servoy.j2db.persistence.IFormElement in project servoy-client by Servoy.
the class ChildrenJSONGenerator method isSecurityVisible.
public boolean isSecurityVisible(IPersist persist) {
if (context.getApplication() == null || persist.getUUID() == null || !(persist instanceof IFormElement))
return true;
int access = context.getApplication().getFlattenedSolution().getSecurityAccess(persist.getUUID(), form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
boolean b_visible = ((access & IRepository.VIEWABLE) != 0);
return b_visible;
}
use of com.servoy.j2db.persistence.IFormElement in project servoy-client by Servoy.
the class ChildrenJSONGenerator method visit.
@SuppressWarnings("nls")
@Override
public Object visit(IPersist o) {
if (o == skip)
return IPersistVisitor.CONTINUE_TRAVERSAL;
if (!isSecurityVisible(o))
return IPersistVisitor.CONTINUE_TRAVERSAL;
if (o instanceof IFormElement) {
FormElement fe = null;
if (part != null) {
int startPos = form.getPartStartYPos(part.getID());
int endPos = part.getHeight();
Point location = CSSPositionUtils.getLocation((IFormElement) o);
if (location != null && (startPos > location.y || endPos <= location.y)) {
return IPersistVisitor.CONTINUE_TRAVERSAL;
}
}
if (cache != null) {
// this is for form component elements finding
fe = cache.getFormElement((IFormElement) o, this.context.getSolution(), null, designer);
}
if (fe == null && formUI != null) {
List<FormElement> cachedFormElements = formUI.getFormElements();
for (FormElement cachedFE : cachedFormElements) {
if (Utils.equalObjects(cachedFE.getPersistIfAvailable(), o)) {
fe = cachedFE;
break;
}
}
}
fe = fe != null ? fe : FormElementHelper.INSTANCE.getFormElement((IFormElement) o, this.context.getSolution(), null, designer);
writer.object();
writeFormElement(writer, o, form, fe, formUI, context, designer);
if (o instanceof WebComponent) {
WebObjectSpecification spec = fe.getWebComponentSpec();
if (spec != null) {
Collection<PropertyDescription> properties = spec.getProperties(FormComponentPropertyType.INSTANCE);
if (properties.size() > 0) {
boolean isResponsive = false;
List<String> children = new ArrayList<>();
for (PropertyDescription pd : properties) {
Object propertyValue = fe.getPropertyValue(pd.getName());
Form frm = FormComponentPropertyType.INSTANCE.getForm(propertyValue, context.getSolution());
if (frm == null)
continue;
isResponsive = frm.isResponsiveLayout();
// listformcomponents that are responsive must be also send over here (the components are also send over in the FormComponentSabloValue)
// this will result in duplicate component data, but we need the structure (and the component names in the right place)
// if (!isResponsive && pd.getConfig() instanceof ComponentTypeConfig && ((ComponentTypeConfig)pd.getConfig()).forFoundset != null)
// continue;
children.add("children_" + pd.getName());
writer.key("children_" + pd.getName());
writer.array();
FormComponentCache fccc = FormElementHelper.INSTANCE.getFormComponentCache(fe, pd, (JSONObject) propertyValue, frm, context.getSolution());
if (isResponsive) {
// layout containers are not in the cache we need to generate manually the model
frm.acceptVisitor(new ChildrenJSONGenerator(writer, context, frm, new IFormElementCache() {
@Override
public FormElement getFormElement(IFormElement component, FlattenedSolution flattendSol, PropertyPath path, boolean design) {
for (FormElement formElement : fccc.getFormComponentElements()) {
if (component.getID() == formElement.getPersistIfAvailable().getID()) {
return formElement;
}
}
return FormElementHelper.INSTANCE.getFormElement(component, flattendSol, path, design);
}
}, null, this.form, false, designer), PositionComparator.XY_PERSIST_COMPARATOR);
} else {
for (FormElement element : fccc.getFormComponentElements()) {
IFormElement persistOfElement = (IFormElement) element.getPersistIfAvailable();
persistOfElement.acceptVisitor(new ChildrenJSONGenerator(writer, context, null, null, null, this.form, false, designer), FORM_INDEX_WITH_HIERARCHY_COMPARATOR);
}
}
writer.endArray();
}
writer.key("formComponent");
writer.array();
children.stream().forEach((child) -> writer.value(child));
writer.endArray();
}
}
}
writer.endObject();
} else if (o instanceof LayoutContainer) {
writer.object();
LayoutContainer layoutContainer = (LayoutContainer) o;
writeLayoutContainer(writer, layoutContainer, formUI, designer);
writer.key("children");
writer.array();
o.acceptVisitor(new ChildrenJSONGenerator(writer, context, o, cache, null, this.form, false, designer), PositionComparator.XY_PERSIST_COMPARATOR);
writer.endArray();
writer.endObject();
return IPersistVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
}
return IPersistVisitor.CONTINUE_TRAVERSAL;
}
use of com.servoy.j2db.persistence.IFormElement in project servoy-client by Servoy.
the class WebFormUI method contributeComponentToElementsScope.
private void contributeComponentToElementsScope(ElementScope elementsScope, FormElement fe, WebObjectSpecification componentSpec, WebFormComponent component) {
Object lengthOfEl = elementsScope.get("length", elementsScope);
int lastElementByIndex = (lengthOfEl instanceof Integer ? ((Integer) lengthOfEl).intValue() : 0);
if (!FormElement.ERROR_BEAN.equals(componentSpec.getName()) && (!fe.getName().startsWith("svy_") || ((fe.getPersistIfAvailable() instanceof IFormElement) && ((IFormElement) fe.getPersistIfAvailable()).getGroupID() != null))) {
RuntimeWebComponent runtimeComponent = new RuntimeWebComponent(component, componentSpec);
if (fe.isLegacy() || ((fe.getForm().getView() == IForm.LIST_VIEW || fe.getForm().getView() == FormController.LOCKED_LIST_VIEW || fe.getForm().getView() == FormController.TABLE_VIEW || fe.getForm().getView() == FormController.LOCKED_TABLE_VIEW) && fe.getTypeName().startsWith("servoydefault-"))) {
// add legacy behavior
runtimeComponent.setPrototype(new RuntimeLegacyComponent(component));
}
if (!fe.getName().startsWith("svy_")) {
elementsScope.put(fe.getRawName(), formController.getFormScope(), runtimeComponent);
elementsScope.put(lastElementByIndex, formController.getFormScope(), runtimeComponent);
}
String groupID = fe.getPersistIfAvailable() instanceof IFormElement ? ((IFormElement) fe.getPersistIfAvailable()).getGroupID() : null;
if (groupID != null) {
if (groups == null)
groups = new HashMap<String, RuntimeWebGroup>(4);
RuntimeWebGroup group = groups.get(groupID);
if (group == null) {
String groupName = FormElementGroup.getName(groupID);
group = new RuntimeWebGroup(groupName);
group.setParentScope(component.getDataConverterContext().getApplication().getScriptEngine().getSolutionScope());
elementsScope.put(groupName, formController.getFormScope(), group);
groups.put(groupID, group);
}
group.add(runtimeComponent);
}
}
}
use of com.servoy.j2db.persistence.IFormElement in project servoy-client by Servoy.
the class WebFormUI method removeComponentFromElementsScope.
// this should be the opposite of formUI.contributeComponentToElementsScope(...)
public void removeComponentFromElementsScope(FormElement fe, WebObjectSpecification componentSpec, WebFormComponent component) {
ElementScope elementsScope = getElementsScope();
if (elementsScope != null) {
if (!FormElement.ERROR_BEAN.equals(componentSpec.getName()) && (!fe.getName().startsWith("svy_") || ((fe.getPersistIfAvailable() instanceof IFormElement) && ((IFormElement) fe.getPersistIfAvailable()).getGroupID() != null))) {
if (!fe.getName().startsWith("svy_")) {
RuntimeWebComponent runtimeComponent = (RuntimeWebComponent) elementsScope.remove(fe.getRawName());
elementsScope.removeIndexByValue(runtimeComponent);
}
String groupID = fe.getPersistIfAvailable() instanceof IFormElement ? ((IFormElement) fe.getPersistIfAvailable()).getGroupID() : null;
if (groupID != null) {
if (groups == null)
groups = new HashMap<String, RuntimeWebGroup>(4);
RuntimeWebGroup group = groups.get(groupID);
if (group != null) {
String groupName = FormElementGroup.getName(groupID);
group.remove(component);
if (group.getComponentCount() == 0)
elementsScope.remove(groupName);
groups.remove(groupID);
}
}
}
} else {
Debug.error(new RuntimeException("Trying to remove component from a non-existent elements scope for form: " + getName()));
}
}
use of com.servoy.j2db.persistence.IFormElement in project servoy-client by Servoy.
the class FormElementHelper method getFormElement.
public FormElement getFormElement(IFormElement formElement, FlattenedSolution fs, PropertyPath propertyPath, final boolean designer) {
// dont cache if solution model is used (media,valuelist,relations can be changed for a none changed element)
if (designer || (fs.getSolutionCopy(false) != null) || ((AbstractBase) formElement).getRuntimeProperty(FORM_COMPONENT_FORM_NAME) != null) {
if (formElement instanceof BodyPortal)
return createBodyPortalFormElement((BodyPortal) formElement, fs, designer);
else
return new FormElement(formElement, fs, propertyPath == null ? new PropertyPath().setShouldAddElementName() : propertyPath, designer);
}
FormElement persistWrapper = persistWrappers.get(formElement);
if (persistWrapper == null) {
if (propertyPath == null) {
propertyPath = new PropertyPath();
propertyPath.setShouldAddElementName();
}
if (formElement instanceof BodyPortal)
persistWrapper = createBodyPortalFormElement((BodyPortal) formElement, getSharedFlattenedSolution(fs), designer);
else
persistWrapper = new FormElement(formElement, getSharedFlattenedSolution(fs), propertyPath, designer);
FormElement existing = persistWrappers.putIfAbsent(formElement, persistWrapper);
if (existing != null) {
persistWrapper = existing;
}
}
return persistWrapper;
}
Aggregations