From 6e420c763f8f68a42c7f944c3c3e951e46bc7b33 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Tue, 2 Feb 2010 15:25:36 +0000 Subject: =?UTF-8?q?=E2=80=A2=20further=20work=20on=20SPFieldMapperControll?= =?UTF-8?q?er?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interfaces/English.lproj/DataMigrationDialog.xib | 230 ++++++++++++++++++++--- Source/SPFieldMapperController.h | 32 +++- Source/SPFieldMapperController.m | 106 ++++++++++- 3 files changed, 342 insertions(+), 26 deletions(-) diff --git a/Interfaces/English.lproj/DataMigrationDialog.xib b/Interfaces/English.lproj/DataMigrationDialog.xib index ada36b1a..cbf5312e 100644 --- a/Interfaces/English.lproj/DataMigrationDialog.xib +++ b/Interfaces/English.lproj/DataMigrationDialog.xib @@ -12,7 +12,7 @@ YES - + YES @@ -30,7 +30,7 @@ YES - TableDocument + SPFieldMapperController FirstResponder @@ -174,7 +174,7 @@ YES - value + import_value 216 15 1000 @@ -250,7 +250,7 @@ - field + target_field 220 10 3.4028234663852886e+38 @@ -344,7 +344,7 @@ 257 _doScroller: - 0.037825059145689011 + 0.035674519836902618 0.99047619104385376 @@ -537,21 +537,22 @@ 400 75 - + - INSERT + UPDATE 2147483647 1 - + NSImage NSMenuCheckmark - + NSImage NSMenuMixedState _popUpItemAction: + 2 YES @@ -559,31 +560,31 @@ OtherViews YES - - + - REPLACE + INSERT 2147483647 - - + + _popUpItemAction: - 1 - + - UPDATE + REPLACE 2147483647 - - + + _popUpItemAction: - 2 + 1 + + 2 1 YES YES @@ -707,6 +708,134 @@ YES + + + tableTargetPopup + + + + 58 + + + + changeTableTarget: + + + + 59 + + + + fileSourcePath + + + + 60 + + + + importMethodPopup + + + + 61 + + + + changeImportMethod: + + + + 62 + + + + recordCountLabel + + + + 65 + + + + rowUpButton + + + + 66 + + + + rowDownButton + + + + 67 + + + + stepRow: + + + + 68 + + + + stepRow: + + + + 69 + + + + fieldMapperTableView + + + + 70 + + + + delegate + + + + 71 + + + + dataSource + + + + 72 + + + + fieldMapperView + + + + 73 + + + + closeSheet: + + + + 74 + + + + closeSheet: + + + + 75 + @@ -1152,9 +1281,9 @@ YES com.apple.InterfaceBuilder.CocoaPlugin - {{503, 302}, {465, 311}} + {{210, 424}, {465, 311}} com.apple.InterfaceBuilder.CocoaPlugin - {{503, 302}, {465, 311}} + {{210, 424}, {465, 311}} {{387, 725}, {432, 282}} @@ -1183,7 +1312,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{234, 355}, {126, 54}} + {{302, 438}, {126, 54}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1237,7 +1366,7 @@ - 57 + 75 @@ -1426,6 +1555,59 @@ + + YES + + SPFieldMapperController + NSWindowController + + YES + + YES + changeImportMethod: + changeTableTarget: + closeSheet: + stepRow: + + + YES + id + id + id + id + + + + YES + + YES + fieldMapperTableView + fieldMapperView + fileSourcePath + importMethodPopup + recordCountLabel + rowDownButton + rowUpButton + tableTargetPopup + + + YES + id + id + id + id + id + id + id + id + + + + IBDocumentRelativeSource + ../../Source/SPFieldMapperController.h + + + 0 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 #import +#import -@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 -- cgit v1.2.3