mirror of
https://github.com/gnustep/libs-gdl2.git
synced 2025-02-19 17:50:47 +00:00
* GDL2Palette/KeyWrapper.m: Ditto. * GDL2Palette/ConnectionInspector.h * GDL2Palette/ConnectionInspector.m (init): Initialize _values. (-awakeFromNib): Update handling of horizontal scroller. (-_associationClassesUsableWithObject:): Implement. (-setObject:): Fix assignment issues. (-_keysFromClassDescription:): Implement. (-_keysFromArray:): Ditto. (-updateValues): Reimplement. (-_oaBrowserAction:): Ditto. (-browser:numberOfRowsInColumn:): Refine implementation. (-browser:willDisplayCell:atRow:column:): Reimplement. (-ok:): Update associations in active document. * GDL2Palette/ResourceManager.m (defaultEditingContext): Try to find defaultEditingContext in document objects. (addResourcesFromPasteboard:): Reimplement. * GDL2Palette/Foundation+Categories.m: (arrayWithObjectsRespondingYesToSelector:): Fix leak. (arrayWithObjectsRespondingYesToSelector:withObject:): Ditto. * GDL2Palette/GNUmakefile: Use PALETTE_LIBS instead of ADDITIONAL_LDFLAGS to link libraries. Add new files. * GDL2Palette/GDL2Palette.tiff: New file. * GDL2Palette/GDL2ConnectionInspector.gorm: New files. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@23398 72102866-910b-0410-8b05-ffd578937521
180 lines
5.4 KiB
Objective-C
180 lines
5.4 KiB
Objective-C
#include "ResourceManager.h"
|
|
|
|
#include <EOInterface/EOAspectConnector.h>
|
|
#include <EOInterface/EODisplayGroup.h>
|
|
#include <EOInterface/EOMasterDetailAssociation.h>
|
|
|
|
#include <EOModeler/EOModelerApp.h>
|
|
#include <GormCore/GormDocument.h>
|
|
|
|
#include <EOAccess/EOModelGroup.h>
|
|
#include <EOAccess/EODatabaseDataSource.h>
|
|
|
|
#include <EOControl/EODetailDataSource.h>
|
|
|
|
#include <AppKit/NSPasteboard.h>
|
|
|
|
#include <Foundation/NSBundle.h>
|
|
#include <Foundation/NSNotification.h>
|
|
|
|
@implementation GDL2ResourceManager
|
|
- (id) initWithDocument:(id<IBDocuments>)doc
|
|
{
|
|
self = [super initWithDocument:doc];
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
selector:@selector(didOpenDocument:)
|
|
name:IBDidOpenDocumentNotification
|
|
object:[self document]];
|
|
|
|
|
|
return self;
|
|
}
|
|
|
|
- (void) didOpenDocument:(NSNotification *)notif
|
|
{
|
|
NSArray *tmp;
|
|
NSMutableArray *modelPaths = [NSMutableArray new];
|
|
NSString *docPath;
|
|
int i,c;
|
|
docPath = [[[self document] documentPath] stringByDeletingLastPathComponent];
|
|
tmp = [[NSBundle bundleWithPath: docPath]
|
|
pathsForResourcesOfType:@"eomodeld"
|
|
inDirectory:nil];
|
|
[modelPaths addObjectsFromArray:tmp];
|
|
tmp = [[NSBundle bundleWithPath: docPath]
|
|
pathsForResourcesOfType:@"eomodel"
|
|
inDirectory:nil];
|
|
|
|
for (i = 0, c = [modelPaths count]; i < c; i++)
|
|
{
|
|
if (![[EOModelGroup defaultGroup] modelWithPath:[modelPaths objectAtIndex:i]])
|
|
[[EOModelGroup globalModelGroup]
|
|
addModelWithFile:[modelPaths objectAtIndex:i]];
|
|
}
|
|
}
|
|
|
|
- (EOEditingContext *) defaultEditingContext
|
|
{
|
|
NSArray *tmp;
|
|
unsigned i, c;
|
|
|
|
tmp = [[self document] objects];
|
|
for (i = 0, c = [tmp count]; i < c; i++)
|
|
{
|
|
id obj = [tmp objectAtIndex:i];
|
|
|
|
if ([obj isKindOfClass:[EOEditingContext class]])
|
|
{
|
|
_defaultEditingContext = obj;
|
|
}
|
|
}
|
|
|
|
if (!_defaultEditingContext)
|
|
_defaultEditingContext = [[EOEditingContext alloc] init];
|
|
|
|
return _defaultEditingContext;
|
|
}
|
|
|
|
- (BOOL) acceptsResourcesFromPasteboard:(NSPasteboard *)pb
|
|
{
|
|
return [[pb types] containsObject:EOMPropertyPboardType];
|
|
}
|
|
|
|
- (NSArray *)resourcePasteboardTypes
|
|
{
|
|
return [NSArray arrayWithObject: EOMPropertyPboardType];
|
|
}
|
|
|
|
- (void) addResourcesFromPasteboard:(NSPasteboard *)pb
|
|
{
|
|
NSArray *pList = [pb propertyListForType:EOMPropertyPboardType];
|
|
EOEditingContext *ec = [self defaultEditingContext];
|
|
NSString *modelPath = [pList objectAtIndex:0];
|
|
int c = [pList count];
|
|
|
|
if (![[self document] containsObject:ec])
|
|
{
|
|
[[self document] attachObject:ec toParent:nil];
|
|
}
|
|
|
|
if (![[EOModelGroup defaultGroup] modelWithPath:modelPath])
|
|
{
|
|
[[EOModelGroup defaultGroup] addModelWithFile:modelPath];
|
|
}
|
|
|
|
if (c == 2)
|
|
{
|
|
EODisplayGroup *dg = [[EODisplayGroup alloc] init];
|
|
EODataSource *ds;
|
|
NSNibOutletConnector *dsConn;
|
|
NSString *eName = [pList objectAtIndex:1];
|
|
ds = [[EODatabaseDataSource alloc]
|
|
initWithEditingContext:ec
|
|
entityName:eName];
|
|
[dg setDataSource:ds];
|
|
RELEASE(ds);
|
|
[[self document] attachObject:dg toParent:nil];
|
|
[[self document] setName:eName forObject:dg];
|
|
dsConn = [[NSNibOutletConnector alloc] init];
|
|
[dsConn setSource:ds];
|
|
[dsConn setDestination:dg];
|
|
[dsConn setLabel: [NSString stringWithFormat:@"dataSource - %@", [ds class]]];
|
|
RELEASE(dg);
|
|
[[(id<IB>)NSApp activeDocument] addConnector: AUTORELEASE(dsConn)];
|
|
}
|
|
else if (c == 3) /* relationship name */
|
|
{
|
|
/* FIXME only valid for to many relationships */
|
|
EODisplayGroup *masterDG;
|
|
EODisplayGroup *detailDG;
|
|
NSNibOutletConnector *dsConn;
|
|
EOAspectConnector *conn;
|
|
EOAssociation *assoc;
|
|
EODataSource *ds;
|
|
NSString *entName = [pList objectAtIndex:1];
|
|
NSString *relName = [pList objectAtIndex:2];
|
|
masterDG = [[EODisplayGroup alloc] init];
|
|
detailDG = [[EODisplayGroup alloc] init];
|
|
ds = [[EODatabaseDataSource alloc] initWithEditingContext:ec
|
|
entityName:entName];
|
|
[masterDG setDataSource:ds];
|
|
RELEASE(ds);
|
|
|
|
dsConn = AUTORELEASE([[NSNibOutletConnector alloc] init]);
|
|
[dsConn setSource:ds];
|
|
[dsConn setDestination:masterDG];
|
|
[dsConn setLabel: [NSString stringWithFormat:@"dataSource - %@", [ds class]]];
|
|
|
|
[[self document] attachObject:masterDG toParent:nil];
|
|
[[self document] setName:entName forObject:masterDG];
|
|
[[(id<IB>)NSApp activeDocument] addConnector: dsConn];
|
|
ds = [ds dataSourceQualifiedByKey:relName];
|
|
[detailDG setDataSource:ds];
|
|
/*
|
|
assoc = [[EOMasterDetailAssociation alloc] initWithObject:detailDG];
|
|
[assoc bindAspect:@"parent"
|
|
displayGroup:masterDG
|
|
key:relName];
|
|
conn = [[EOAspectConnector alloc] initWithAssociation:assoc
|
|
aspectName:@"parent"];
|
|
|
|
[conn setSource:masterDG];
|
|
[conn setDestination:detailDG];
|
|
[conn setLabel:[NSString stringWithFormat:@"parent - %@",[pList objectAtIndex:2]]];
|
|
*/
|
|
|
|
dsConn = [[NSNibOutletConnector alloc] init];
|
|
[dsConn setSource:ds];
|
|
[dsConn setDestination:detailDG];
|
|
[dsConn setLabel: [NSString stringWithFormat:@"dataSource - %@", [ds class]]];
|
|
[[self document] attachObject:detailDG toParent:nil];
|
|
[[self document] setName:relName forObject:detailDG];
|
|
// [[(id<IB>)NSApp activeDocument] addConnector: conn];
|
|
[[(id<IB>)NSApp activeDocument] addConnector: AUTORELEASE(dsConn)];
|
|
RELEASE(masterDG);
|
|
RELEASE(detailDG);
|
|
}
|
|
}
|
|
|
|
@end
|
|
|