use of com.servoy.j2db.server.ngclient.property.FoundsetLinkedConfig in project servoy-client by Servoy.
the class TitleStringPropertyType method toSabloComponentDefaultValue.
/*
* (non-Javadoc)
*
* @see com.servoy.j2db.server.ngclient.property.types.NGConversions.IFormElementDefaultValueToSabloComponent#toSabloComponentDefaultValue(org.sablo.
* specification.PropertyDescription, com.servoy.j2db.server.ngclient.INGFormElement, com.servoy.j2db.server.ngclient.WebFormComponent,
* com.servoy.j2db.server.ngclient.DataAdapterList)
*/
@Override
public BasicTagStringTypeSabloValue toSabloComponentDefaultValue(PropertyDescription pd, INGFormElement formElement, WebFormComponent component, DataAdapterList dataAdapterList) {
TitleStringConfig titleStringConfig = (TitleStringConfig) pd.getConfig();
String forDataprovider = titleStringConfig.getForDataprovider();
if (forDataprovider != null) {
PropertyDescription forProperty = formElement.getPropertyDescription(forDataprovider);
if (forProperty != null) {
IPropertyType<?> type = forProperty.getType();
if (type instanceof FoundsetLinkedPropertyType) {
Object config = forProperty.getConfig();
if (config instanceof FoundsetLinkedConfig && ((FoundsetLinkedConfig) config).getForFoundsetName() != null) {
String forFoundset = ((FoundsetLinkedConfig) config).getForFoundsetName();
String dataproviderID = (String) formElement.getPropertyValue(forDataprovider);
JSONObject foundsetValue = (JSONObject) formElement.getPropertyValue(forFoundset);
if (foundsetValue != null) {
String foundsetID = foundsetValue.optString(FoundsetPropertyType.FOUNDSET_SELECTOR);
INGApplication application = ((WebFormComponent) component.getUnderlyingWebObject()).getDataConverterContext().getApplication();
Form form = ((IContextProvider) component.getUnderlyingWebObject()).getDataConverterContext().getForm().getForm();
ITable table = FoundsetTypeSabloValue.getTableBasedOfFoundsetPropertyFromFoundsetIdentifier(foundsetID, application, form);
if (table != null) {
Column dataproviderColumn = table.getColumn(dataproviderID);
if (dataproviderColumn != null) {
return toSabloComponentValue(dataproviderColumn.getTitle(), pd, formElement, component, dataAdapterList);
}
}
}
}
}
}
}
return null;
}
use of com.servoy.j2db.server.ngclient.property.FoundsetLinkedConfig in project servoy-client by Servoy.
the class ValueListPropertyType method getDependenciesToOtherProperties.
protected ValuelistPropertyDependencies getDependenciesToOtherProperties(PropertyDescription pd, IPropertyDescriptionProvider propertyDescriptionProvider) {
ValueListConfig config = (ValueListConfig) pd.getConfig();
String dataproviderPropertyName = config.getFor();
String foundsetPropertyName = null;
// this is really only used I think when you have a custom valuelist with date values (without separate display values) - to convert the String defined dates in the custom valuelist into actual Date values
String formatPropertyName = null;
boolean dataproviderResolveValuelist = false;
if (dataproviderPropertyName != null) {
PropertyDescription dpPropertyDef = propertyDescriptionProvider.getPropertyDescription(dataproviderPropertyName);
Object dpConfig = null;
if (dpPropertyDef != null) {
dpConfig = dpPropertyDef.getConfig();
}
if (dpPropertyDef != null && (dpPropertyDef.getType() instanceof FoundsetLinkedPropertyType)) {
foundsetPropertyName = ((FoundsetLinkedConfig) dpPropertyDef.getConfig()).getForFoundsetName();
dpConfig = ((FoundsetLinkedConfig) dpPropertyDef.getConfig()).getWrappedPropertyDescription().getConfig();
}
if (dpConfig instanceof DataproviderConfig && ((DataproviderConfig) dpConfig).shouldResolveValuelist()) {
dataproviderResolveValuelist = true;
}
}
Collection<PropertyDescription> properties = propertyDescriptionProvider.getProperties(FormatPropertyType.INSTANCE);
for (PropertyDescription formatPd : properties) {
// compare whether format and valueList property are for same property (dataprovider) or if format is used for valuelist property itself
if (formatPd.getConfig() instanceof String[] && ((String[]) formatPd.getConfig()).length > 0) {
for (String formatForClauseEntry : ((String[]) formatPd.getConfig())) {
if (dataproviderPropertyName.equals(formatForClauseEntry) || pd.getName().equals(formatForClauseEntry)) {
formatPropertyName = formatPd.getName();
break;
}
}
// there can/should be only one format property for a specific valuelist; we found it
if (formatPropertyName != null)
break;
}
}
return new ValuelistPropertyDependencies(dataproviderPropertyName, foundsetPropertyName, formatPropertyName, dataproviderResolveValuelist);
}
use of com.servoy.j2db.server.ngclient.property.FoundsetLinkedConfig in project servoy-client by Servoy.
the class FormatPropertyType method getPropertyDependencies.
private FormatPropertyDependencies getPropertyDependencies(PropertyDescription pd, IPropertyDescriptionProvider pdProvider) {
String forDataproviderPropertyName = null;
String forFoundsetPropertyName = null;
String forValuelistPropertyName = null;
if (pd.getConfig() instanceof String[]) {
for (String dependency : (String[]) pd.getConfig()) {
// IMPORTANT: here we iterate over the for: configs to identify any dataprovider or valuelist properties that this format is meant for
//
// if you have for: [valuelist, dataprovider] then 2 things can happen:
// - valuelist if it has both real and display values - forces the type; it is either TEXT (custom vl., global method vl.) or the 'display' column type in case it's a DB valuelist
// - valuelist if not real/display but only one kind of values: here it is required in docs in the spec file that the valuelist property also defines "for": dataprovider if format
// defines both "for" valuelist and "for" dataprovider => valuelist doesn't force the type and then the dataprovider will decide the type
//
// if you have just for: dataprovider the the dataprovider property determines the type
// if you have just for: valuelist (TODO) - this is currently not properly supported - as here we should get the type always from the VL (for both display and real values) - as we don't have a dataprovider to fall back on
PropertyDescription forProperty = pdProvider.getPropertyDescription(dependency);
if (forProperty != null) {
IPropertyType<?> type = forProperty.getType();
if (type instanceof IYieldingType<?, ?>) {
type = ((IYieldingType) type).getPossibleYieldType();
}
if (type instanceof DataproviderPropertyType) {
if (forDataproviderPropertyName == null) {
forDataproviderPropertyName = dependency;
// see if it's foundset linked
Object config = forProperty.getConfig();
if (config instanceof FoundsetLinkedConfig && ((FoundsetLinkedConfig) config).getForFoundsetName() != null) {
forFoundsetPropertyName = ((FoundsetLinkedConfig) config).getForFoundsetName();
}
} else
Debug.warn("Format property '" + pd + " declares in .spec file to be for more then one dataprovider property; this is incorrect. (" + forDataproviderPropertyName + "," + dependency + ")");
} else if (type instanceof ValueListPropertyType) {
if (forValuelistPropertyName == null)
forValuelistPropertyName = dependency;
else
Debug.warn("Format property '" + pd + " declares in .spec file to be for more then one valuelist property; this is incorrect. (" + forDataproviderPropertyName + "," + dependency + ")");
}
}
}
}
return new FormatPropertyDependencies(forDataproviderPropertyName, forFoundsetPropertyName, forValuelistPropertyName);
}
use of com.servoy.j2db.server.ngclient.property.FoundsetLinkedConfig in project servoy-client by Servoy.
the class FormatTypeSabloValue method getSabloValue.
protected ComponentFormat getSabloValue(String formatValue, String dataproviderId, Object valuelistId, String foundsetId, IWebObjectContext webObjectCntxt) {
INGApplication application = ((WebFormComponent) webObjectCntxt.getUnderlyingWebObject()).getDataConverterContext().getApplication();
IDataProviderLookup dataProviderLookup = null;
// IMPORTANT: here we use the for: configs in .spec file
//
// if you have for: [valuelist, dataprovider] then 2 things can happen:
// - valuelist if it has both real and display values - forces the type; it is either TEXT (custom vl., global method vl.) or the 'display' column type in case it's a DB valuelist
// - valuelist if not real/display but only one kind of values: here it is required in docs in the spec file that the valuelist property also defines "for": dataprovider if format
// defines both "for" valuelist and dataprovider => valuelist doesn't force the type and then the dataprovider will decide the type
//
// if you have just for: dataprovider the the dataprovider property determines the type
// if you have just for: valuelist (TODO) - this is currently not properly supported - as here we should get the type always from the VL (for both display and real values) - as we don't have a dataprovider to fall back on
isValuelistFormatSet = false;
if (valuelistId != null) {
// if we have a "for" valuelist, see if this valuelist forces the format type due to display values (when they are separate from real values)
// otherwise it will do nothing and loop/fallback to the other if clause below which checks the "for" dataprovider
ValueList valuelistPersist = ValueListTypeSabloValue.getValuelistPersist(valuelistId, application);
if (valuelistPersist != null) {
IDataProvider dataProvider = null;
ITable table;
try {
if (valuelistPersist.getRelationName() != null) {
Relation[] relations = application.getFlattenedSolution().getRelationSequence(valuelistPersist.getRelationName());
table = application.getFlattenedSolution().getTable(relations[relations.length - 1].getForeignDataSource());
} else {
table = application.getFlattenedSolution().getTable(valuelistPersist.getDataSource());
}
if (table != null) {
// if the format is for a table valuelist - the type to be used is the one of the dp chosen as 'display' in the valuelist
String dp = null;
// if show == real then we can use show anyway cause there is only one value for both real and display; if show != real we care about show
int showDataProviders = valuelistPersist.getShowDataProviders();
if ((showDataProviders & 1) != 0) {
dp = valuelistPersist.getDataProviderID1();
}
if ((showDataProviders & 2) != 0) {
// display value is a concat of multiple columns, so a string; not even sure if format property makes sense, but it is for a String then
if (dp != null)
return ComponentFormat.getComponentFormat(formatValue, IColumnTypes.TEXT, application);
dp = valuelistPersist.getDataProviderID2();
}
if ((showDataProviders & 4) != 0) {
// display value is a concat of multiple columns, so a string; not even sure if format property makes sense, but it is for a String then
if (dp != null)
return ComponentFormat.getComponentFormat(formatValue, IColumnTypes.TEXT, application);
dp = valuelistPersist.getDataProviderID3();
}
if (dp != null) {
dataProvider = application.getFlattenedSolution().getDataProviderForTable(table, dp);
}
isValuelistFormatSet = true;
return ComponentFormat.getComponentFormat(formatValue, dataProvider, application, true);
} else if (valuelistPersist.getValueListType() == IValueListConstants.CUSTOM_VALUES) {
IValueList realValuelist = null;
ValueListTypeSabloValue valuelistSabloValue = (ValueListTypeSabloValue) FoundsetLinkedTypeSabloValue.unwrapIfNeeded(webObjectContext.getProperty(propertyDependencies.valueListPropertyName));
if (valuelistSabloValue != null) {
// take it from property, may not be the shared instance in case setvaluelistitems on component was used
realValuelist = valuelistSabloValue.getValueList();
}
if (realValuelist == null) {
realValuelist = com.servoy.j2db.component.ComponentFactory.getRealValueList(application, valuelistPersist, true, Types.OTHER, ComponentFormat.getComponentFormat(formatValue, dataproviderId, null, application, true).parsedFormat, null, true);
}
if (realValuelist.hasRealValues()) {
// if custom vl has both real and display values, the display values are TEXT (format is for those)
// of if it has displayValueType set, use that
isValuelistFormatSet = true;
int realValueDisplayType = realValuelist.getValueList().getDisplayValueType();
return ComponentFormat.getComponentFormat(formatValue, realValueDisplayType != 0 ? realValueDisplayType : IColumnTypes.TEXT, application);
}
} else if (valuelistPersist.getValueListType() == IValueListConstants.GLOBAL_METHOD_VALUES) {
PropertyDescription vlPD = webObjectCntxt.getPropertyDescription(propertyDependencies.valueListPropertyName);
Object vlPDConfig = null;
if (vlPD != null) {
vlPDConfig = vlPD.getConfig();
if (vlPDConfig instanceof FoundsetLinkedConfig)
vlPDConfig = ((FoundsetLinkedConfig) vlPDConfig).getWrappedConfig();
}
boolean lazyLoad = valuelistPersist.getLazyLoading() && vlPDConfig instanceof ValueListConfig && ((ValueListConfig) vlPDConfig).getLazyLoading();
if (!lazyLoad) {
IValueList realValuelist = com.servoy.j2db.component.ComponentFactory.getRealValueList(application, valuelistPersist, true, Types.OTHER, null, null, true);
if (realValuelist instanceof GlobalMethodValueList) {
((GlobalMethodValueList) realValuelist).fill(null, "", null);
if (realValuelist.hasRealValues() || realValuelist.getSize() == 0 || (realValuelist.getSize() == 1 && valuelistPersist.getAddEmptyValue() == IValueListConstants.EMPTY_VALUE_ALWAYS)) {
// if global method vl has both real and display values, the display values are TEXT (format is for those)
// of if it has displayValueType set, use that
isValuelistFormatSet = true;
int realValueDisplayType = realValuelist.getValueList().getDisplayValueType();
return ComponentFormat.getComponentFormat(formatValue, realValueDisplayType != 0 ? realValueDisplayType : IColumnTypes.TEXT, application);
}
}
}
}
} catch (Exception ex) {
Debug.error(ex);
}
}
// here - we want to fall back to the dataprovider if available in for: [ ..., dataprovider] if valuelist didn't force a certain display type on the format
}
if (dataproviderId != null && foundsetId != null) {
ITable table = null;
Form form = ((IContextProvider) webObjectCntxt.getUnderlyingWebObject()).getDataConverterContext().getForm().getForm();
// always assume now that the the properties has the foundset property name.
FoundsetTypeSabloValue runtimeValOfFoundset = (FoundsetTypeSabloValue) webObjectCntxt.getUnderlyingWebObject().getProperty(this.propertyDependencies.foundsetPropertyName);
if (runtimeValOfFoundset != null && runtimeValOfFoundset.getFoundset() != null && runtimeValOfFoundset.getFoundset().getDataSource().equals(foundsetId)) {
table = runtimeValOfFoundset.getFoundset().getTable();
}
if (table == null)
table = FoundsetTypeSabloValue.getTableBasedOfFoundsetPropertyFromFoundsetIdentifier(foundsetId, application, form);
if (table != null) {
dataProviderLookup = new FormAndTableDataProviderLookup(application.getFlattenedSolution(), form, table);
}
// else it will be searched for in form's context and table as below
}
if (dataProviderLookup == null) {
WebObjectSpecification spec = ((WebFormComponent) webObjectCntxt.getUnderlyingWebObject()).getParent().getSpecification();
if (spec != null) {
Collection<PropertyDescription> formComponentProperties = spec.getProperties(FormComponentPropertyType.INSTANCE);
if (formComponentProperties != null) {
for (PropertyDescription property : formComponentProperties) {
if (property.getConfig() instanceof ComponentTypeConfig && ((ComponentTypeConfig) property.getConfig()).forFoundset != null) {
FoundsetTypeSabloValue runtimeValOfFoundset = (FoundsetTypeSabloValue) ((WebFormComponent) webObjectCntxt.getUnderlyingWebObject()).getParent().getProperty(((ComponentTypeConfig) property.getConfig()).forFoundset);
ITable table = null;
Form form = ((IContextProvider) webObjectCntxt.getUnderlyingWebObject()).getDataConverterContext().getForm().getForm();
if (runtimeValOfFoundset.getFoundset() != null)
table = runtimeValOfFoundset.getFoundset().getTable();
if (table == null)
table = FoundsetTypeSabloValue.getTableBasedOfFoundsetPropertyFromFoundsetIdentifier(runtimeValOfFoundset.getFoundsetSelector(), application, form);
if (table != null) {
dataProviderLookup = new FormAndTableDataProviderLookup(application.getFlattenedSolution(), form, table);
}
break;
}
}
}
}
}
if (dataProviderLookup == null && application != null)
dataProviderLookup = application.getFlattenedSolution().getDataproviderLookup(application.getFoundSetManager(), ((IContextProvider) webObjectCntxt.getUnderlyingWebObject()).getDataConverterContext().getForm().getForm());
ComponentFormat format = ComponentFormat.getComponentFormat(formatValue, dataproviderId, dataProviderLookup, application, true);
return format;
}
use of com.servoy.j2db.server.ngclient.property.FoundsetLinkedConfig 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