mirror of
https://github.com/gnustep/libs-gdl2.git
synced 2025-02-22 19:01:04 +00:00
assignment. Replace label with window title. (-runAdaptorsPanel:): Remove unused variable. * DBModeler/DefaultColumnProvider.m: Add missing braces, remove unused ivars. (-cellForColumnNamed:): Autorelease cells. * DBModeler/EOAdditions.m: New EOAttribute KVC methods -allowNull and -setAllowNull:. * DBModeler/GNUmakefile: Add new to project. * DBModeler/KVDataSource.m (-createObject:): Return nil after throwing exception. * DBModeler/MainModelEditor.m (-dragImageForRows:event:dragImageOffset:):: Enable drag and drop for relationships. (-initWithDocument:): Add parenthesis around assignment. Don't release the document window on close. (-ecStuff:): temporarily reload everything in the outline view when something changes. (-viewSelectedObject:): Remove NSLog. Rewrite editor activation. Fix leaks. * DBModeler/Modeler.m (-applicationWillFinishLaunching:): Add new menu items. Don't order our menu in. (-new:,-open:): Move document initializition to _newDocumentWithModel:. (-_newDocumentWithModel:,-newFromDatabase:): New methods. (-validateMenuItem:,-generateSQL:): Ditto. * DBModeler/ModelerAttributeEditor.m (-initWithParentEditor:): Remove unused variables. (-displayGroupDidChangeSelection:): return early if there is no longer a selection. * DBModeler/ModelerEntityEditor.m: (-canSupportCurrentSelection): Remove NSLog. (-displayGroupDidChangeSelection:): Ditto. (-dealloc:): New method. (-initWithParentEditor:): Remove unused variables. Add parens around assignment. Release local variables. * DBModeler/ModelerTableEmbedibleEditor: (-addDefaultTableColumnsForTableView:displayGroup:): Release table columns. (-addTableColumnForItem:tableView:): Ditto. * DBModeler/Inspectors/RelationshipInspector.m: (-selectedEntity, -selectedDestinationAttribute): New methods. (-selectedSourceAttribute, -indexOfSourceAttribute:): Ditto. (-indexOfDestinationAttribute:,joinWithSource:destination:): Ditto. (-selectedJoin:,updateConnectButton,): Ditto. (-refresh): Rewrite using new methods. (-numberOfRowsInTableView:): Add fallback return value. (-tableView:objectValueForTableColumn:row:): Ditto. (-tableView:selectionDidChange:): If a source or destination attribute is now selected, select its counterpart. (-tableView:shouldSelectRow:): New method to disallow entity selection if there is a destination entity. (-tableView:willDisplayCell:forTableColumn:row:): New method, set the cell text color to disabled text color, if we would disallow selection. (-connectionChanged:): Implement disconnection. * DBModeler/SQLGenerator.h/m: New files initial implementation. * DBModeler/Resources/SQLGenerator.gorm: Ditto. * DBModeler/ConsistencyChecker.h/m: Ditto. * DBModeler/ConsistencyResults.h/m: Ditto. * DBModeler/ConsistencyResults.gorm: Ditto. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@21438 72102866-910b-0410-8b05-ffd578937521
341 lines
9 KiB
Objective-C
341 lines
9 KiB
Objective-C
#include "RelationshipInspector.h"
|
|
|
|
#include <EOAccess/EOEntity.h>
|
|
#include <EOAccess/EORelationship.h>
|
|
#include <EOAccess/EOModel.h>
|
|
#include <EOAccess/EOAttribute.h>
|
|
|
|
#include <EOModeler/EOModelerApp.h>
|
|
#include <EOModeler/EOModelerDocument.h>
|
|
|
|
#include <Foundation/NSArray.h>
|
|
|
|
@implementation RelationshipInspector
|
|
- (EOEntity *)selectedEntity
|
|
{
|
|
int row = [destEntity_tableView selectedRow];
|
|
|
|
if (row == -1)
|
|
return nil;
|
|
|
|
return [[[[EOMApp activeDocument] model] entities] objectAtIndex:row];
|
|
}
|
|
|
|
- (EOAttribute *)selectedDestinationAttribute
|
|
{
|
|
int row = [destAttrib_tableView selectedRow];
|
|
|
|
if (row == -1)
|
|
return nil;
|
|
|
|
return [[[self selectedEntity] attributes]
|
|
objectAtIndex:[destAttrib_tableView selectedRow]];
|
|
}
|
|
|
|
- (EOAttribute *)selectedSourceAttribute
|
|
{
|
|
int row = [srcAttrib_tableView selectedRow];
|
|
|
|
if (row == -1)
|
|
return nil;
|
|
|
|
return [[[[self selectedObject] entity] attributes] objectAtIndex:[srcAttrib_tableView selectedRow]];
|
|
}
|
|
|
|
- (int) indexOfSourceAttribute:(EOAttribute *)srcAttrib
|
|
{
|
|
id tmp;
|
|
int row;
|
|
|
|
if (srcAttrib == nil) return NSNotFound;
|
|
|
|
tmp = [self selectedObject];
|
|
if (tmp == nil) return NSNotFound;
|
|
|
|
tmp = [tmp entity];
|
|
if (tmp == nil) return NSNotFound;
|
|
|
|
tmp = [(EOEntity *)tmp attributes];
|
|
if (tmp == nil) return NSNotFound;
|
|
|
|
row = [tmp indexOfObject:srcAttrib];
|
|
return row;
|
|
}
|
|
|
|
- (int) indexOfDestinationAttribute:(EOAttribute *)destAttrib
|
|
{
|
|
id tmp;
|
|
int row;
|
|
|
|
if (destAttrib == nil) return NSNotFound;
|
|
|
|
tmp = [self selectedObject];
|
|
if (tmp == nil) return NSNotFound;
|
|
|
|
tmp = [tmp destinationEntity];
|
|
if (tmp == nil) return NSNotFound;
|
|
|
|
tmp = [(EOEntity *)tmp attributes];
|
|
if (tmp == nil) return NSNotFound;
|
|
|
|
row = [tmp indexOfObject:destAttrib];
|
|
return row;
|
|
}
|
|
|
|
- (EOJoin *) joinWithSource:(EOAttribute *)srcAttrib destination:(EOAttribute *)destAttrib
|
|
{
|
|
NSArray *joins;
|
|
int i,c;
|
|
|
|
if (!srcAttrib && !destAttrib)
|
|
return nil;
|
|
|
|
joins = [[self selectedObject] joins];
|
|
c = [joins count];
|
|
for (i = 0; i < c; i++)
|
|
{
|
|
BOOL flag;
|
|
id join = [joins objectAtIndex:i];
|
|
|
|
/* if both arguments are non-nil, both must be equal,
|
|
* if one argument is nil the non-nil argument must be equal */
|
|
flag = ((srcAttrib
|
|
&& destAttrib
|
|
&& [srcAttrib isEqual:[join sourceAttribute]]
|
|
&& [destAttrib isEqual:[join destinationAttribute]])
|
|
|| (srcAttrib
|
|
&& (destAttrib == nil)
|
|
&& [srcAttrib isEqual:[join sourceAttribute]])
|
|
|| (destAttrib
|
|
&& (srcAttrib == nil)
|
|
&& [destAttrib isEqual:[join destinationAttribute]]));
|
|
|
|
if (flag)
|
|
{
|
|
return join;
|
|
}
|
|
}
|
|
return nil;
|
|
}
|
|
|
|
- (EOJoin *) selectedJoin
|
|
{
|
|
return [self joinWithSource:[self selectedSourceAttribute]
|
|
destination:[self selectedDestinationAttribute]];
|
|
}
|
|
|
|
- (void) awakeFromNib
|
|
{
|
|
[destEntity_tableView setAllowsEmptySelection:NO];
|
|
[srcAttrib_tableView setAllowsEmptySelection:NO];
|
|
[destAttrib_tableView setAllowsEmptySelection:NO];
|
|
}
|
|
|
|
- (float) displayOrder
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
- (BOOL) canInspectObject:(id)anObject
|
|
{
|
|
return [anObject isKindOfClass:[EORelationship class]];
|
|
}
|
|
|
|
- (void) updateConnectButton
|
|
{
|
|
[connect_button setState: ([self selectedJoin] != nil) ? NSOnState : NSOffState];
|
|
}
|
|
|
|
- (void) refresh
|
|
{
|
|
EOModel *activeModel = [[EOMApp activeDocument] model];
|
|
EOEntity *destEntity;
|
|
EOAttribute *srcAttrib, *destAttrib;
|
|
NSArray *joins;
|
|
unsigned int row;
|
|
[name_textField setStringValue:[(EORelationship *)[self selectedObject] name]];
|
|
|
|
/* it is important that the destEntity has a selected row before the destAttrib tableview
|
|
* reloads data */
|
|
[destEntity_tableView reloadData];
|
|
destEntity = [[self selectedObject] destinationEntity];
|
|
if (destEntity)
|
|
{
|
|
row = [[activeModel entities] indexOfObject:destEntity];
|
|
if (row == NSNotFound)
|
|
row = 0;
|
|
}
|
|
else if ([destEntity_tableView numberOfRows])
|
|
row = 0;
|
|
|
|
[destEntity_tableView selectRow:row byExtendingSelection:NO];
|
|
|
|
joins = [[self selectedObject] joins];
|
|
|
|
if ([joins count])
|
|
{
|
|
EOJoin *join = [joins objectAtIndex:0];
|
|
srcAttrib = [join sourceAttribute];
|
|
destAttrib = [join destinationAttribute];
|
|
row = [self indexOfSourceAttribute:srcAttrib];
|
|
[srcAttrib_tableView selectRow:row byExtendingSelection:NO];
|
|
row = [self indexOfDestinationAttribute:srcAttrib];
|
|
[destAttrib_tableView selectRow:row byExtendingSelection:NO];
|
|
}
|
|
else
|
|
{
|
|
[srcAttrib_tableView selectRow:0 byExtendingSelection:NO];
|
|
[destAttrib_tableView selectRow:0 byExtendingSelection:NO];
|
|
}
|
|
|
|
[self updateConnectButton];
|
|
|
|
[joinCardinality_matrix selectCellWithTag:[[self selectedObject] isToMany]];
|
|
[joinSemantic_popup selectItemAtIndex: [joinSemantic_popup indexOfItemWithTag: [[self selectedObject] joinSemantic]]];
|
|
}
|
|
|
|
- (int) numberOfRowsInTableView:(NSTableView *)tv
|
|
{
|
|
EOModel *activeModel = [[EOMApp activeDocument] model];
|
|
if (tv == destEntity_tableView)
|
|
return [[activeModel entities] count];
|
|
else if (tv == srcAttrib_tableView)
|
|
return [[(EOEntity *)[[self selectedObject] entity] attributes] count];
|
|
else if (tv == destAttrib_tableView)
|
|
{
|
|
int selectedRow = [destEntity_tableView selectedRow];
|
|
if (selectedRow == -1 || selectedRow == NSNotFound)
|
|
return 0;
|
|
return [[(EOEntity *)[[activeModel entities] objectAtIndex:[destEntity_tableView selectedRow]] attributes] count];
|
|
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
- (id) tableView:(NSTableView *)tv
|
|
objectValueForTableColumn:(NSTableColumn *)tc
|
|
row:(int)rowIndex
|
|
{
|
|
EOModel *activeModel = [[EOMApp activeDocument] model];
|
|
if (tv == destEntity_tableView)
|
|
{
|
|
return [(EOEntity *)[[activeModel entities] objectAtIndex:rowIndex] name];
|
|
}
|
|
else if (tv == srcAttrib_tableView)
|
|
{
|
|
return [(EOAttribute *)[[(EOEntity *)[[self selectedObject] entity] attributes] objectAtIndex:rowIndex] name];
|
|
}
|
|
else if (tv == destAttrib_tableView)
|
|
{
|
|
int selectedRow = [destEntity_tableView selectedRow];
|
|
if (selectedRow == NSNotFound)
|
|
[destEntity_tableView selectRow:0 byExtendingSelection:NO];
|
|
return [(EOAttribute *)[[(EOEntity *)[[activeModel entities] objectAtIndex:[destEntity_tableView selectedRow]]
|
|
attributes] objectAtIndex:rowIndex] name];
|
|
}
|
|
|
|
return nil;
|
|
}
|
|
|
|
- (void) tableViewSelectionDidChange:(NSNotification *)notif
|
|
{
|
|
NSTableView *tv = [notif object];
|
|
|
|
if (tv == destEntity_tableView)
|
|
{
|
|
[destAttrib_tableView reloadData];
|
|
}
|
|
else if (tv == destAttrib_tableView)
|
|
{
|
|
EOJoin *join = [self joinWithSource:nil destination:[self selectedDestinationAttribute]];
|
|
int row = [self indexOfSourceAttribute:[join sourceAttribute]];
|
|
|
|
if (row != NSNotFound)
|
|
[srcAttrib_tableView selectRow:row byExtendingSelection:NO];
|
|
|
|
[self updateConnectButton];
|
|
}
|
|
else if (tv == srcAttrib_tableView)
|
|
{
|
|
EOJoin *join = [self joinWithSource:[self selectedSourceAttribute] destination:nil];
|
|
int row = [self indexOfDestinationAttribute:[join destinationAttribute]];
|
|
|
|
if (row != NSNotFound)
|
|
[destAttrib_tableView selectRow:row byExtendingSelection:NO];
|
|
|
|
[self updateConnectButton];
|
|
}
|
|
}
|
|
|
|
- (BOOL) tableView:(NSTableView *)tv shouldSelectRow:(int)rowIndex
|
|
{
|
|
if (tv == destEntity_tableView)
|
|
{
|
|
return [[self selectedObject] destinationEntity] == nil;
|
|
}
|
|
else
|
|
{
|
|
return YES;
|
|
}
|
|
}
|
|
|
|
- (void) tableView:(NSTableView *)tv willDisplayCell:(NSCell *)cell forTableColumn:(id)tc
|
|
row:(int)row
|
|
{
|
|
if (tv == destEntity_tableView)
|
|
{
|
|
NSColor *enabledText = [NSColor controlTextColor];
|
|
NSColor *disabledText = [NSColor disabledControlTextColor];
|
|
BOOL flag = ([[self selectedObject] destinationEntity] == nil);
|
|
|
|
[(NSTextFieldCell *)cell setTextColor:(flag == YES) ? enabledText : disabledText];
|
|
}
|
|
}
|
|
|
|
- (void) connectionChanged:(id)sender
|
|
{
|
|
EOAttribute *srcAttrib;
|
|
EOAttribute *destAttrib;
|
|
EOJoin *join;
|
|
EOEntity *destEnt = [[self selectedObject] destinationEntity];
|
|
destAttrib = [self selectedDestinationAttribute];
|
|
srcAttrib = [self selectedSourceAttribute];
|
|
|
|
if ([sender state] == NSOnState)
|
|
{
|
|
join = [[EOJoin alloc] initWithSourceAttribute:srcAttrib destinationAttribute:destAttrib];
|
|
[[self selectedObject] addJoin:join];
|
|
[join release];
|
|
}
|
|
else
|
|
{
|
|
join = [self joinWithSource:srcAttrib destination:destAttrib];
|
|
[[self selectedObject] removeJoin:join];
|
|
}
|
|
|
|
if (destEnt != [[self selectedObject] destinationEntity])
|
|
[destEntity_tableView reloadData];
|
|
}
|
|
|
|
- (void) nameChanged:(id)sender
|
|
{
|
|
NSString *name = [name_textField stringValue];
|
|
|
|
[(EORelationship *)[self selectedObject] setName:name];
|
|
}
|
|
|
|
- (void) semanticChanged:(id)sender
|
|
{
|
|
/* the tag in the nib must match the values in the EOJoinSemantic enum */
|
|
[[self selectedObject] setJoinSemantic: [[sender selectedItem] tag]];
|
|
|
|
}
|
|
|
|
- (void) cardinalityChanged:(id)sender
|
|
{
|
|
/* the tag in the nib for to-one must be 0 to-many 1 */
|
|
[[self selectedObject] setToMany: [[sender selectedCell] tag]];
|
|
}
|
|
|
|
@end
|
|
|