Skip to content

Commit

Permalink
update unique key after editing
Browse files Browse the repository at this point in the history
  • Loading branch information
drjokepu committed Jun 6, 2013
1 parent aa54006 commit 079b195
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
Expand Up @@ -449,8 +449,16 @@ -(void)openUniqueKeyEditorSheet:(BOOL)isPrimaryKey withConstraint:(PGConstraint*
PGUniqueKeyEditorWindowController *uniqueKeyEditorSheet = [[PGUniqueKeyEditorWindowController alloc] init];
uniqueKeyEditorSheet.isPrimaryKey = isPrimaryKey;
uniqueKeyEditorSheet.availableColumns = self.tableColumns;
if (constraint != nil)

if (constraint == nil)
{
uniqueKeyEditorSheet.constraintEditorAction = PGEditorAdd;
}
else
{
[uniqueKeyEditorSheet useConstraint:constraint];
uniqueKeyEditorSheet.constraintEditorAction = PGEditorUpdate;
}

[[NSApplication sharedApplication] beginSheet:[uniqueKeyEditorSheet window]
modalForWindow:[self window]
Expand All @@ -465,7 +473,14 @@ -(void)didEndUniqueKeyEditorSheet:(NSWindow *)sheet returnCode:(NSInteger)return
{
if (returnCode == 1)
{
[self.tableConstraints addObject:[self.uniqueKeyEditorSheet getConstraint]];
if (self.uniqueKeyEditorSheet.constraintEditorAction == PGEditorAdd)
{
[self.tableConstraints addObject:[self.uniqueKeyEditorSheet getConstraint]];
}
else
{
[self.uniqueKeyEditorSheet updateConstraint];
}
[self.constraintsTableView reloadData];
}

Expand Down
Expand Up @@ -12,14 +12,15 @@
@class PGConstraint;
@interface PGUniqueKeyEditorWindowController : NSWindowController <NSTableViewDataSource, NSTableViewDelegate>

@property (nonatomic, assign) PGEditorAction columnEditorAction;
@property (nonatomic, assign) PGEditorAction constraintEditorAction;
@property (nonatomic, assign) BOOL isPrimaryKey;
@property (nonatomic, strong) NSArray *availableColumns;

-(IBAction)didClickCancel:(id)sender;
-(IBAction)didClickAction:(id)sender;

-(PGConstraint*)getConstraint;
-(void)updateConstraint;
-(void)useConstraint:(PGConstraint*)constraint;

@end
Expand Up @@ -31,7 +31,7 @@ @interface PGUniqueKeyEditorWindowController ()
@end

@implementation PGUniqueKeyEditorWindowController
@synthesize isPrimaryKey, availableColumns, keyColumns, initialConstraint, columnEditorAction;
@synthesize isPrimaryKey, availableColumns, keyColumns, initialConstraint, constraintEditorAction;

-(NSString *)windowNibName
{
Expand All @@ -41,7 +41,7 @@ -(NSString *)windowNibName
- (void)windowDidLoad
{
[super windowDidLoad];
switch (columnEditorAction)
switch (constraintEditorAction)
{
case PGEditorAdd:
[self.actionButton setTitle:@"Add"];
Expand Down Expand Up @@ -217,13 +217,25 @@ -(void)didClickColumnMoveDown:(id)sender
{
[self.keyColumns swapObjectAtIndex:selectedRow withObjectAtIndex:selectedRow + 1];
[self.keyColumnsTableView reloadData];
[self.keyColumnsTableView selectRowIndexes:[[NSIndexSet alloc] initWithIndex:selectedRow + 1] byExtendingSelection:NO];
[self.keyColumnsTableView selectRowIndexes:[[NSIndexSet alloc] initWithIndex:selectedRow + 1]
byExtendingSelection:NO];
}
}

-(PGConstraint *)getConstraint
{
PGConstraint *constraint = [[PGConstraint alloc] init];
[self populateConstraintWithDetails:constraint];
return constraint;
}

-(void)updateConstraint
{
[self populateConstraintWithDetails:initialConstraint];
}

-(void)populateConstraintWithDetails:(PGConstraint *)constraint
{
constraint.type = isPrimaryKey ? PGConstraintTypePrimaryKey : PGConstraintTypeUniqueKey;
constraint.name = [self.constraintNameTextField stringValue];

Expand All @@ -236,8 +248,6 @@ -(PGConstraint *)getConstraint
[constraintColumns addObject:constraintColumn];
}
constraint.columns = constraintColumns;

return constraint;
}

-(void)useConstraint:(PGConstraint *)constraint
Expand Down

0 comments on commit 079b195

Please sign in to comment.