/***************************************************************** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. ****************************************************************/ #import "CAYTreeController.h" @implementation CAYTreeController - (id)newObject { /* * Tip: If you are having trouble here, make sure that the views selectionIndexPaths are * bound to the controllers selectionIndexPaths */ id r = [super newObject]; if([self objectContext] && [r isKindOfClass:[CAYPersistentObject class]]) { CAYPersistentObject *po = (CAYPersistentObject *)r; if(![po objectContext]) { [[self objectContext] registerNewObject:po]; } } return r; } - (void)remove:(id)sender { // TODO: look for deleteObjectOnRemove from binding? Problem is that it only are used // in a core data environment // remember objects to delete for later NSMutableArray *objectsToDelete = [NSMutableArray array]; if([self deleteObjectOnRemove]) { [objectsToDelete addObjectsFromArray:[self selectedObjects]]; } // do the relationship handling [super remove:sender]; // delete objects if any if([self deleteObjectOnRemove]) { CAYPersistentObject *element = nil; for(element in objectsToDelete) { [[element objectContext] deleteObject:element]; } } } -(void)setObjectContext:(CAYObjectContext *)ctxt { // do not need to retain our master objectContext = ctxt; } -(CAYObjectContext *)objectContext { return objectContext; } -(void)setDeleteObjectOnRemove:(BOOL)d { deleteObjectOnRemove = d; } -(BOOL)deleteObjectOnRemove { return deleteObjectOnRemove; } -(void)dealloc { [self setObjectContext:nil]; [super dealloc]; } @end