use of com.servoy.j2db.server.ngclient.property.types.PropertyPath 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;
}
use of com.servoy.j2db.server.ngclient.property.types.PropertyPath in project servoy-client by Servoy.
the class FormElementHelper method generateFormComponentElements.
private static List<FormElement> generateFormComponentElements(INGFormElement parent, PropertyDescription pd, JSONObject json, Form frm, FlattenedSolution fs) {
List<FormElement> elements = new ArrayList<>();
List<IFormElement> persistElements = generateFormComponentPersists(parent, pd, json, frm, fs);
for (IFormElement formElement : persistElements) {
elements.add(new FormElement(formElement, fs, new PropertyPath(), parent.getDesignId() != null));
}
return elements;
}
use of com.servoy.j2db.server.ngclient.property.types.PropertyPath in project servoy-client by Servoy.
the class FormElementHelper method createBodyPortalFormElement.
private FormElement createBodyPortalFormElement(BodyPortal listViewPortal, FlattenedSolution fs, final boolean isInDesigner) {
Form form = listViewPortal.getForm();
Part bodyPart = null;
for (Part prt : Utils.iterate(form.getParts())) {
if (prt.getPartType() == Part.BODY) {
bodyPart = prt;
break;
}
}
if (bodyPart != null) {
try {
String name = "svy_lvp_" + form.getName();
int startPos = form.getPartStartYPos(bodyPart.getID());
int endPos = bodyPart.getHeight();
int bodyheight = endPos - startPos;
JSONObject portal = new JSONObject();
portal.put("name", name);
portal.put("multiLine", !listViewPortal.isTableview());
portal.put("rowHeight", !listViewPortal.isTableview() ? bodyheight : getRowHeight(form));
int scrollbars = form.getScrollbars();
if (!listViewPortal.isTableview()) {
// handle horizontal scrollbar on form level for listview
int verticalScrollBars = ISupportScrollbars.VERTICAL_SCROLLBAR_AS_NEEDED;
if ((form.getScrollbars() & ISupportScrollbars.VERTICAL_SCROLLBAR_ALWAYS) != 0) {
verticalScrollBars = ISupportScrollbars.VERTICAL_SCROLLBAR_ALWAYS;
} else if ((form.getScrollbars() & ISupportScrollbars.VERTICAL_SCROLLBAR_NEVER) != 0) {
verticalScrollBars = ISupportScrollbars.VERTICAL_SCROLLBAR_NEVER;
}
scrollbars = ISupportScrollbars.HORIZONTAL_SCROLLBAR_NEVER + verticalScrollBars;
}
portal.put("scrollbars", scrollbars);
if (listViewPortal.isTableview()) {
int headerHeight = 30;
if (form.hasPart(Part.HEADER)) {
headerHeight = 0;
}
portal.put("headerHeight", headerHeight);
portal.put("sortable", form.getOnSortCmdMethodID() != -1);
}
portal.put("readOnlyMode", form.getNgReadOnlyMode());
JSONObject location = new JSONObject();
location.put("x", 0);
location.put("y", isInDesigner ? startPos : 0);
portal.put("location", location);
JSONObject size = new JSONObject();
// size.put("width", (listViewPortal.isTableview() && !fillsWidth) ? getGridWidth(form) : form.getWidth());
size.put("width", form.getWidth());
size.put("height", bodyheight);
portal.put("size", size);
portal.put("visible", listViewPortal.getVisible());
portal.put("enabled", listViewPortal.getEnabled());
// empty contents; will be updated afterwards directly with form element values for components
portal.put("childElements", new JSONArray());
JSONObject relatedFoundset = new JSONObject();
relatedFoundset.put("foundsetSelector", "");
portal.put("relatedFoundset", relatedFoundset);
PropertyPath propertyPath = new PropertyPath();
propertyPath.setShouldAddElementName();
FormElement portalFormElement = new FormElement("servoycore-portal", portal, form, name, fs, propertyPath, isInDesigner);
PropertyDescription pd = portalFormElement.getWebComponentSpec().getProperties().get("childElements");
if (pd != null)
pd = ((CustomJSONArrayType<?, ?>) pd.getType()).getCustomJSONTypeDefinition();
if (pd == null) {
Debug.error(new RuntimeException("Cannot find component definition special type to use for portal."));
return null;
}
ComponentPropertyType type = ((ComponentPropertyType) pd.getType());
Map<String, Object> portalFormElementProperties = new HashMap<>(portalFormElement.getRawPropertyValues());
portalFormElementProperties.put("anchors", IAnchorConstants.ALL);
portalFormElementProperties.put("offsetY", startPos);
portalFormElementProperties.put("partHeight", bodyPart.getHeight());
portalFormElementProperties.put("formview", true);
// now put real child component form element values in "childElements"
Iterator<IPersist> it = form.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
// contains actually ComponentTypeFormElementValue objects
List<Object> children = new ArrayList<>();
List<IPersist> labelFors = new ArrayList<>();
propertyPath.add(portalFormElement.getName());
propertyPath.add("childElements");
// it's a generated table-view form portal (BodyPortal); we just
// have to set the Portal's tabSeq to the first one of it's children for it to work properly
int minBodyPortalTabSeq = -2;
while (it.hasNext()) {
IPersist persist = it.next();
if (persist instanceof IFormElement) {
Point loc = CSSPositionUtils.getLocation((IFormElement) persist);
if (startPos <= loc.y && endPos > loc.y) {
if (listViewPortal.isTableview() && persist instanceof GraphicalComponent && ((GraphicalComponent) persist).getLabelFor() != null)
continue;
propertyPath.add(children.size());
FormElement fe = getFormElement((IFormElement) persist, fs, propertyPath, isInDesigner);
if (listViewPortal.isTableview()) {
String elementName = ((IFormElement) persist).getName();
Iterator<GraphicalComponent> graphicalComponents = form.getGraphicalComponents();
boolean hasLabelFor = false;
while (graphicalComponents.hasNext()) {
GraphicalComponent gc = graphicalComponents.next();
if (gc.getLabelFor() != null && Utils.equalObjects(elementName, gc.getLabelFor()) && startPos <= gc.getLocation().y && endPos > gc.getLocation().y) {
labelFors.add(gc);
hasLabelFor = true;
break;
}
}
Map<String, Object> feRawProperties = new HashMap<>(fe.getRawPropertyValues());
feRawProperties.put("componentIndex", Integer.valueOf(children.size()));
if (hasLabelFor)
feRawProperties.put("headerIndex", Integer.valueOf(labelFors.size() - 1));
fe.updatePropertyValuesDontUse(feRawProperties);
}
children.add(type.getFormElementValue(null, pd, propertyPath, fe, fs));
propertyPath.backOneLevel();
Collection<PropertyDescription> tabSequenceProperties = fe.getWebComponentSpec().getProperties(NGTabSeqPropertyType.NG_INSTANCE);
for (PropertyDescription tabSeqProperty : tabSequenceProperties) {
String tabSeqPropertyName = tabSeqProperty.getName();
Integer tabSeqVal = (Integer) fe.getPropertyValue(tabSeqPropertyName);
// default is 0 == DEFAULT tab sequence
if (tabSeqVal == null)
tabSeqVal = Integer.valueOf(0);
if (minBodyPortalTabSeq < 0 || (minBodyPortalTabSeq > tabSeqVal.intValue() && tabSeqVal.intValue() >= 0))
minBodyPortalTabSeq = tabSeqVal.intValue();
}
}
}
}
propertyPath.backOneLevel();
propertyPath.backOneLevel();
portalFormElementProperties.put("childElements", children.toArray());
if (listViewPortal.isTableview()) {
propertyPath.add("headers");
List<Object> headers = new ArrayList<>();
for (IPersist persist : labelFors) {
if (persist instanceof IFormElement) {
propertyPath.add(headers.size());
FormElement fe = getFormElement((IFormElement) persist, fs, propertyPath, isInDesigner);
headers.add(type.getFormElementValue(null, pd, propertyPath, fe, fs));
propertyPath.backOneLevel();
}
}
propertyPath.backOneLevel();
propertyPath.backOneLevel();
portalFormElementProperties.put("headers", headers.toArray());
}
// table view tab seq. is the minimum of it's children tabSeq'es
portalFormElementProperties.put("tabSeq", Integer.valueOf(minBodyPortalTabSeq));
portalFormElement.updatePropertyValuesDontUse(portalFormElementProperties);
return portalFormElement;
} catch (JSONException ex) {
Debug.error("Cannot create list view portal component", ex);
}
}
return null;
}
Aggregations