Oh man! All that code reduced to:
NSMutableArray favourites;
public ElementSearch(WOContext context) {
super(context);
favourites();
}
/** @TypeInfo Element */
public NSMutableArray favourites() {
if (favourites == null) {
favourites = (NSMutableArray)user.favouriteElements();
}
return favourites;
}
public boolean elementChecked()
{
return favourites.containsObject(anElement);
}
public void setElementChecked(boolean newElementChecked) {
// Jerry Walker's code:
// is the element already in the favourites?
boolean oldValue = elementChecked();
// if selected, and not already in the favourites list, add it
if (newElementChecked && !oldValue) {
user.addObjectToBothSidesOfRelationshipWithKey(anElement, "favouriteElements");
}
// if not selected but already in the favourites list, remove it
else if ( !newArtifactChecked && oldValue) {
user.removeObjectFromBothSidesOfRelationshipWithKey(anElement, "favouriteElements");
}
}
public WOComponent submit()
{
Session session = (Session)session();
EOEditingContext ec = session.defaultEditingContext();
ec.saveChanges();
return null;
}
Where do I send the beer??
I didn't realize that I could cast the NSArray user.favouriteElements() to NSMutableArray. That was pretty much the key. NOW it's FAST!
Thanks so much,
David
--
It's like driving a car at night. You never see further than your headlights, but you can make the whole trip that way.
E. L. Doctorow
from Sunbeams: http://www.thesunmagazine.org
On 5 Dec 2006, at 9:41 AM, Mark Morris wrote:
you should be able to directly use user.favouriteElements() instead of going through selectionList. In other words, elementChecked and setElementChecked can directly work on userFavouriteElements().