diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPFieldMapperController.h | 32 | ||||
-rw-r--r-- | Source/SPFieldMapperController.m | 106 |
2 files changed, 136 insertions, 2 deletions
diff --git a/Source/SPFieldMapperController.h b/Source/SPFieldMapperController.h index a1d8d4fa..21a34f0e 100644 --- a/Source/SPFieldMapperController.h +++ b/Source/SPFieldMapperController.h @@ -23,10 +23,40 @@ // More info at <http://code.google.com/p/sequel-pro/> #import <Cocoa/Cocoa.h> +#import <MCPKit/MCPKit.h> -@interface SPFieldMapperController : NSObject { + +@interface SPFieldMapperController : NSWindowController { + + IBOutlet id fieldMapperView; + IBOutlet id fieldMapperTableView; + IBOutlet id tableTargetPopup; + IBOutlet id fileSourcePath; + IBOutlet id importMethodPopup; + IBOutlet id rowUpButton; + IBOutlet id rowDownButton; + IBOutlet id recordCountLabel; + + id theDelegate; + + NSInteger fieldMappingCurrentRow; + NSArray *fieldMappingImportArray; + NSArray *fieldMappingArray; + + BOOL fieldMappingImportArrayIsPreview; + + MCPConnection *mySQLConnection; } +- (id)initWithDelegate:(id)managerDelegate; + +- (void)setConnection:(MCPConnection *)theConnection; + +// IBAction methods +- (IBAction)changeTableTarget:(id)sender; +- (IBAction)changeImportMethod:(id)sender; +- (IBAction)stepRow:(id)sender; + @end diff --git a/Source/SPFieldMapperController.m b/Source/SPFieldMapperController.m index a5729905..70a4b049 100644 --- a/Source/SPFieldMapperController.m +++ b/Source/SPFieldMapperController.m @@ -24,8 +24,112 @@ // #import "SPFieldMapperController.h" - +#import "SPTableData.h" @implementation SPFieldMapperController +#pragma mark - +#pragma mark Initialization + + +/** + * Initialize the field mapper + */ +- (id)initWithDelegate:(id)managerDelegate +{ + if ((self = [super initWithWindowNibName:@"DataMigrationDialog"])) { + + fieldMappingCurrentRow = 0; + if(managerDelegate == nil) { + NSBeep(); + NSLog(@"FieldMapperController was called without a delegate."); + return nil; + } + theDelegate = managerDelegate; + + } + + return self; +} + +- (void)awakeFromNib +{ + +} + +/* + * Set the connection for use. + * Called by the connect sheet methods. + */ +- (void)setConnection:(MCPConnection *)theConnection +{ + mySQLConnection = theConnection; + [mySQLConnection retain]; +} + +- (void)dealloc +{ + if (mySQLConnection) [mySQLConnection release]; + [super dealloc]; +} + +#pragma mark - +#pragma mark IBAction methods + +- (IBAction)changeTableTarget:(id)sender +{ + + // Remove all the current columns + // [fieldMappingTableColumnNames removeAllObjects]; + + // Retrieve the information for the newly selected table using a SPTableData instance + SPTableData *selectedTableData = [[SPTableData alloc] init]; + [selectedTableData setConnection:mySQLConnection]; + NSDictionary *tableDetails = [selectedTableData informationForTable:[tableTargetPopup titleOfSelectedItem]]; + if (tableDetails) { + // for (NSDictionary *column in [tableDetails objectForKey:@"columns"]) { + // [fieldMappingTableColumnNames addObject:[NSString stringWithString:[column objectForKey:@"name"]]]; + // } + } + [selectedTableData release]; + + // Update the table view + fieldMappingCurrentRow = 0; + if (fieldMappingArray) [fieldMappingArray release], fieldMappingArray = nil; + // [self setupFieldMappingArray]; + [rowDownButton setEnabled:NO]; + [rowUpButton setEnabled:([fieldMappingImportArray count] > 1)]; + [recordCountLabel setStringValue:[NSString stringWithFormat:@"%ld of %@%lu records", (long)(fieldMappingCurrentRow+1), fieldMappingImportArrayIsPreview?@"first ":@"", (unsigned long)[fieldMappingImportArray count]]]; + + // [self updateFieldMappingButtonCell]; + [fieldMapperTableView reloadData]; +} + +- (IBAction)changeImportMethod:(id)sender +{ + +} + +/* + * Displays next/previous row in fieldMapping tableView + */ +- (IBAction)stepRow:(id)sender +{ + if ( [sender tag] == 0 ) { + fieldMappingCurrentRow--; + } else { + fieldMappingCurrentRow++; + } + // [self updateFieldMappingButtonCell]; + + [fieldMapperTableView reloadData]; + + [recordCountLabel setStringValue:[NSString stringWithFormat:@"%ld of %@%lu records", (long)(fieldMappingCurrentRow+1), fieldMappingImportArrayIsPreview?@"first ":@"", (unsigned long)[fieldMappingImportArray count]]]; + + // enable/disable buttons + [rowDownButton setEnabled:(fieldMappingCurrentRow != 0)]; + [rowUpButton setEnabled:(fieldMappingCurrentRow != ([fieldMappingImportArray count]-1))]; +} + + @end |