* EOInterface/EOAssociation.m: New variable _objectToAssociations.

(+objectDeallocated:): New private method.
(+initialize): initialize _objectToAssociations.
(-dealloc): Discard any pending notifications.
(-establishConnection): Retain display groups we're bound to.
Retain our self and register our object for dealloc notification.
(-breakConnection): Release display groups we're bound to. Release
our self and discard any pending notifications.
(-subjectChanged): Add comment

* EOInterface/EOColumnAssociation.m (-establishConnection): Assign our
dg ivar after establishing connection.  Use the dg ivar and move 2 if
statements into one.

* EOInterface/EODisplayGroup.m: Remove debugging class/category for
emptyArray and emptyDictionary.
(-indexesForObjectsIndeticalTo:): Fix typo by renaming to
-indexesForObjectsIdenticalTo:.
(-dealloc): Remove our self as an observer for any notifications,
as an editor or message handler for our editing context, our observer
proxies as observers from the observer center. Don't release
array/dictionary ivars that are emptyArray or emptyDictionary.
(-setSelectionIndexes:): Update to reflect change in method name.
(-deleteSelection): Remove unused local var.
(-fetch:): Call -redisplay.
(-updatedObjectIndex:): Return -1 instead of 0 until this is
implemented.
(-setValue:forObject:key:): fix comment in exception handlers.

* EOInterface/EOGenericControlAssociation.m:
(-subjectChanged:): Remove unused local variable.

* EOMasterDetailAssociation.m:
(-establishConnection, -breakConnection, -subjectChanged): Implement.

* EOInterface/EOPopUpAssociation.m: Remove unused local variables.

* EOInterface/EOTableViewAssociation.m:
(-breakConnection:): Remove our NSTableView object from the map table.
(-subjectChanged:): Remove unused local variables. Release temporary
retain on selection indexes.
(+bindToTableView:displayGroup:): Don't retain the table views in the
map table.  Release the newly created association.
(-dealloc): Remove self from the tvAssociationMap.

* EOInterface/SubclassFlags.h: Fix bitmask on MatchKey1AspectMask.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@21439 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Matt Rice 2005-07-09 03:01:22 +00:00
parent 91868e3d12
commit b70ec2777a
9 changed files with 170 additions and 73 deletions

View file

@ -1,3 +1,45 @@
2005-07-08 Matt Rice <ratmice@yahoo.com>
* EOInterface/EOAssociation.m: New variable _objectToAssociations.
(+objectDeallocated:): New private method.
(+initialize): initialize _objectToAssociations.
(-dealloc): Discard any pending notifications.
(-establishConnection): Retain display groups we're bound to.
Retain our self and register our object for dealloc notification.
(-breakConnection): Release display groups we're bound to. Release
our self and discard any pending notifications.
(-subjectChanged): Add comment
* EOInterface/EOColumnAssociation.m (-establishConnection): Assign our
dg ivar after establishing connection. Use the dg ivar and move 2 if
statements into one.
* EOInterface/EODisplayGroup.m: Remove debugging class/category for
emptyArray and emptyDictionary.
(-indexesForObjectsIndeticalTo:): Fix typo by renaming to
-indexesForObjectsIdenticalTo:.
(-dealloc): Remove our self as an observer for any notifications,
as an editor or message handler for our editing context, our observer
proxies as observers from the observer center. Don't release
array/dictionary ivars that are emptyArray or emptyDictionary.
(-setSelectionIndexes:): Update to reflect change in method name.
(-deleteSelection): Remove unused local var.
(-fetch:): Call -redisplay.
(-updatedObjectIndex:): Return -1 instead of 0 until this is
implemented.
(-setValue:forObject:key:): fix comment in exception handlers.
* EOInterface/EOGenericControlAssociation.m:
(-subjectChanged:): Remove unused local variable.
* EOMasterDetailAssociation.m:
(-establishConnection, -breakConnection, -subjectChanged): Implement.
* EOInterface/EOPopUpAssociation.m: Remove unused local variables.
* EOInterface/EOTableViewAssociation.m:
(-breakConnection:): Remove our NSTableView object from the map table.
(-subjectChanged:): Remove unused local variables. Release temporary
retain on selection indexes.
(+bindToTableView:displayGroup:): Don't retain the table views in the
map table. Release the newly created association.
(-dealloc): Remove self from the tvAssociationMap.
* EOInterface/SubclassFlags.h: Fix bitmask on MatchKey1AspectMask.
2005-07-08 Matt Rice <ratmice@yahoo.com>
* DBModeler/AdaptorsPanel.m (-init): Add parenthesis around assignment.

View file

@ -41,9 +41,26 @@
#include "EOAssociation.h"
/* For GDL2NonRetainingArray */
#include "../EOControl/EOPrivate.h"
@implementation EOAssociation
static NSArray *_emptyArray = nil;
static NSMutableArray *_associationClasses = nil;
static NSMapTable *_objectToAssociations;
+ (void) objectDeallocated:(id)object
{
GDL2NonRetainingMutableArray *associations;
associations = NSMapGet(_objectToAssociations, object);
if (associations)
{
[associations makeObjectsPerform: @selector(breakConnection)];
NSMapRemove(_objectToAssociations, object);
}
}
+ (void)bundleLoaded: (NSNotification *)notification
{
DESTROY(_associationClasses);
@ -60,6 +77,9 @@ static NSMutableArray *_associationClasses = nil;
selector: @selector(bundleLoaded:)
name: NSBundleDidLoadNotification
object: nil];
_objectToAssociations = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks,
NSObjectMapValueCallBacks,
32);
}
}
@ -174,9 +194,9 @@ static NSMutableArray *_associationClasses = nil;
- (void)dealloc
{
[self discardPendingNotification];
NSFreeMapTable (_displayGroupMap);
NSFreeMapTable (_displayGroupKeyMap);
[super dealloc];
}
@ -196,17 +216,38 @@ static NSMutableArray *_associationClasses = nil;
EODisplayGroup *displayGroup;
Class EOObserverCenterClass = [EOObserverCenter class];
void *unusedKey;
GDL2NonRetainingMutableArray *associations;
displayGroupEnum = NSEnumerateMapTable(_displayGroupMap);
while (NSNextMapEnumeratorPair(&displayGroupEnum,
&unusedKey, (void*)&displayGroup))
{
[displayGroup retain];
[EOObserverCenterClass addObserver: self forObject: displayGroup];
}
NSEndMapTableEnumeration (&displayGroupEnum);
_isConnected = YES;
//TODO: cause _object to retain us
/* registerAssociationForDeallocHack is implemented in
EOControl/EOEditingContext.m this causes +objectDeallocated:
to be called when '_object' is deallocated, which will break the
connection which releases the association instance. */
[self retain];
[self registerAssociationForDeallocHack:_object];
associations = (id)NSMapGet(_objectToAssociations, _object);
if (!associations)
{
associations = [[GDL2NonRetainingMutableArray alloc] initWithCapacity:32];
[associations addObject:self];
NSMapInsert(_objectToAssociations, _object, associations);
}
else
{
[associations addObject:self];
}
_isConnected = YES;
}
}
@ -224,12 +265,14 @@ static NSMutableArray *_associationClasses = nil;
while (NSNextMapEnumeratorPair(&displayGroupEnum,
&unusedKey, (void *)&displayGroup))
{
[displayGroup release];
[EOObserverCenterClass removeObserver: self forObject: displayGroup];
}
NSEndMapTableEnumeration (&displayGroupEnum);
_isConnected = YES;
//TODO: cause _object to release us
[self discardPendingNotification];
_isConnected = NO;
[self release];
}
}
@ -253,11 +296,13 @@ static NSMutableArray *_associationClasses = nil;
{
return NSMapGet(_displayGroupMap, aspectName);
}
- (NSString *)displayGroupKeyForAspect: (NSString *)aspectName;
{
return NSMapGet(_displayGroupKeyMap, aspectName);
}
/** Implemented by subclasses. */
- (void)subjectChanged
{
}
@ -282,6 +327,7 @@ static NSMutableArray *_associationClasses = nil;
return [dg selectedObjectValueForKey: key];
}
- (BOOL)setValue: (id)value forAspect: (NSString *)aspectName
{
EODisplayGroup *dg = [self displayGroupForAspect: aspectName];

View file

@ -102,13 +102,17 @@
- (void)establishConnection
{
EODisplayGroup *dg = [self displayGroupForAspect:@"value"];
EODisplayGroup *dg;
[super establishConnection];
dg = [self displayGroupForAspect:@"value"];
if (dg)
[EOTableViewAssociation bindToTableView: [[self object] tableView]
displayGroup: dg ];
if ([self displayGroupForAspect:@"value"] != nil)
subclassFlags |= ValueAspectMask;
{
[EOTableViewAssociation bindToTableView: [[self object] tableView]
displayGroup: dg];
subclassFlags |= ValueAspectMask;
}
[[self object] setIdentifier: self];
_enabledAspectBound = [self displayGroupForAspect:@"enabled"] != nil;
}

View file

@ -73,49 +73,15 @@ RCS_ID("$Id$")
@selector(displayGroup:didInsertObject:)
#define DG_DID_CHANGE_SELECTION \
@selector(displayGroupDidChangeSelection:)
/* undocumented notification */
/* undocumented notification */
NSString *EODisplayGroupWillFetchNotification = @"EODisplayGroupWillFetch";
@interface EOIEmptyArray : NSArray
@end
@implementation EOIEmptyArray : NSArray
- (void) release
{
[super release];
}
- (void) dealloc
{
[super dealloc];
}
- (id) autorelease
{
return [super autorelease];
}
@end
@interface GSInlineArray : NSObject
@end
@implementation GSInlineArray(foo)
- (void) release
{
}
- (void) dealloc
{
}
- (id) autorelease
{
return self;
}
@end
@interface NSArray (private)
- (NSArray *)indexesForObjectsIndenticalTo: (NSArray *)array;
- (NSArray *)indexesForObjectsIdenticalTo: (NSArray *)array;
@end
@implementation NSArray (private)
- (NSArray *)indexesForObjectsIndenticalTo: (NSArray *)array
- (NSArray *)indexesForObjectsIdenticalTo: (NSArray *)array
{
unsigned idx, i, c = [array count];
NSMutableArray *indices = (id)[NSMutableArray arrayWithCapacity: c];
@ -174,8 +140,8 @@ NSString *EODisplayGroupWillFetchNotification = @"EODisplayGroupWillFetch";
@implementation EODisplayGroup
static EOIEmptyArray *emptyArray;
static NSDictionary *emptyDictionary;
NSArray *emptyArray;
NSDictionary *emptyDictionary;
+ (void)initialize
{
if (emptyArray == nil)
@ -250,18 +216,31 @@ static BOOL _globalDefaultForValidatesChangesImmediately = NO;
- (void)dealloc
{
DESTROY(_dataSource);
DESTROY(_allObjects);
DESTROY(_displayedObjects);
EOEditingContext *context = [_dataSource editingContext];
DESTROY(_selection);
[[NSNotificationCenter defaultCenter] removeObserver:self];
[context removeEditor:self];
if ([context messageHandler] == self)
[context setMessageHandler:nil];
DESTROY(_dataSource);
if (_allObjects != emptyArray)
DESTROY(_allObjects);
DESTROY(_displayedObjects);
if (_selection != emptyArray)
DESTROY(_selection);
DESTROY(_sortOrdering);
DESTROY(_qualifier);
DESTROY(_localKeys);
DESTROY(_selectedObjects);
[EOObserverCenter removeObserver:_observerNotificationBeginProxy
forObject:self];
[EOObserverCenter removeObserver:_observerNotificationEndProxy
forObject:self];
DESTROY(_observerNotificationBeginProxy);
DESTROY(_observerNotificationEndProxy);
DESTROY(_insertedObjectDefaultValues);
if (_insertedObjectDefaultValues != emptyDictionary)
DESTROY(_insertedObjectDefaultValues);
DESTROY(_savedAllObjects);
DESTROY(_queryMatch);
DESTROY(_queryMin);
@ -670,9 +649,9 @@ static BOOL _globalDefaultForValidatesChangesImmediately = NO;
}
ASSIGNCOPY(_selectedObjects, newObjects);
newSelection =
[_displayedObjects indexesForObjectsIndenticalTo: _selectedObjects];
[_displayedObjects indexesForObjectsIdenticalTo: _selectedObjects];
/* don't release emptyArray */
(_selection == emptyArray) ? _selection = newSelection : ASSIGN(_selection, newSelection);
(_selection == emptyArray) ? _selection = RETAIN(newSelection) : ASSIGN(_selection, newSelection);
_flags.didChangeSelection = YES;
if ([_delegate respondsToSelector: DG_DID_CHANGE_SELECTION])
{
@ -704,7 +683,7 @@ static BOOL _globalDefaultForValidatesChangesImmediately = NO;
NSArray *indices;
if (selection && [selection count])
{
indices = [_displayedObjects indexesForObjectsIndenticalTo: selection];
indices = [_displayedObjects indexesForObjectsIdenticalTo: selection];
if (indices && ![indices count])
{
indices = nil;
@ -885,7 +864,6 @@ static BOOL _globalDefaultForValidatesChangesImmediately = NO;
}
- (BOOL)deleteSelection
{
BOOL flag;
if ([self endEditing])
{
NSArray *selections = [self selectedObjects];
@ -958,6 +936,7 @@ static BOOL _globalDefaultForValidatesChangesImmediately = NO;
- (void)fetch: (id)sender
{
[self fetch];
[self redisplay];
}
- (void)insert: (id)sender
@ -1006,7 +985,7 @@ static BOOL _globalDefaultForValidatesChangesImmediately = NO;
}
- (int)updatedObjectIndex
{
return 0;
return -1;
}
- (id)valueForObject: (id)object key: (NSString *)key
@ -1034,7 +1013,7 @@ static BOOL _globalDefaultForValidatesChangesImmediately = NO;
[object takeValue:value forKeyPath:key];
}
NS_HANDLER
/* use NSLog because -userInfo may contain useful information. */
/* -userInfo likely contains useful information... */
NSLog(@"Exception in %@ name:%@ reason:%@ userInfo:%@", NSStringFromSelector(_cmd), [localException name], [localException reason], [localException userInfo]);
return NO;
NS_ENDHANDLER
@ -1053,7 +1032,7 @@ static BOOL _globalDefaultForValidatesChangesImmediately = NO;
if (exception)
{
/* use NSLog because -userInfo may contain useful information. */
/* -userInfo likely contains useful information... */
NSLog(@"Exception in %@ name:%@ reason:%@ userInfo:%@", NSStringFromSelector(_cmd), [exception name], [exception reason], [exception userInfo]);
}
return (exception == nil);

View file

@ -112,7 +112,6 @@
{
if (subclassFlags & ValueAspectMask)
{
EODisplayGroup *dg = [self displayGroupForAspect:@"value"];
[[self control] setObjectValue: [self valueForAspect:@"value"]];
}
if (subclassFlags & EnabledAspectMask)

View file

@ -34,6 +34,7 @@
#include "EODisplayGroup.h"
#include "EOMasterDetailAssociation.h"
#include "SubclassFlags.h"
@implementation EOMasterDetailAssociation
@ -77,13 +78,42 @@
- (void)establishConnection
{
EODisplayGroup *parent = [self displayGroupForAspect:@"parent"];
[super establishConnection];
if (parent)
{
EODetailDataSource *ds = [_object dataSource];
subclassFlags |= ParentAspectMask;
[ds setMasterClassDescription:[[parent dataSource]
classDescriptionForObjects]];
[ds setDetailKey:[self displayGroupKeyForAspect:@"parent"]];
}
}
- (void)breakConnection
{
[super breakConnection];
subclassFlags = 0;
}
- (void)subjectChanged
{
if (subclassFlags & ParentAspectMask)
{
id selectedObject = [[self displayGroupForAspect:@"parent"]
selectedObject];
id key = [self displayGroupKeyForAspect:@"parent"];
if (selectedObject)
{
[[_object dataSource]
qualifyWithRelationshipKey:key
ofObject:selectedObject];
if ([_object fetch])
[_object redisplay];
}
}
}
- (EOObserverPriority)priority

View file

@ -116,7 +116,6 @@
{
int i,c;
NSArray *dispObj;
NSMutableArray *titles = [[NSMutableArray alloc] init];
subclassFlags |= TitlesAspectMask;
dispObj = [dg displayedObjects];
@ -178,8 +177,6 @@
{
int i,c;
NSArray *dispObj;
NSMutableArray *titles = [[NSMutableArray alloc] init];
NSString *key = [self displayGroupKeyForAspect:@"titles"];
dispObj = [dg displayedObjects];
c = [dispObj count];
@ -201,14 +198,12 @@
if ([dg selectionChanged] || [dg contentsChanged])
{
int tag = [[self valueForAspect:@"selectedTag"] intValue];
int index = [_object indexOfItemWithTag:tag];
[_object selectItemAtIndex:tag];
}
}
else if (subclassFlags & SelectedTitleAspectMask)
{
NSString *title;
dg = [self displayGroupForAspect:@"selectedTitle"];
if ([dg selectionChanged] || [dg contentsChanged])
{
@ -261,7 +256,6 @@
}
else if (subclassFlags & SelectedObjectAspectMask)
{
EODisplayGroup *titlesGroup = [self displayGroupForAspect:@"titles"];
id obj = [[_object itemAtIndex:[_object indexOfSelectedItem]] representedObject];
[self setValue: obj forAspect:@"selectedObject"];

View file

@ -102,6 +102,7 @@ static NSMapTable *tvAssociationMap;
- (void)breakConnection
{
[super breakConnection];
NSMapRemove(tvAssociationMap, _object);
_enabledAspectBound = NO;
_italicAspectBound = NO;
_colorAspectBound = NO;
@ -121,7 +122,7 @@ static NSMapTable *tvAssociationMap;
if ([dg selectionChanged])
{
NSArray *selectionIndexes = RETAIN([dg selectionIndexes]);
unsigned int i, count, newSel;
unsigned int i, count;
count = [selectionIndexes count];
for (i = 0; i < count; i++)
{
@ -130,6 +131,7 @@ static NSMapTable *tvAssociationMap;
byExtendingSelection: (i != 0)]; /* don't extend the first selection */
[[self object] scrollRowToVisible:rowIndex];
}
RELEASE(selectionIndexes);
}
}
@ -141,7 +143,7 @@ static NSMapTable *tvAssociationMap;
if (!tvAssociationMap)
{
tvAssociationMap = NSCreateMapTableWithZone(NSObjectMapKeyCallBacks,
tvAssociationMap = NSCreateMapTableWithZone(NSNonRetainedObjectMapKeyCallBacks,
NSNonRetainedObjectMapValueCallBacks,
0, [self zone]);
assoc = [[self allocWithZone:NSDefaultMallocZone()] initWithObject:tableView];
@ -150,6 +152,7 @@ static NSMapTable *tvAssociationMap;
[tableView setDataSource:assoc];
[tableView setDelegate:assoc];
[assoc establishConnection];
RELEASE(assoc);
return;
}
@ -161,6 +164,7 @@ static NSMapTable *tvAssociationMap;
[tableView setDataSource:assoc];
[tableView setDelegate:assoc];
[assoc establishConnection];
RELEASE(assoc);
NSMapInsert(tvAssociationMap, tableView, assoc);
}
}
@ -292,7 +296,6 @@ textShouldBeginEditing: (NSText *)fieldEditor
- (void) dealloc
{
NSMapRemove(tvAssociationMap, self);
[super dealloc];
}
@end

View file

@ -81,9 +81,9 @@
#define ParentAspectMask 0x1
/* EOPickTextAssociation:3 (matchKey2, matchKey3, matchKey1) */
#define MatchKey1AspectMask 0x0
#define MatchKey2AspectMask 0x1
#define MatchKey3AspectMask 0x2
#define MatchKey1AspectMask 0x4
/* EORadioMatrixAssociation:3 (enabled, selectedTitle, selectedTag) */
// EnabledAspectMask 0x1