aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPFieldMapperController.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-02-18 12:54:38 +0000
committerBibiko <bibiko@eva.mpg.de>2010-02-18 12:54:38 +0000
commit1bde8b65c0213bcf0514c69f1b8b70a00971b573 (patch)
treeb4a56556179011242f9309f8df1b21355bf4c11b /Source/SPFieldMapperController.m
parent299e8821edf9a1705a556c482a2a0ea4d6f9a0a8 (diff)
downloadsequelpro-1bde8b65c0213bcf0514c69f1b8b70a00971b573.tar.gz
sequelpro-1bde8b65c0213bcf0514c69f1b8b70a00971b573.tar.bz2
sequelpro-1bde8b65c0213bcf0514c69f1b8b70a00971b573.zip
• CSV Import Field Mapper
- allow to define a list of global variables (incl. a true NULL value) - such a global variable will be inserted into the mapped table target field for all rows imported
Diffstat (limited to 'Source/SPFieldMapperController.m')
-rw-r--r--Source/SPFieldMapperController.m43
1 files changed, 41 insertions, 2 deletions
diff --git a/Source/SPFieldMapperController.m b/Source/SPFieldMapperController.m
index 4313dc59..7ecdb8f0 100644
--- a/Source/SPFieldMapperController.m
+++ b/Source/SPFieldMapperController.m
@@ -105,6 +105,7 @@
[fieldMapperTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:NO];
[removeGlobalValueButton setEnabled:([globalValuesTableView numberOfSelectedRows] > 0)];
+ [insertNULLValueButton setEnabled:([globalValuesTableView numberOfSelectedRows] == 1)];
[self updateFieldNameAlignment];
}
@@ -175,6 +176,11 @@
return fieldMappingArray;
}
+- (NSArray*)fieldMappingGlobalValueArray
+{
+ return fieldMappingGlobalValues;
+}
+
- (NSArray*)fieldMappingTableColumnNames
{
return fieldMappingTableColumnNames;
@@ -377,6 +383,18 @@
[[globalValuesSheet window] makeFirstResponder:globalValuesTableView];
[removeGlobalValueButton setEnabled:([globalValuesTableView numberOfSelectedRows] > 0)];
+ [insertNULLValueButton setEnabled:([globalValuesTableView numberOfSelectedRows] == 1)];
+}
+
+- (IBAction)insertNULLValue:(id)sender;
+{
+ if([globalValuesTableView numberOfSelectedRows] != 1) return;
+
+ [globalValuesTableView abortEditing];
+ [fieldMappingGlobalValues replaceObjectAtIndex:[globalValuesTableView selectedRow]+numberOfImportColumns withObject:[NSNull null]];
+
+ [globalValuesTableView reloadData];
+
}
- (IBAction)closeGlobalValuesSheet:(id)sender
@@ -396,6 +414,7 @@
- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
[[globalValuesSheet window] orderOut:self];
+ [self updateFieldMappingButtonCell];
}
- (void)matchHeaderNames
@@ -466,15 +485,27 @@
- (void)updateFieldMappingButtonCell
{
NSInteger i;
-
+ if([fieldMappingImportArray count] == 0) return;
[fieldMappingButtonOptions setArray:[fieldMappingImportArray objectAtIndex:fieldMappingCurrentRow]];
for (i = 0; i < [fieldMappingButtonOptions count]; i++) {
if ([[fieldMappingButtonOptions objectAtIndex:i] isNSNull]) {
- [fieldMappingButtonOptions replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%i. %@", i+1, [prefs objectForKey:SPNullValue]]];
+ [fieldMappingButtonOptions replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%i. <%@>", i+1, [prefs objectForKey:SPNullValue]]];
} else {
[fieldMappingButtonOptions replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%i. %@", i+1, NSArrayObjectAtIndex(fieldMappingButtonOptions, i)]];
}
}
+
+ // Add global values if any
+ if([fieldMappingGlobalValues count]>numberOfImportColumns)
+ for(i; i < [fieldMappingGlobalValues count]; i++) {
+ if ([NSArrayObjectAtIndex(fieldMappingGlobalValues, i) isNSNull])
+ [fieldMappingButtonOptions addObject:[NSString stringWithFormat:@"%i. <%@>", i+1, [prefs objectForKey:SPNullValue]]];
+ else
+ [fieldMappingButtonOptions addObject:[NSString stringWithFormat:@"%i. %@", i+1, NSArrayObjectAtIndex(fieldMappingGlobalValues, i)]];
+ }
+
+ [fieldMapperTableView reloadData];
+
}
/*
@@ -565,13 +596,20 @@
if(aTableView == fieldMapperTableView) {
if([[aTableColumn identifier] isEqualToString:@"import_value"] && [importFieldNamesHeaderSwitch state] == NSOnState) {
+
if ([fieldMappingOperatorArray objectAtIndex:rowIndex] == doNotImport) return @"";
+
+ if([NSArrayObjectAtIndex(fieldMappingArray, rowIndex) integerValue]>=[NSArrayObjectAtIndex(fieldMappingImportArray, 0) count])
+ return [NSString stringWithFormat:@"%@: %@", NSLocalizedString(@"Global value", @"global value"),
+ NSArrayObjectAtIndex(fieldMappingGlobalValues, [NSArrayObjectAtIndex(fieldMappingArray, rowIndex) integerValue])];
+
if(fieldMappingCurrentRow)
return [NSString stringWithFormat:@"%@: %@",
[NSArrayObjectAtIndex(NSArrayObjectAtIndex(fieldMappingImportArray, 0), [NSArrayObjectAtIndex(fieldMappingArray, rowIndex) integerValue]) description],
[NSArrayObjectAtIndex(NSArrayObjectAtIndex(fieldMappingImportArray, fieldMappingCurrentRow), [NSArrayObjectAtIndex(fieldMappingArray, rowIndex) integerValue]) description]];
else
return [NSArrayObjectAtIndex(NSArrayObjectAtIndex(fieldMappingImportArray, 0), [NSArrayObjectAtIndex(fieldMappingArray, rowIndex) integerValue]) description];
+
}
else if([[aTableColumn identifier] isEqualToString:@"import_value"] && [importFieldNamesHeaderSwitch state] == NSOffState)
return [NSArrayObjectAtIndex(NSArrayObjectAtIndex(fieldMappingImportArray, fieldMappingCurrentRow), [NSArrayObjectAtIndex(fieldMappingArray, rowIndex) integerValue]) description];
@@ -680,6 +718,7 @@
if (object == globalValuesTableView) {
[removeGlobalValueButton setEnabled:([globalValuesTableView numberOfSelectedRows] > 0)];
+ [insertNULLValueButton setEnabled:([globalValuesTableView numberOfSelectedRows] == 1)];
}
}