use of com.servoy.j2db.persistence.IPersist 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.IPersist 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.IPersist in project servoy-client by Servoy.
the class WebFormComponent method findCorrectFormEvenForServoyFormComponentChildren.
private Form findCorrectFormEvenForServoyFormComponentChildren() {
Form formElementForm = null;
IPersist persist = formElement.getPersistIfAvailable();
if (persist instanceof AbstractBase) {
String formName = ((AbstractBase) persist).getRuntimeProperty(FormElementHelper.FORM_COMPONENT_FORM_NAME);
if (formName != null) {
formElementForm = dataAdapterList.getApplication().getFormManager().getForm(formName).getForm();
}
}
if (formElementForm == null) {
formElementForm = formElement.getForm();
}
return formElementForm;
}
use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.
the class FormElementHelper method compareTabSeq.
// TODO: try to make this method recursive, for the cases when there are more than 2 nested form components
public static int compareTabSeq(int seq1, Object o1, int seq2, Object o2, FlattenedSolution flattenedSolution) {
int yxCompare = 0;
if (seq1 == ISupportTabSeq.DEFAULT && seq2 == ISupportTabSeq.DEFAULT && o1 instanceof IPersist && o2 instanceof IPersist) {
IPersist form = ((IPersist) o1).getAncestor(IRepository.FORMS);
if (form instanceof Form && ((Form) form).isResponsiveLayout()) {
if (((IPersist) o1).getParent().equals(((IPersist) o2).getParent())) {
// delegate to Yx
yxCompare = PositionComparator.YX_PERSIST_COMPARATOR.compare((IPersist) o1, (IPersist) o2);
} else {
/*
* We must search all the parents of the objects o1 and o2.If the objects have a same parent by searching all the ancestors we must compare
* the objects before encountering the same parent.
*/
List<IPersist> parentsOfo1 = new ArrayList<IPersist>();
IPersist parent = ((IPersist) o1).getParent();
while (!(parent instanceof Form)) {
parentsOfo1.add(parent);
parent = parent.getParent();
}
// also add the form to the list of parents
parentsOfo1.add(parent);
// the last parent of o1 or o2 is a formComponent, not the main form
if (parent instanceof Form) {
if (((Form) parent).isFormComponent() && o1 instanceof AbstractBase) {
String uuid = ((AbstractBase) o1).getRuntimeProperty(FORM_COMPONENT_UUID);
if (uuid != null) {
IPersist persist = flattenedSolution.searchPersist(uuid);
if (persist != null) {
parent = persist.getParent();
while (!(parent instanceof Form)) {
parentsOfo1.add(parent);
parent = parent.getParent();
}
// also add the form to the list of parents
parentsOfo1.add(parent);
}
}
}
}
IPersist childo2 = (IPersist) o2;
IPersist parento2 = ((IPersist) o2).getParent();
while (!(parento2 instanceof Form)) {
if (parentsOfo1.contains(parento2)) {
int index = parentsOfo1.indexOf(parento2);
// delegate to Yx
if (index > 0) {
yxCompare = PositionComparator.YX_PERSIST_COMPARATOR.compare(parentsOfo1.get(index - 1), childo2);
}
}
childo2 = parento2;
parento2 = parento2.getParent();
}
// also check to see if the common parent is the actual form
if (parentsOfo1.contains(parento2)) {
int index = parentsOfo1.indexOf(parento2);
if (index > 0) {
yxCompare = PositionComparator.YX_PERSIST_COMPARATOR.compare(parentsOfo1.get(index - 1), childo2);
}
}
if (parento2 instanceof Form && !parento2.equals(form)) {
if (((Form) parento2).isFormComponent() && o2 instanceof AbstractBase) {
String uuid = ((AbstractBase) o2).getRuntimeProperty(FORM_COMPONENT_UUID);
if (uuid != null) {
IPersist persist = flattenedSolution.searchPersist(uuid);
if (persist != null) {
parento2 = persist.getParent();
while (!(parento2 instanceof Form)) {
if (parentsOfo1.contains(parento2)) {
int index = parentsOfo1.indexOf(parento2);
// delegate to Yx
if (index > 0) {
yxCompare = PositionComparator.YX_PERSIST_COMPARATOR.compare(parentsOfo1.get(index - 1), childo2);
}
}
childo2 = parento2;
parento2 = parento2.getParent();
}
}
}
}
}
if (yxCompare == 0 && parentsOfo1.contains(parento2) && parentsOfo1.size() > 1) {
yxCompare = PositionComparator.YX_PERSIST_COMPARATOR.compare(parentsOfo1.get(parentsOfo1.size() - 2), childo2);
}
}
} else if (form instanceof Form && !((Form) form).isResponsiveLayout()) {
yxCompare = PositionComparator.YX_PERSIST_COMPARATOR.compare((IPersist) o1, (IPersist) o2);
}
// if they are at the same position, and are different persist, just use UUID to decide the sequence
return yxCompare == 0 ? ((IPersist) o1).getUUID().compareTo(((IPersist) o2).getUUID()) : yxCompare;
} else if (seq1 == ISupportTabSeq.DEFAULT) {
return 1;
} else if (seq2 == ISupportTabSeq.DEFAULT) {
return -1;
}
return seq1 - seq2;
}
use of com.servoy.j2db.persistence.IPersist 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);
}
}
Aggregations