David
/** @TypeInfo Artifact */
public NSArray favourites() {
if (favourites == null) {
favourites = favAppPermission.favouriteArtifacts(); //get favourites from the database
}
return favourites;
}
/** @TypeInfo Artifact */
public NSMutableArray selectionList() {
if (selectionList == null) {
selectionList = new NSMutableArray(favourites.mutableClone()); // set the UI the same as the contents of the database
}
return selectionList;
}
public boolean artifactChecked()
{
return selectionList.containsObject(anArtifact); // is the item checked in the UI?
}
public void setArtifactChecked(boolean newArtifactChecked) {
if ( newArtifactChecked) {
if (!selectionList.containsObject(anArtifact)) {
selectionList.addObject(anArtifact);
}
} else
if (selectionList.containsObject(anArtifact)) {
selectionList.removeObject(anArtifact);
mostRecentRemoval.addObject(anArtifact);
}
}
public WOComponent submit()
{
Session session = (Session)session();
EOEditingContext ec = session.defaultEditingContext();
int y = 0;
while (mostRecentRemoval.count() != y) {
anArtifact = (Artifact)mostRecentRemoval.objectAtIndex(y);
favAppPermission.removeObjectFromBothSidesOfRelationshipWithKey(anArtifact, "favouriteArtifacts");
++y;
}
int z = 0;
while (selectionList.count() != z) {
anArtifact = (Artifact)selectionList.objectAtIndex(z);
favAppPermission.addObjectToBothSidesOfRelationshipWithKey(anArtifact, "favouriteArtifacts");
++z;
}
ec.saveChanges();
return null;
}
CheckBox1: WOCheckBox {
checked = artifactChecked;
}