use of com.servoy.j2db.server.ngclient.property.DataproviderConfig 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;
}
Aggregations