this.nextPage = nextPage;
this.pickRelationshipName = pickRelationshipName;
}
public WOComponent nextPage(WOComponent sender) {
EOEditingContext ec = eo.editingContext();
ec.lock();
try {
NSArray selectedObjects;
if(sender instanceof ERDPickPageInterface) {
selectedObjects = ((ERDPickPageInterface)sender).selectedObjects();
} else {
selectedObjects = (NSArray)sender.valueForKeyPath("selectedObjects");
}
NSArray relatedObjects = (NSArray)eo.valueForKeyPath(relationshipName);
for(Enumeration e = relatedObjects.immutableClone().objectEnumerator(); e.hasMoreElements(); ) {
EOEnterpriseObject relatedObject = (EOEnterpriseObject)e.nextElement();
EOEnterpriseObject pickedObject = (EOEnterpriseObject)relatedObject.valueForKey(pickRelationshipName);
if(!selectedObjects.containsObject(pickedObject)) {
eo.removeObjectFromBothSidesOfRelationshipWithKey(relatedObject, relationshipName);
ec.deleteObject(relatedObject);
}
}
NSArray pickedObjects = (NSArray)eo.valueForKeyPath(relationshipName +"." + pickRelationshipName +".@unique");
EOEntity entity = ERXEOAccessUtilities.destinationEntityForKeyPath(ERXEOAccessUtilities.entityForEo(eo), relationshipName);
for(Enumeration e = selectedObjects.objectEnumerator(); e.hasMoreElements(); ) {
EOEnterpriseObject selectedObject = (EOEnterpriseObject)e.nextElement();
if(!pickedObjects.containsObject(selectedObject)) {
EOEnterpriseObject relatedObject = ERXEOControlUtilities.createAndInsertObject(ec, entity.name());
relatedObject.addObjectToBothSidesOfRelationshipWithKey(selectedObject, pickRelationshipName);
eo.addObjectToBothSidesOfRelationshipWithKey(relatedObject, relationshipName);
}
}
} finally {
ec.unlock();
}
return nextPage;
}