use of com.servoy.j2db.persistence.IFormElement 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.persistence.IFormElement 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;
}
use of com.servoy.j2db.persistence.IFormElement in project servoy-client by Servoy.
the class FormElementHelper method addFormComponentProperties.
private void addFormComponentProperties(Collection<PropertyDescription> formComponentProperties, IFormElement formElement, FlattenedSolution flattenedSolution, Map<TabSeqProperty, Integer> cachedTabSeq, List<TabSeqProperty> selected, List<TabSeqProperty> listFormComponentElements, boolean design, Set<String> recursionCheck) {
if (formComponentProperties != null && formComponentProperties.size() > 0) {
boolean isListFormComponent = isListFormComponent(formComponentProperties);
// avoid infinite cycle here
FormElement formComponentEl = FormElementHelper.INSTANCE.getFormElement(formElement, flattenedSolution, null, design);
for (PropertyDescription property : formComponentProperties) {
Object frmValue = formComponentEl.getPropertyValue(property.getName());
Form frm = FormComponentPropertyType.INSTANCE.getForm(frmValue, flattenedSolution);
if (frm == null)
continue;
if (!recursionCheck.add(frm.getName())) {
// $NON-NLS-1$
Debug.error("recursive reference found between (List)FormComponents: " + recursionCheck);
continue;
}
// do not use the formcomponentcache, we do not want formelement with wrong tabseq to be cached, must caclulate first the sequence
List<IFormElement> elements = generateFormComponentPersists(formComponentEl, property, (JSONObject) frmValue, frm, flattenedSolution);
for (IFormElement element : elements) {
if (element instanceof ISupportTabSeq) {
if (isListFormComponent && listFormComponentElements != null) {
listFormComponentElements.add(new TabSeqProperty(element, StaticContentSpecLoader.PROPERTY_TABSEQ.getPropertyName()));
} else if (((ISupportTabSeq) element).getTabSeq() >= 0) {
selected.add(new TabSeqProperty(element, StaticContentSpecLoader.PROPERTY_TABSEQ.getPropertyName(), CSSPositionUtils.getLocation(formElement)));
} else {
cachedTabSeq.put(new TabSeqProperty(element, StaticContentSpecLoader.PROPERTY_TABSEQ.getPropertyName()), Integer.valueOf(-2));
}
} else if (FormTemplateGenerator.isWebcomponentBean(element)) {
String nestedDomponentType = FormTemplateGenerator.getComponentTypeName(element);
WebObjectSpecification nestedSpecification = WebComponentSpecProvider.getSpecProviderState().getWebComponentSpecification(nestedDomponentType);
if (nestedSpecification != null) {
Collection<PropertyDescription> nestedProperties = nestedSpecification.getProperties(NGTabSeqPropertyType.NG_INSTANCE);
if (nestedProperties != null && nestedProperties.size() > 0) {
IBasicWebComponent webComponent = (IBasicWebComponent) element;
for (PropertyDescription tabSeqProperty : nestedProperties) {
int tabseq = Utils.getAsInteger(webComponent.getProperty(tabSeqProperty.getName()));
if (tabseq >= 0 && isListFormComponent && listFormComponentElements != null) {
// all elements will have the tabseq of the list
listFormComponentElements.add(new TabSeqProperty(element, tabSeqProperty.getName()));
} else if (tabseq >= 0) {
selected.add(new TabSeqProperty(element, tabSeqProperty.getName(), CSSPositionUtils.getLocation(formElement)));
} else {
cachedTabSeq.put(new TabSeqProperty(element, tabSeqProperty.getName()), Integer.valueOf(-2));
}
}
}
nestedProperties = nestedSpecification.getProperties(FormComponentPropertyType.INSTANCE);
addFormComponentProperties(nestedProperties, element, flattenedSolution, cachedTabSeq, selected, listFormComponentElements, design, recursionCheck);
}
}
}
recursionCheck.remove(frm.getName());
}
}
}
use of com.servoy.j2db.persistence.IFormElement in project servoy-client by Servoy.
the class ComponentFactory method createComponent.
@SuppressWarnings("nls")
public static WebFormComponent createComponent(IApplication application, IDataAdapterList dataAdapterList, FormElement fe, Container parentToAddTo, Form form) {
// TODO anything to do here for custom special types?
WebFormComponent webComponent = new WebFormComponent(fe.getName(), fe, dataAdapterList);
if (parentToAddTo != null)
parentToAddTo.add(webComponent);
String name = fe.getName();
IPersist persist = fe.getPersistIfAvailable();
int elementSecurity = 0;
if (persist != null) {
boolean getItDirectlyBasedOnPersistAndForm = true;
// FormComponent's child security is the security of the FormComponent
if (fe.isFormComponentChild()) {
String feName = fe.getName();
// form component children security access is currently dictated by the root form component component security settings; currently one only has the Security tab in form editors not in form component editors;
// for example if you have a form that contains a form component component A pointing to form component X that has in it a form component component B that points to form component Y
// then the children of both X and Y in this case have the same security settings as 'root' form component component which is A;
// so find the 'root' form component component persist and get it's access rights; this should always be found!
String formComponentName = feName.substring(0, feName.indexOf('$'));
for (IPersist p : form.getFlattenedFormElementsAndLayoutContainers()) {
if (p instanceof IFormElement && formComponentName.equals(((IFormElement) p).getName())) {
elementSecurity = application.getFlattenedSolution().getSecurityAccess(p.getUUID(), form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
getItDirectlyBasedOnPersistAndForm = false;
break;
}
}
if (getItDirectlyBasedOnPersistAndForm)
Debug.warn("'Root' form component including component on form " + form.getName() + " was not found when trying to determine access rights for a child of a form component: " + name);
} else if (persist.getParent() instanceof Portal) {
elementSecurity = application.getFlattenedSolution().getSecurityAccess(((Portal) persist.getParent()).getUUID(), form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
getItDirectlyBasedOnPersistAndForm = false;
}
if (getItDirectlyBasedOnPersistAndForm) {
elementSecurity = application.getFlattenedSolution().getSecurityAccess(persist.getUUID(), form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
}
if (!((elementSecurity & IRepository.VIEWABLE) != 0)) {
webComponent.setVisible(false);
}
}
WebObjectSpecification componentSpec = fe.getWebComponentSpec(false);
// first convert formElement-to-Sablo and store them in the webComponent
for (String propName : fe.getRawPropertyValues().keySet()) {
// TODO this if should not be necessary. currently in the case of "printable" hidden property
if (componentSpec.getProperty(propName) == null)
continue;
Object value = fe.getPropertyValueConvertedForWebComponent(propName, webComponent, (DataAdapterList) dataAdapterList);
fillProperty(value, fe.getPropertyValue(propName), componentSpec.getProperty(propName), webComponent);
}
// then after all of them are converted above attach them to the webComponent (so that when attach is called on any ISmartPropertyValue at least all the other properties are converted
// this could help initialize smart properties that depend on each other faster then if we would convert and then attach right away each value)
webComponent.propertiesInitialized();
// overwrite accessible
if (persist != null) {
if (// element not accessible
!((elementSecurity & IRepository.ACCESSIBLE) != 0)) {
webComponent.setProperty(WebFormUI.ENABLED, false);
Object enableValue = webComponent.getRawPropertyValue(WebFormUI.ENABLED);
if (enableValue instanceof NGEnabledSabloValue) {
((NGEnabledSabloValue) enableValue).setAccessible(false);
}
} else {
int formSecurity = application.getFlattenedSolution().getSecurityAccess(form.getUUID(), form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
if (// form not accessible
!((formSecurity & IRepository.ACCESSIBLE) != 0)) {
webComponent.setProperty(WebFormUI.ENABLED, false);
Object enableValue = webComponent.getRawPropertyValue(WebFormUI.ENABLED);
if (enableValue instanceof NGEnabledSabloValue) {
((NGEnabledSabloValue) enableValue).setAccessible(false);
}
}
}
}
boolean[] foundOnDataChangeInDPConfigFromSpec = new boolean[] { false };
componentSpec.getProperties(DataproviderPropertyType.INSTANCE, true).forEach((propertyFromSpec) -> {
// the property type found here is for a 'dataprovider' property from the spec file of this component
Object configOfDPOrFoundsetLinkedDP = propertyFromSpec.getConfig();
DataproviderConfig dpConfig;
if (configOfDPOrFoundsetLinkedDP instanceof FoundsetLinkedConfig)
dpConfig = (DataproviderConfig) ((FoundsetLinkedConfig) configOfDPOrFoundsetLinkedDP).getWrappedConfig();
else
dpConfig = (DataproviderConfig) configOfDPOrFoundsetLinkedDP;
if (dpConfig.getOnDataChange() != null && form.getOnElementDataChangeMethodID() > 0) {
foundOnDataChangeInDPConfigFromSpec[0] = true;
webComponent.add(dpConfig.getOnDataChange(), form.getOnElementDataChangeMethodID());
}
});
// TODO should this be a part of type conversions for handlers instead?
for (String eventName : componentSpec.getHandlers().keySet()) {
Object eventValue = fe.getPropertyValue(eventName);
if (eventValue instanceof String) {
IPersist function = application.getFlattenedSolution().getScriptMethod((String) eventValue);
if (function == null) {
function = application.getFlattenedSolution().searchPersist((String) eventValue);
if (function == null) {
Debug.warn("Script Method of value '" + eventValue + "' for handler " + eventName + " not found trying just the form " + form);
IPersist child = form.getChild(UUID.fromString((String) eventValue));
if (child != null) {
Debug.warn("Script Method " + child + " on the form " + form + " with uuid " + child.getUUID());
function = child;
} else {
Debug.warn("Still not found on Form " + form + " Script Method of value '" + eventValue + "' for handler " + eventName);
}
}
}
if (function != null) {
webComponent.add(eventName, function.getID());
} else {
Debug.warn("Event handler for " + eventName + " with value '" + eventValue + "' not found (form " + form + ", form element " + name + ")");
}
} else if (eventValue instanceof Number && ((Number) eventValue).intValue() > 0) {
webComponent.add(eventName, ((Number) eventValue).intValue());
} else if (Utils.equalObjects(eventName, StaticContentSpecLoader.PROPERTY_ONFOCUSGAINEDMETHODID.getPropertyName()) && (form.getOnElementFocusGainedMethodID() > 0)) {
webComponent.add(eventName, form.getOnElementFocusGainedMethodID());
} else if (Utils.equalObjects(eventName, StaticContentSpecLoader.PROPERTY_ONFOCUSLOSTMETHODID.getPropertyName()) && (form.getOnElementFocusLostMethodID() > 0)) {
webComponent.add(eventName, form.getOnElementFocusLostMethodID());
} else if (!foundOnDataChangeInDPConfigFromSpec[0] && Utils.equalObjects(eventName, StaticContentSpecLoader.PROPERTY_ONDATACHANGEMETHODID.getPropertyName()) && (form.getOnElementDataChangeMethodID() > 0)) {
// legacy behavior - based on hard-coded handler name (of component)
webComponent.add(eventName, form.getOnElementDataChangeMethodID());
}
}
// just created, it should have no changes.
webComponent.clearChanges();
return webComponent;
}
use of com.servoy.j2db.persistence.IFormElement in project servoy-client by Servoy.
the class FormElement method getLabel.
public IFormElement getLabel() {
IFormElement label = null;
String name = (String) getPropertyValue(StaticContentSpecLoader.PROPERTY_NAME.getPropertyName());
if (name != null && form != null) {
Iterator<IPersist> formElementsIte = form.getAllObjects();
IPersist p;
while (formElementsIte.hasNext()) {
p = formElementsIte.next();
if (p instanceof GraphicalComponent && name.equals(((GraphicalComponent) p).getLabelFor())) {
label = (GraphicalComponent) p;
break;
}
}
}
return label;
}
Aggregations