diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-03-03 19:49:20 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-03-03 19:49:20 +0000 |
commit | a10a86f1326aff47e4b045c987ec8159181ad4ff (patch) | |
tree | 2bb04ee1644b7f582f561908d47ce29d4482b549 /Source | |
parent | 0c303c40066f65fa0739f43b46aecca1172d2ddc (diff) | |
download | sequelpro-a10a86f1326aff47e4b045c987ec8159181ad4ff.tar.gz sequelpro-a10a86f1326aff47e4b045c987ec8159181ad4ff.tar.bz2 sequelpro-a10a86f1326aff47e4b045c987ec8159181ad4ff.zip |
• CSV Import Field Mapper
- further work on UPDATE (not yet activated)
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPFieldMapperController.h | 3 | ||||
-rw-r--r-- | Source/SPFieldMapperController.m | 44 | ||||
-rw-r--r-- | Source/TableDump.h | 1 | ||||
-rw-r--r-- | Source/TableDump.m | 1 |
4 files changed, 46 insertions, 3 deletions
diff --git a/Source/SPFieldMapperController.h b/Source/SPFieldMapperController.h index e7f0aa18..6dc7ffe8 100644 --- a/Source/SPFieldMapperController.h +++ b/Source/SPFieldMapperController.h @@ -37,6 +37,7 @@ IBOutlet id rowDownButton; IBOutlet id recordCountLabel; IBOutlet id importFieldNamesHeaderSwitch; + IBOutlet id addRemainingDataSwitch; IBOutlet id importButton; IBOutlet NSPopUpButton *alignByPopup; IBOutlet NSMenuItem *matchingNameMenuItem; @@ -102,6 +103,7 @@ - (NSArray*)fieldMappingTableColumnNames; - (NSArray*)fieldMappingGlobalValueArray; - (BOOL)importFieldNamesHeader; +- (BOOL)insertRemainingRowsAfterUpdate; - (NSString*)onupdateString; - (NSString*)importHeaderString; @@ -130,5 +132,6 @@ - (void)updateFieldMappingButtonCell; - (void)updateFieldMappingOperatorOptions; - (void)updateFieldNameAlignment; +- (void)validateImportButton; @end diff --git a/Source/SPFieldMapperController.m b/Source/SPFieldMapperController.m index 514d031a..8f13b6bb 100644 --- a/Source/SPFieldMapperController.m +++ b/Source/SPFieldMapperController.m @@ -97,6 +97,8 @@ } [importFieldNamesHeaderSwitch setState:importFieldNamesHeader]; + [addRemainingDataSwitch setHidden:YES]; + [addRemainingDataSwitch setState:NSOffState]; [self changeHasHeaderCheckbox:self]; [self changeTableTarget:self]; @@ -193,6 +195,11 @@ return ([importFieldNamesHeaderSwitch state] == NSOnState)?YES:NO; } +- (BOOL)insertRemainingRowsAfterUpdate +{ + return ([addRemainingDataSwitch state] == NSOnState)?YES:NO; +} + - (NSString*)importHeaderString { if([[importMethodPopup titleOfSelectedItem] isEqualToString:@"INSERT"]) { @@ -310,17 +317,23 @@ - (IBAction)changeImportMethod:(id)sender { NSInteger i; + // If operator is set to = for UPDATE method replace it by doNotImport if(![[importMethodPopup titleOfSelectedItem] isEqualToString:@"UPDATE"]) { [advancedButton setEnabled:YES]; + [addRemainingDataSwitch setHidden:YES]; for(i=0; i<[fieldMappingTableColumnNames count]; i++) { - if([fieldMappingOperatorArray objectAtIndex:i] == isEqual) + if([fieldMappingOperatorArray objectAtIndex:i] == isEqual) { [fieldMappingOperatorArray replaceObjectAtIndex:i withObject:doNotImport]; + } } } else { [advancedButton setEnabled:NO]; + [addRemainingDataSwitch setHidden:NO]; } + [self validateImportButton]; + [self updateFieldMappingOperatorOptions]; [fieldMapperTableView reloadData]; } @@ -667,6 +680,22 @@ } +- (void)validateImportButton +{ + BOOL enableImportButton = YES; + if([[self selectedImportMethod] isEqualToString:@"UPDATE"]) { + enableImportButton = NO; + for(id op in fieldMappingOperatorArray) { + if(op == isEqual) { + enableImportButton = YES; + break; + } + } + enableImportButton = NO; // TODO HansJB WIP + } + [importButton setEnabled:enableImportButton]; +} + #pragma mark - #pragma mark Table view datasource methods @@ -699,6 +728,7 @@ [fieldMappingOperatorArray removeAllObjects]; for(i=0; i < [fieldMappingTableColumnNames count]; i++) [fieldMappingOperatorArray addObject:globalValue]; + [self validateImportButton]; [fieldMapperTableView reloadData]; } } @@ -786,10 +816,11 @@ [c addItemWithTitle:[NSString stringWithFormat:@"DEFAULT: %@", [fieldMappingTableDefaultValues objectAtIndex:rowIndex]]]; [[m itemAtIndex:[c numberOfItems]-1] setEnabled:NO]; - // If user doesn't want to import it show its DEFAULT value otherwise hide it. + // If user doesn't want to import it show its DEFAULT value if not + // UPDATE was chosen otherwise hide it. if([fieldMappingOperatorArray objectAtIndex:rowIndex] != doNotImport) return [fieldMappingArray objectAtIndex:rowIndex]; - else + else if(![[self selectedImportMethod] isEqualToString:@"UPDATE"]) return [NSNumber numberWithInteger:[c numberOfItems]-1]; } @@ -854,6 +885,9 @@ [aTableView performSelector:@selector(reloadData) withObject:nil afterDelay:0.0]; [self addGlobalSourceVariable:nil]; } + + [self validateImportButton]; + return; } @@ -866,6 +900,9 @@ // If user _changed_ the csv file column set the operator to doImport if([(NSNumber*)anObject integerValue] > -1) [fieldMappingOperatorArray replaceObjectAtIndex:rowIndex withObject:doImport]; + + [self validateImportButton]; + } else if ([[aTableColumn identifier] isEqualToString:@"operator"]) { @@ -876,6 +913,7 @@ if(anObject == doNotImport) lastDisabledCSVFieldcolumn = [fieldMappingArray objectAtIndex:rowIndex]; [fieldMappingOperatorArray replaceObjectAtIndex:rowIndex withObject:anObject]; } + [self validateImportButton]; } // Refresh table [aTableView performSelector:@selector(reloadData) withObject:nil afterDelay:0.01]; diff --git a/Source/TableDump.h b/Source/TableDump.h index 14149aa5..3855fe57 100644 --- a/Source/TableDump.h +++ b/Source/TableDump.h @@ -115,6 +115,7 @@ typedef enum _SPExportModes { NSInteger fieldMapperSheetStatus; BOOL fieldMappingArrayHasGlobalVariables; BOOL csvImportMethodHasTail; + BOOL insertRemainingRowsAfterUpdate; NSUInteger exportMode; NSUserDefaults *prefs; diff --git a/Source/TableDump.m b/Source/TableDump.m index 4d6e93ef..542d52ba 100644 --- a/Source/TableDump.m +++ b/Source/TableDump.m @@ -1199,6 +1199,7 @@ csvImportHeaderString = [[NSString stringWithString:[fieldMapperController importHeaderString]] retain]; csvImportTailString = [[NSString stringWithString:[fieldMapperController onupdateString]] retain]; csvImportMethodHasTail = ([csvImportTailString length] == 0) ? NO : YES; + insertRemainingRowsAfterUpdate = [fieldMapperController insertRemainingRowsAfterUpdate]; if([fieldMappingImportArray count] && [fieldMappingGlobalValueArray count] > [NSArrayObjectAtIndex(fieldMappingImportArray,0) count]) fieldMappingArrayHasGlobalVariables = YES; |