libs-gdl2/DBModeler/ModelerAttributeEditor.m
ratmice e0c9a227ef * DBModeler/AdaptorsPanel.m (-init): Add parenthesis around
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
2005-07-09 02:07:42 +00:00

255 lines
7.8 KiB
Objective-C

/**
ModelerAttributeEditor.m
Author: Matt Rice <ratmice@yahoo.com>
Date: Apr 2005
This file is part of DBModeler.
<license>
DBModeler is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
DBModeler is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DBModeler; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
</license>
**/
#include "DefaultColumnProvider.h"
#include "ModelerAttributeEditor.h"
#include "ModelerEntityEditor.h"
#include "KVDataSource.h"
#include <AppKit/NSImage.h>
#include <AppKit/NSTableView.h>
#include <AppKit/NSTableColumn.h>
#include <AppKit/NSPopUpButton.h>
#include <AppKit/NSPopUpButtonCell.h>
#include <AppKit/NSScrollView.h>
#include <AppKit/NSSplitView.h>
#include <EOAccess/EOEntity.h>
#include <EOModeler/EOModelerDocument.h>
#include <EOModeler/EOModelerApp.h>
#include <EOInterface/EODisplayGroup.h>
#include <Foundation/NSRunLoop.h>
@interface NSArray (EOMAdditions)
- (id) firstSelectionOfClass:(Class) aClass;
@end
@implementation ModelerAttributeEditor
- (id) initWithParentEditor:(id)parentEditor
{
NSScrollView *scrollView;
KVDataSource *wds1, *wds2;
NSPopUpButton *cornerView;
NSMenuItem *mi = [[NSMenuItem alloc] initWithTitle:@"+" action:(SEL)nil keyEquivalent:@""];
self = [super initWithParentEditor:parentEditor];
[DefaultColumnProvider class];
_mainView = [[NSSplitView alloc] initWithFrame:NSMakeRect(0,0,100,100)];
/* setup the attributes table view */
scrollView = [[NSScrollView alloc] initWithFrame:NSMakeRect(0,0,100,100)];
_attributes_tableView = [[NSTableView alloc] initWithFrame:NSMakeRect(0,0,100,100)];
[_attributes_tableView setAutoresizesAllColumnsToFit:YES];
[scrollView setBorderType: NSBezelBorder];
[scrollView setHasHorizontalScroller:YES];
[scrollView setHasVerticalScroller:YES];
[scrollView setDocumentView:_attributes_tableView];
RELEASE(_attributes_tableView);
[_mainView addSubview:scrollView];
RELEASE(scrollView);
/* and the tableViews corner view */
cornerView = [[NSPopUpButton alloc] initWithFrame:[[_attributes_tableView cornerView] bounds] pullsDown:YES];
[[cornerView cell] setArrowPosition:NSPopUpNoArrow];
[cornerView setTitle:@"+"];
[cornerView setPreferredEdge:NSMinYEdge];
[[cornerView cell] setUsesItemFromMenu:NO];
[[cornerView cell] setShowsFirstResponder:NO];
[[cornerView cell] setMenuItem:mi];
[_attributes_tableView setCornerView:cornerView];
RELEASE(cornerView);
/* and the attributes tableview's display group */
wds1 = [[KVDataSource alloc] initWithClassDescription:nil
editingContext:[[self document] editingContext]];
[wds1 setKey:@"attributes"];
_attributes_dg = [[EODisplayGroup alloc] init];
[_attributes_dg setDataSource:wds1];
RELEASE(wds1);
[_attributes_dg setFetchesOnLoad:YES];
[_attributes_dg setDelegate:self];
[self setupCornerView:cornerView
tableView:_attributes_tableView
displayGroup:_attributes_dg
forClass:[EOAttribute class]];
[self addDefaultTableColumnsForTableView:_attributes_tableView
displayGroup:_attributes_dg];
/* setup the relationships table view */
scrollView = [[NSScrollView alloc] initWithFrame:NSMakeRect(0,0,100,100)];
[scrollView setBorderType: NSBezelBorder];
[scrollView setHasHorizontalScroller:YES];
[scrollView setHasVerticalScroller:YES];
_relationships_tableView = [[NSTableView alloc] initWithFrame:NSMakeRect(0,0,100,100)];
[_relationships_tableView setAutoresizesAllColumnsToFit:YES];
[scrollView setDocumentView:_relationships_tableView];
RELEASE(_relationships_tableView);
[_mainView addSubview:scrollView];
RELEASE(scrollView);
/* and the tableViews corner view */
cornerView = [[NSPopUpButton alloc] initWithFrame:[[_relationships_tableView cornerView] bounds] pullsDown:YES];
[cornerView setPreferredEdge:NSMinYEdge];
[[cornerView cell] setArrowPosition:NSPopUpNoArrow];
[cornerView setTitle:@"+"];
[[cornerView cell] setUsesItemFromMenu:NO];
[[cornerView cell] setShowsFirstResponder:NO];
[[cornerView cell] setMenuItem:mi];
[_relationships_tableView setCornerView:cornerView];
RELEASE(cornerView);
/* and the relationships display group. */
wds2 = [[KVDataSource alloc] initWithClassDescription:nil
editingContext:[[self document] editingContext]];
[wds2 setKey:@"relationships"];
_relationships_dg = [[EODisplayGroup alloc] init];
[_relationships_dg setDataSource:wds2];
RELEASE(wds2);
[_relationships_dg setFetchesOnLoad:YES];
[_relationships_dg setDelegate:self];
[self setupCornerView:cornerView
tableView:_relationships_tableView
displayGroup:_relationships_dg
forClass:[EORelationship class]];
[self addDefaultTableColumnsForTableView:_relationships_tableView
displayGroup:_relationships_dg];
return self;
}
- (void) dealloc
{
if (_entityToObserve)
[EOObserverCenter removeObserver:self forObject:_entityToObserve];
if (_attributeToObserve)
[EOObserverCenter removeObserver:self forObject:_attributeToObserve];
RELEASE(_mainView);
RELEASE(_relationships_dg);
RELEASE(_attributes_dg);
}
- (NSView *)mainView
{
return _mainView;
}
- (BOOL) canSupportCurrentSelection
{
id selection = [self selectionWithinViewedObject];
BOOL flag;
if ([selection count] == 0)
return NO;
selection = [selection objectAtIndex:0];
flag = ([selection isKindOfClass:[EOEntity class]]
|| [selection isKindOfClass:[EOAttribute class]]
|| [selection isKindOfClass:[EORelationship class]]);
return flag;
}
- (void) activate
{
if (_entityToObserve)
[EOObserverCenter removeObserver:self forObject:_entityToObserve];
_entityToObserve = [[self selectionPath] firstSelectionOfClass:[EOEntity class]];
[EOObserverCenter addObserver:self forObject:_entityToObserve];
[(KVDataSource *)[_attributes_dg dataSource] setDataObject: _entityToObserve];
[(KVDataSource *)[_relationships_dg dataSource] setDataObject: _entityToObserve];
[_attributes_dg fetch];
[_relationships_dg fetch];
}
- (NSArray *) friendEditorClasses
{
return [NSArray arrayWithObjects: [ModelerEntityEditor class], nil];
}
- (void) objectWillChange:(id)sender
{
[[NSRunLoop currentRunLoop] performSelector:@selector(needToFetch:)
target:self
argument:nil
order:999
modes:[NSArray arrayWithObject:NSDefaultRunLoopMode]];
}
- (void) needToFetch:(id)arg
{
[_attributes_dg fetch];
[_relationships_dg fetch];
}
- (NSArray *)defaultColumnNamesForClass:(Class)aClass
{
NSArray *colNames = [super defaultColumnNamesForClass:aClass];
if (colNames == nil || [colNames count] == 0)
{
if (aClass == [EOAttribute class])
return DefaultAttributeColumns;
else if (aClass == [EORelationship class])
return DefaultRelationshipColumns;
else
return nil;
}
return colNames;
}
- (void) displayGroupDidChangeSelection:(EODisplayGroup *)displayGroup
{
NSArray *currentSelection = [_parentEditor selectionWithinViewedObject];
id theSelection;
int c = [currentSelection count];
if (!c)
return;
else
theSelection = [currentSelection objectAtIndex:0];
if ([theSelection isKindOfClass:[EOEntity class]])
{
NSArray *vop;
vop = [_parentEditor viewedObjectPath];
[self setViewedObjectPath: [vop arrayByAddingObject:theSelection]];
}
[self setSelectionWithinViewedObject: [displayGroup selectedObjects]];
}
@end