use of com.servoy.j2db.persistence.IFormElement in project servoy-client by Servoy.
the class FormWrapper method getBaseComponents.
public Collection<IFormElement> getBaseComponents() {
if (this.baseComponents != null)
return this.baseComponents;
List<IFormElement> components = new ArrayList<>();
Collection<BaseComponent> excludedComponents = null;
if ((isListView && !design) || isTableView) {
excludedComponents = getBodyComponents();
}
List<IFormElement> persists = form.getFlattenedObjects(Form.FORM_INDEX_COMPARATOR);
for (IFormElement persist : persists) {
if (isSecurityVisible(persist)) {
if ((excludedComponents == null || !excludedComponents.contains(persist)))
components.add(persist);
checkFormComponents(components, FormElementHelper.INSTANCE.getFormElement(persist, context.getSolution(), null, design), new HashSet<String>());
}
}
if ((isListView && !design) || isTableView) {
components.add(new BodyPortal(form));
}
if (form.getNavigatorID() == Form.NAVIGATOR_DEFAULT) {
components.add(DefaultNavigator.INSTANCE);
}
this.baseComponents = components;
return components;
}
use of com.servoy.j2db.persistence.IFormElement in project servoy-client by Servoy.
the class WebListFormUI method getFormElements.
@Override
public List<FormElement> getFormElements() {
if (cachedElements.size() == 0) {
Form form = getController().getForm();
List<IFormElement> elements = form.getFlattenedObjects(PositionComparator.XY_PERSIST_COMPARATOR);
Iterator<IFormElement> it = elements.iterator();
Part body = FormElementHelper.INSTANCE.getBodyPart(form);
int bodyStartY = form.getPartStartYPos(body.getID());
int bodyEndY = body.getHeight();
// only the elements from other form parts then body still need to be added to cached elements
while (it.hasNext()) {
IFormElement element = it.next();
if (bodyStartY <= element.getLocation().y && bodyEndY > element.getLocation().y) {
it.remove();
}
}
elements.add(getPortal());
cachedElements = FormElementHelper.INSTANCE.getFormElements(new ArrayList<IPersist>(elements).iterator(), getDataConverterContext());
}
return cachedElements;
}
use of com.servoy.j2db.persistence.IFormElement in project servoy-client by Servoy.
the class PersistBasedFormElementImpl method convertFromPortalToNGProperties.
private void convertFromPortalToNGProperties(Portal portal, FlattenedSolution fs, Map<String, Object> map, Map<String, PropertyDescription> specProperties, PropertyPath propertyPath) {
try {
map.remove("relationName");
JSONObject relatedFoundset = new JSONObject();
relatedFoundset.put("foundsetSelector", portal.getRelationName());
// get property type 'foundset'
PropertyDescription pd = specProperties.get("relatedFoundset");
if (pd == null) {
Debug.error(new RuntimeException("Cannot find foundset special type to use for portal."));
return;
} else {
putAndConvertProperty("relatedFoundset", relatedFoundset, map, fs, pd, propertyPath);
}
map.remove("ngReadOnlyMode");
if (portal.getNgReadOnlyMode() != null) {
PropertyDescription readOnlyModePD = specProperties.get("readOnlyMode");
if (pd == null) {
Debug.error(new RuntimeException("Cannot find foundset special type to use for portal."));
return;
} else {
putAndConvertProperty("readOnlyMode", portal.getNgReadOnlyMode(), map, fs, readOnlyModePD, propertyPath);
}
}
// components: 'component[]',
// component: {
// definition: 'componentDef',
// (...)
// },
// get property type 'component definition'
pd = specProperties.get("childElements");
if (pd != null)
pd = ((CustomJSONArrayType<?, ?>) pd.getType()).getCustomJSONTypeDefinition();
List<IPersist> components = ComponentFactory.sortElementsOnPositionAndGroup(portal.getAllObjectsAsList());
if (pd == null) {
Debug.error(new RuntimeException("Cannot find component definition special type to use for portal."));
return;
} else {
// of ComponentTypeFormElementValue type (this array of objects corresponds to CustomJSONArrayType form element value
Object[] componentFormElementValues = new Object[components.size()];
int i = 0;
ComponentPropertyType type = ((ComponentPropertyType) pd.getType());
propertyPath.add("childElements");
for (IPersist component : components) {
if (component instanceof IFormElement) {
FormElement nfe = FormElementHelper.INSTANCE.getFormElement((IFormElement) component, fs, propertyPath, formElement.getDesignId() != null);
boolean somePropertyChanged = false;
propertyPath.add(i);
// remove the name of relation prefix from child dataproviders as it only stands in the way later on...
Collection<PropertyDescription> dataProviderProperties = nfe.getWebComponentSpec().getProperties(DataproviderPropertyType.INSTANCE);
String relationPrefix = portal.getRelationName() + '.';
Map<String, Object> elementProperties = new HashMap<>(nfe.getRawPropertyValues());
for (PropertyDescription dpProperty : dataProviderProperties) {
String dpPropertyName = dpProperty.getName();
// TODO adjust this when/if dataprovider properties change the form element value type in the future
String dp = (String) nfe.getPropertyValue(dpPropertyName);
if (dp != null && dp.startsWith(relationPrefix)) {
somePropertyChanged = true;
// portal always prefixes comp. dataproviders with related fs name
putAndConvertProperty(dpPropertyName, dp.substring(relationPrefix.length()), elementProperties, fs, nfe.getWebComponentSpec().getProperty(dpPropertyName), propertyPath);
}
}
// legacy portals need to set the same tabSeq. property for all children if they are to function properly
Collection<PropertyDescription> tabSequenceProperties = nfe.getWebComponentSpec().getProperties(NGTabSeqPropertyType.NG_INSTANCE);
for (PropertyDescription tabSeqProperty : tabSequenceProperties) {
String tabSeqPropertyName = tabSeqProperty.getName();
somePropertyChanged = true;
putAndConvertProperty(tabSeqPropertyName, Integer.valueOf(1), elementProperties, fs, nfe.getWebComponentSpec().getProperty(tabSeqPropertyName), // just put an 1 on all (default legacy portal doesn't allow non-default tab seq in it)
propertyPath);
}
if (somePropertyChanged)
nfe.updatePropertyValuesDontUse(elementProperties);
componentFormElementValues[i++] = type.getFormElementValue(null, pd, propertyPath, nfe, fs);
propertyPath.backOneLevel();
}
}
propertyPath.backOneLevel();
map.put("childElements", componentFormElementValues);
}
} catch (IllegalArgumentException e) {
Debug.error(e);
return;
} catch (JSONException e) {
Debug.error(e);
return;
}
}
use of com.servoy.j2db.persistence.IFormElement in project servoy-client by Servoy.
the class FormElementHelper method getControlledTabSeqReplacementFor.
/**
* Generates a Servoy controlled tab-sequence-index. We try to avoid sending default (0 or null) tabSeq even
* for forms that do use default tab sequence in order to avoid problems with nesting default and non-default tabSeq forms.
*
* @param designValue the value the persist holds for the tabSeq.
* @param form the form containing the persist
* @param persistIfAvailable the persist. For now, 'component' type properties might work with non-persist-linked FormElements so it could be null.
* When those become persist based as well this will never be null.
* @return the requested controlled tabSeq (should make tabSeq be identical to the one shown in developer).
*/
public Integer getControlledTabSeqReplacementFor(Integer designValue, PropertyDescription pd, Form flattenedForm, IPersist persistIfAvailable, // TODO more args will be needed here such as the tabSeq property name or description
FlattenedSolution flattenedSolution, // TODO more args will be needed here such as the tabSeq property name or description
boolean design) {
// TODO this can be removed when we know we'll always have a persist here; currently don't handle this in any way as it's not supported
if (persistIfAvailable == null || (nestedCall.get() != null && nestedCall.get().booleanValue()))
return designValue;
nestedCall.set(Boolean.TRUE);
final boolean responsiveForm = flattenedForm.isResponsiveLayout();
try {
if (flattenedForm.isFormComponent() && persistIfAvailable instanceof AbstractBase) {
String mainFormName = ((AbstractBase) persistIfAvailable).getRuntimeProperty(FORM_COMPONENT_FORM_NAME);
if (mainFormName != null) {
flattenedForm = flattenedSolution.getFlattenedForm(flattenedSolution.getForm(mainFormName));
// just return the skip value if this is somehow invalid.
if (flattenedForm == null)
return Integer.valueOf(-2);
}
}
boolean formWasModifiedViaSolutionModel = flattenedSolution.hasCopy(flattenedForm);
Map<TabSeqProperty, Integer> cachedTabSeq = null;
if (formWasModifiedViaSolutionModel) {
Pair<Long, Map<TabSeqProperty, Integer>> pair = flattenedForm.getRuntimeProperty(FORM_TAB_SEQUENCE);
if (pair != null && flattenedForm.getLastModified() == pair.getLeft().longValue()) {
cachedTabSeq = pair.getRight();
}
} else
cachedTabSeq = formTabSequences.get(flattenedForm.getUUID());
if (cachedTabSeq == null) {
cachedTabSeq = new HashMap<TabSeqProperty, Integer>();
SortedList<TabSeqProperty> selected = new SortedList<TabSeqProperty>(new Comparator<TabSeqProperty>() {
public int compare(TabSeqProperty o1, TabSeqProperty o2) {
int seq1 = o1.getSeqValue();
int seq2 = o2.getSeqValue();
if (seq1 == ISupportTabSeq.DEFAULT && seq2 == ISupportTabSeq.DEFAULT) {
if (responsiveForm) {
if (o1.element.getParent() == o2.element.getParent()) {
int positionComparator = PositionComparator.comparePoint(false, o1.getLocation(), o2.getLocation());
if (positionComparator != 0) {
return positionComparator;
}
} else {
List<ISupportChilds> ancestors = new ArrayList<ISupportChilds>();
IPersist persist = o1.element;
while (persist.getParent() instanceof AbstractContainer) {
ancestors.add(persist.getParent());
persist = persist.getParent();
}
persist = o2.element;
while (persist.getParent() instanceof AbstractContainer) {
if (ancestors.contains(persist.getParent())) {
// we found the common ancestor
int index = ancestors.indexOf(persist.getParent());
IPersist comparablePersist = index == 0 ? o1.element : ancestors.get(index - 1);
int positionComparator = PositionComparator.comparePoint(false, ((ISupportBounds) comparablePersist).getLocation(), ((ISupportBounds) persist).getLocation());
if (positionComparator != 0) {
return positionComparator;
}
}
persist = persist.getParent();
}
}
} else {
int positionComparator = PositionComparator.comparePoint(false, o1.getLocation(), o2.getLocation());
if (positionComparator != 0) {
return positionComparator;
}
}
}
return compareTabSeq(seq1, o1.element, seq2, o2.element, flattenedSolution);
}
});
Map<TabSeqProperty, List<TabSeqProperty>> listFormComponentMap = new HashMap<TabSeqProperty, List<TabSeqProperty>>();
List<TabSeqProperty> listFormComponentElements = null;
TabSeqProperty listFormComponentTabSeq = null;
Iterator<IFormElement> iterator = flattenedForm.getFlattenedObjects(null).iterator();
while (iterator.hasNext()) {
IFormElement formElement = iterator.next();
if (FormTemplateGenerator.isWebcomponentBean(formElement)) {
String componentType = FormTemplateGenerator.getComponentTypeName(formElement);
WebObjectSpecification specification = WebComponentSpecProvider.getSpecProviderState().getWebComponentSpecification(componentType);
if (specification != null) {
Collection<PropertyDescription> properties = specification.getProperties(NGTabSeqPropertyType.NG_INSTANCE);
Collection<PropertyDescription> formComponentProperties = specification.getProperties(FormComponentPropertyType.INSTANCE);
boolean isListFormComponent = isListFormComponent(formComponentProperties);
if (properties != null && properties.size() > 0) {
IBasicWebComponent webComponent = (IBasicWebComponent) formElement;
for (PropertyDescription tabSeqProperty : properties) {
int tabseq = Utils.getAsInteger(webComponent.getProperty(tabSeqProperty.getName()));
TabSeqProperty seqProperty = new TabSeqProperty(formElement, tabSeqProperty.getName());
if (listFormComponentTabSeq == null && isListFormComponent) {
listFormComponentTabSeq = seqProperty;
listFormComponentElements = new ArrayList<TabSeqProperty>();
listFormComponentMap.put(listFormComponentTabSeq, listFormComponentElements);
}
if (tabseq >= 0) {
selected.add(seqProperty);
} else {
cachedTabSeq.put(seqProperty, Integer.valueOf(-2));
}
}
}
addFormComponentProperties(formComponentProperties, formElement, flattenedSolution, cachedTabSeq, selected, listFormComponentElements, design, new HashSet<String>());
}
} else if (formElement instanceof ISupportTabSeq) {
if (((ISupportTabSeq) formElement).getTabSeq() >= 0) {
selected.add(new TabSeqProperty(formElement, StaticContentSpecLoader.PROPERTY_TABSEQ.getPropertyName()));
} else {
cachedTabSeq.put(new TabSeqProperty(formElement, StaticContentSpecLoader.PROPERTY_TABSEQ.getPropertyName()), Integer.valueOf(-2));
}
}
}
int i = 1;
for (TabSeqProperty tabSeq : selected) {
cachedTabSeq.put(tabSeq, Integer.valueOf(i++));
}
for (TabSeqProperty tabSeq : listFormComponentMap.keySet()) {
List<TabSeqProperty> elements = listFormComponentMap.get(tabSeq);
if (elements != null) {
Integer value = cachedTabSeq.get(tabSeq);
// all elements inside list form component have same tabindex as the list itself
for (TabSeqProperty tabSeqElement : elements) {
cachedTabSeq.put(tabSeqElement, value);
}
}
}
if (!formWasModifiedViaSolutionModel) {
formTabSequences.putIfAbsent(flattenedForm.getUUID(), cachedTabSeq);
} else {
flattenedForm.setRuntimeProperty(FORM_TAB_SEQUENCE, new Pair<>(Long.valueOf(flattenedForm.getLastModified()), cachedTabSeq));
}
}
IPersist realPersist = flattenedForm.findChild(persistIfAvailable.getUUID());
if (realPersist == null) {
realPersist = persistIfAvailable;
}
Integer controlledTabSeq = cachedTabSeq.get(new TabSeqProperty(realPersist, pd.getName()));
// if not in tabSeq, use "skip" value
if (controlledTabSeq == null)
controlledTabSeq = Integer.valueOf(-2);
return controlledTabSeq;
} finally {
nestedCall.set(Boolean.FALSE);
}
}
use of com.servoy.j2db.persistence.IFormElement in project servoy-client by Servoy.
the class FormElementHelper method generateFormComponentPersists.
private static List<IFormElement> generateFormComponentPersists(INGFormElement parent, PropertyDescription pd, JSONObject json, Form frm, FlattenedSolution fs) {
List<IFormElement> elements = new ArrayList<>();
List<IFormElement> formelements = fs.getFlattenedForm(frm).getFlattenedObjects(PositionComparator.XY_PERSIST_COMPARATOR);
for (IFormElement element : formelements) {
element = (IFormElement) ((AbstractBase) element).clonePersist(null);
// we kind of want to have this element a new uuid, but then it is very hard to get it stable.
UUID newElementUUID = null;
synchronized (formComponentElementsUUIDS) {
Map<UUID, UUID> map = formComponentElementsUUIDS.get(parent.getPersistIfAvailable().getUUID());
if (map == null) {
map = new HashMap<>();
formComponentElementsUUIDS.put(parent.getPersistIfAvailable().getUUID(), map);
}
newElementUUID = map.get(element.getUUID());
if (newElementUUID == null) {
newElementUUID = UUID.randomUUID();
map.put(element.getUUID(), newElementUUID);
}
}
((AbstractBase) element).resetUUID(newElementUUID);
String elementName = element.getName();
if (elementName == null) {
elementName = FormElement.SVY_NAME_PREFIX + String.valueOf(element.getID());
}
String templateName = getStartElementName(parent, pd) + elementName;
String formName = parent.getForm().getName();
if (parent.getForm().isFormComponent() && parent.getPersistIfAvailable() instanceof AbstractBase && ((AbstractBase) parent.getPersistIfAvailable()).getRuntimeProperty(FORM_COMPONENT_FORM_NAME) != null) {
formName = ((AbstractBase) parent.getPersistIfAvailable()).getRuntimeProperty(FORM_COMPONENT_FORM_NAME);
}
((AbstractBase) element).setRuntimeProperty(FORM_COMPONENT_FORM_NAME, formName);
((AbstractBase) element).setRuntimeProperty(FORM_COMPONENT_UUID, parent.getPersistIfAvailable().getUUID().toString());
JSONObject elementJson = json.optJSONObject(elementName);
if (elementJson != null) {
Map<String, Method> methods = RepositoryHelper.getSetters(element);
WebObjectSpecification legacySpec = FormTemplateGenerator.getWebObjectSpecification(element);
for (String key : elementJson.keySet()) {
Object val = elementJson.get(key);
if (val != null && methods.get(key) != null) {
Method method = methods.get(key);
Class<?> paramType = method.getParameterTypes()[0];
if (!paramType.isAssignableFrom(val.getClass()) && !(paramType.isPrimitive() && val instanceof Number)) {
PropertyDescription property = legacySpec.getProperty(key);
if (property != null && property.getType() instanceof IDesignValueConverter) {
val = ((IDesignValueConverter) property.getType()).fromDesignValue(val, property);
} else {
// will not fit, very likely a uuid that should be an int.
if (val != null) {
IPersist found = fs.searchPersist(val.toString());
if (found != null)
val = Integer.valueOf(found.getID());
}
}
}
}
if (val instanceof JSONObject && ((AbstractBase) element).getProperty(key) instanceof JSONObject) {
// if both are json (like a nested form) then merge it in.
ServoyJSONObject.mergeAndDeepCloneJSON((JSONObject) val, (JSONObject) ((AbstractBase) element).getProperty(key));
} else if (val instanceof String && StaticContentSpecLoader.PROPERTY_CUSTOMPROPERTIES.getPropertyName().equals(key) && ((AbstractBase) element).getCustomProperties() != null) {
// custom properties needs to be merged in..
JSONObject original = new ServoyJSONObject(((AbstractBase) element).getCustomProperties(), true);
ServoyJSONObject.mergeAndDeepCloneJSON(new ServoyJSONObject((String) val, true), original);
((AbstractBase) element).setCustomProperties(ServoyJSONObject.toString(original, true, true, true));
} else if (val instanceof JSONArray && ((AbstractBase) element).getProperty(key) instanceof IChildWebObject[]) {
IChildWebObject[] webObjectChildren = (IChildWebObject[]) ((AbstractBase) element).getProperty(key);
JSONArray original = new JSONArray();
for (IChildWebObject element2 : webObjectChildren) {
original.put(element2.getJson());
}
ServoyJSONObject.mergeAndDeepCloneJSON((JSONArray) val, original);
((AbstractBase) element).setProperty(key, original);
} else
((AbstractBase) element).setProperty(key, val);
}
}
element.setName(templateName);
elements.add(element);
}
return elements;
}
Aggregations