use of com.servoy.j2db.persistence.IPersist 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;
}
use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.
the class JSRelation method getRelationItems.
/**
* Returns an array of JSRelationItem objects representing the relation criteria defined for this relation.
*
* @sample
* var criteria = relation.getRelationItems();
* for (var i=0; i<criteria.length; i++)
* {
* var item = criteria[i];
* application.output('relation item no. ' + i);
* application.output('primary column: ' + item.primaryDataProviderID);
* application.output('operator: ' + item.operator);
* application.output('foreign column: ' + item.foreignColumnName);
* }
*
* @return An array of JSRelationItem instances representing the relation criteria of this relation.
*/
@JSFunction
public JSRelationItem[] getRelationItems() {
ArrayList<JSRelationItem> al = new ArrayList<JSRelationItem>();
Iterator<IPersist> allObjects = relation.getAllObjects();
while (allObjects.hasNext()) {
IPersist persist = allObjects.next();
if (persist instanceof RelationItem) {
al.add(new JSRelationItem((RelationItem) persist, this, isCopy));
}
}
return al.toArray(new JSRelationItem[al.size()]);
}
use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.
the class JSRelation method removeRelationItem.
/**
* Removes the desired relation item from the specified relation.
*
* @sample
* var relation = solutionModel.newRelation('myRelation', 'db:/myServer/parentTable', 'db:/myServer/childTable', JSRelation.INNER_JOIN);
* relation.newRelationItem('someColumn1', '=', 'someColumn2');
* relation.newRelationItem('anotherColumn', '=', 'someOtherColumn');
* relation.removeRelationItem('someColumn1', '=', 'someColumn2');
* var criteria = relation.getRelationItems();
* for (var i = 0; i < criteria.length; i++) {
* var item = criteria[i];
* application.output('primary column: ' + item.primaryDataProviderID);
* application.output('operator: ' + item.operator);
* application.output('foreign column: ' + item.foreignColumnName);
* }
*
* @param primaryDataProviderID the primary data provider (column) name
* @param operator the operator
* @param foreignColumnName the foreign column name
*/
@JSFunction
public void removeRelationItem(String primaryDataProviderID, String operator, String foreignColumnName) {
checkModification();
Iterator<IPersist> allObjects = relation.getAllObjects();
while (allObjects.hasNext()) {
IPersist persist = allObjects.next();
if (persist instanceof RelationItem) {
RelationItem ri = (RelationItem) persist;
int validOperator = RelationItem.getValidOperator(operator, RelationItem.RELATION_OPERATORS, null);
if (ri.getPrimaryDataProviderID().equals(primaryDataProviderID) && ri.getOperator() == validOperator && ri.getForeignColumnName().equals(foreignColumnName)) {
relation.removeChild(persist);
relation.setValid(true);
break;
}
}
}
}
use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.
the class JSTabPanel method removeTab.
/**
* Removes the tab with the specified name from the tab panel.
*
* @param name the name of the tab to be removed
*
* @sample
* var tabPanel = form.newTabPanel('tabs', 10, 10, 620, 460);
* tabPanel.newTab('tab1', 'Child Two', childOne);
* tabPanel.newTab('tab2', 'Child Two', childTwo);
* tabPanel.removeTab('tab1');
*/
@JSFunction
public void removeTab(String name) {
if (name == null)
return;
TabPanel tp = getBaseComponent(true);
Iterator<IPersist> tabs = tp.getTabs();
while (tabs.hasNext()) {
Tab tab = (Tab) tabs.next();
if (name.equals(tab.getName())) {
// removing the child tab from the tabpanel
tp.removeChild(tab);
break;
}
}
}
use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.
the class JSBase method getOverridePersistIfNeeded.
public static AbstractBase getOverridePersistIfNeeded(AbstractBase persist, AbstractBase finalPersist, IJSParent parent) {
AbstractBase baseComponent = finalPersist;
if (persist != null && persist.getAncestor(IRepository.FORMS) != null) {
IJSParent<?> jsparent = parent;
while (jsparent != null) {
if (jsparent.getSupportChild() instanceof Form)
break;
jsparent = jsparent.getJSParent();
}
if (jsparent != null && jsparent.getSupportChild() instanceof Form && !jsparent.getSupportChild().getUUID().equals(persist.getAncestor(IRepository.FORMS).getUUID())) {
// inherited persist
try {
IPersist parentPersist = persist;
while (PersistHelper.getSuperPersist((ISupportExtendsID) parentPersist) != null) {
parentPersist = PersistHelper.getSuperPersist((ISupportExtendsID) parentPersist);
}
// first check if the override persist already exists, and return it in that case
List<IPersist> children = PersistHelper.getHierarchyChildren((AbstractBase) parent.getSupportChild());
IPersist form = parent.getSupportChild() instanceof Form ? parent.getSupportChild() : parent.getSupportChild().getAncestor(IRepository.FORMS);
if (form != null) {
for (IPersist p : children) {
if (parentPersist.getID() == ((ISupportExtendsID) p).getExtendsID() && form.equals(p.getAncestor(IRepository.FORMS))) {
return (AbstractBase) p;
}
}
} else {
// should not happen
Debug.error("Cannot find form of persist " + parent.getSupportChild());
}
baseComponent = (AbstractBase) persist.cloneObj(parent.getSupportChild(), false, null, false, false, false);
baseComponent.copyPropertiesMap(null, true);
((ISupportExtendsID) baseComponent).setExtendsID(parentPersist.getID());
} catch (Exception ex) {
Debug.error(ex);
}
}
}
return baseComponent;
}
Aggregations