diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPFieldMapperController.h | 9 | ||||
-rw-r--r-- | Source/SPFieldMapperController.m | 234 |
2 files changed, 131 insertions, 112 deletions
diff --git a/Source/SPFieldMapperController.h b/Source/SPFieldMapperController.h index a12adcb8..76b65c49 100644 --- a/Source/SPFieldMapperController.h +++ b/Source/SPFieldMapperController.h @@ -33,7 +33,7 @@ @class SPTablesList; @class SPMySQLConnection; -@interface SPFieldMapperController : NSWindowController <NSTokenFieldCellDelegate> +@interface SPFieldMapperController : NSWindowController <NSTokenFieldCellDelegate, NSMenuDelegate> { IBOutlet SPTableView *fieldMapperTableView; IBOutlet NSScrollView *fieldMapperTableScrollView; @@ -110,9 +110,9 @@ NSMutableArray *fieldMappingTableDefaultValues; NSMutableArray *defaultFieldTypesForComboBox; - NSNumber *doImport; - NSNumber *doNotImport; - NSNumber *isEqual; + NSNumber *doImportKey; + NSNumber *doNotImportKey; + NSNumber *isEqualKey; NSString *doImportString; NSString *doNotImportString; NSString *isEqualString; @@ -135,6 +135,7 @@ NSUInteger windowMinHeigth; NSInteger numberOfImportColumns; NSInteger fieldMappingCurrentRow; + NSInteger firstDefaultItemOffset; BOOL fieldMappingImportArrayIsPreview; BOOL importFieldNamesHeader; diff --git a/Source/SPFieldMapperController.m b/Source/SPFieldMapperController.m index a79c8a40..2fcf4c9e 100644 --- a/Source/SPFieldMapperController.m +++ b/Source/SPFieldMapperController.m @@ -53,6 +53,10 @@ static NSString *SPTableViewSqlColumnID = @"sql"; static NSUInteger SPSourceColumnTypeText = 0; static NSUInteger SPSourceColumnTypeInteger = 1; +@interface SPFieldMapperController (Private) +- (void)_setupFieldMappingPopUpMenus; +@end + @implementation SPFieldMapperController @synthesize sourcePath; @@ -85,9 +89,9 @@ static NSUInteger SPSourceColumnTypeInteger = 1; lastDisabledCSVFieldcolumn = @0; - doImport = @0; - doNotImport = @1; - isEqual = @2; + doImportKey = @0; + doNotImportKey = @1; + isEqualKey = @2; doImportString = @"―"; doNotImportString = @" "; isEqualString = @"="; @@ -215,20 +219,20 @@ static NSUInteger SPSourceColumnTypeInteger = 1; - (void)dealloc { - if (mySQLConnection) [mySQLConnection release]; - if (sourcePath) [sourcePath release]; - if (fieldMappingTableColumnNames) [fieldMappingTableColumnNames release]; - if (defaultFieldTypesForComboBox) [defaultFieldTypesForComboBox release]; - if (fieldMappingTableTypes) [fieldMappingTableTypes release]; - if (fieldMappingArray) [fieldMappingArray release]; - if (fieldMappingButtonOptions) [fieldMappingButtonOptions release]; - if (fieldMappingOperatorOptions) [fieldMappingOperatorOptions release]; - if (fieldMappingOperatorArray) [fieldMappingOperatorArray release]; - if (fieldMappingGlobalValues) [fieldMappingGlobalValues release]; - if (fieldMappingGlobalValuesSQLMarked) [fieldMappingGlobalValuesSQLMarked release]; - if (fieldMappingTableDefaultValues) [fieldMappingTableDefaultValues release]; - if (primaryKeyFields) [primaryKeyFields release]; - if (toBeEditedRowIndexes) [toBeEditedRowIndexes release]; + if (mySQLConnection) [mySQLConnection release], mySQLConnection = nil; + if (sourcePath) [sourcePath release], sourcePath = nil; + if (fieldMappingTableColumnNames) [fieldMappingTableColumnNames release], fieldMappingTableColumnNames = nil; + if (defaultFieldTypesForComboBox) [defaultFieldTypesForComboBox release], defaultFieldTypesForComboBox = nil; + if (fieldMappingTableTypes) [fieldMappingTableTypes release], fieldMappingTableTypes = nil; + if (fieldMappingArray) [fieldMappingArray release], fieldMappingArray = nil; + if (fieldMappingButtonOptions) [fieldMappingButtonOptions release], fieldMappingButtonOptions = nil; + if (fieldMappingOperatorOptions) [fieldMappingOperatorOptions release], fieldMappingOperatorOptions = nil; + if (fieldMappingOperatorArray) [fieldMappingOperatorArray release], fieldMappingOperatorArray = nil; + if (fieldMappingGlobalValues) [fieldMappingGlobalValues release], fieldMappingGlobalValues = nil; + if (fieldMappingGlobalValuesSQLMarked) [fieldMappingGlobalValuesSQLMarked release], fieldMappingGlobalValuesSQLMarked = nil; + if (fieldMappingTableDefaultValues) [fieldMappingTableDefaultValues release], fieldMappingTableDefaultValues = nil; + if (primaryKeyFields) [primaryKeyFields release], primaryKeyFields = nil; + if (toBeEditedRowIndexes) [toBeEditedRowIndexes release], toBeEditedRowIndexes = nil; [super dealloc]; } @@ -309,7 +313,7 @@ static NSUInteger SPSourceColumnTypeInteger = 1; { NSInteger i = 0; for(id item in fieldMappingArray) { - if([item intValue] >= numberOfImportColumns && NSArrayObjectAtIndex(fieldMappingOperatorArray, i) != doNotImport) + if([item intValue] >= numberOfImportColumns && ![doNotImportKey isEqualToNumber:NSArrayObjectAtIndex(fieldMappingOperatorArray, i)]) return YES; i++; } @@ -455,7 +459,7 @@ static NSUInteger SPSourceColumnTypeInteger = 1; for(columnIndex = 0; columnIndex < numberOfColumns; columnIndex++) { // Skip fields which aren't marked as imported - if ([fieldMappingOperatorArray objectAtIndex:columnIndex] != doImport) { + if (![doImportKey isEqualToNumber:[fieldMappingOperatorArray objectAtIndex:columnIndex]]) { continue; } @@ -610,16 +614,16 @@ static NSUInteger SPSourceColumnTypeInteger = 1; [self updateFieldMappingButtonCell]; [self updateFieldMappingOperatorOptions]; - // Set all operators to doNotImport + // Set all operators to doNotImportKey [fieldMappingOperatorArray removeAllObjects]; for(i=0; i < [fieldMappingTableColumnNames count]; i++) - [fieldMappingOperatorArray addObject:doNotImport]; + [fieldMappingOperatorArray addObject:doNotImportKey]; // Set the first n operators to doImport if([fieldMappingImportArray count]) { NSUInteger possibleImports = ([NSArrayObjectAtIndex(fieldMappingImportArray, 0) count] > [fieldMappingTableColumnNames count]) ? [fieldMappingTableColumnNames count] : [NSArrayObjectAtIndex(fieldMappingImportArray, 0) count]; for(i=0; i < possibleImports; i++) - [fieldMappingOperatorArray replaceObjectAtIndex:i withObject:doImport]; + [fieldMappingOperatorArray replaceObjectAtIndex:i withObject:doImportKey]; } // Disable Import button if no fields are available @@ -638,6 +642,7 @@ static NSUInteger SPSourceColumnTypeInteger = 1; [self updateFieldNameAlignment]; + [self _setupFieldMappingPopUpMenus]; [fieldMapperTableView reloadData]; } @@ -686,12 +691,12 @@ static NSUInteger SPSourceColumnTypeInteger = 1; [advancedBox setHidden:YES]; } - // If operator is set to = for UPDATE method replace it by doNotImport + // If operator is set to = for UPDATE method replace it by doNotImportKey if(![[importMethodPopup titleOfSelectedItem] isEqualToString:@"UPDATE"]) { [advancedButton setEnabled:YES]; for(i=0; i<[fieldMappingTableColumnNames count]; i++) { - if([fieldMappingOperatorArray objectAtIndex:i] == isEqual) { - [fieldMappingOperatorArray replaceObjectAtIndex:i withObject:doNotImport]; + if([isEqualKey isEqualToNumber:[fieldMappingOperatorArray objectAtIndex:i]]) { + [fieldMappingOperatorArray replaceObjectAtIndex:i withObject:doNotImportKey]; } } } else { @@ -701,6 +706,8 @@ static NSUInteger SPSourceColumnTypeInteger = 1; [self validateImportButton]; [self updateFieldMappingOperatorOptions]; + + [self _setupFieldMappingPopUpMenus]; [fieldMapperTableView reloadData]; } @@ -715,23 +722,23 @@ static NSUInteger SPSourceColumnTypeInteger = 1; if(possibleImports < 1) return; - // Set all operators to doNotImport + // Set all operators to doNotImportKey [fieldMappingOperatorArray removeAllObjects]; for(i=0; i < [fieldMappingTableColumnNames count]; i++) - [fieldMappingOperatorArray addObject:doNotImport]; + [fieldMappingOperatorArray addObject:doNotImportKey]; switch([[alignByPopup selectedItem] tag]) { case 0: // file order for(j=0; j<possibleImports; j++) { [fieldMappingArray replaceObjectAtIndex:j withObject:[NSNumber numberWithInteger:j]]; - [fieldMappingOperatorArray replaceObjectAtIndex:j withObject:doImport]; + [fieldMappingOperatorArray replaceObjectAtIndex:j withObject:doImportKey]; } break; case 1: // reversed file order possibleImports--; for(j=possibleImports; j>=0; j--) { [fieldMappingArray replaceObjectAtIndex:possibleImports-j withObject:[NSNumber numberWithInteger:j]]; - [fieldMappingOperatorArray replaceObjectAtIndex:possibleImports-j withObject:doImport]; + [fieldMappingOperatorArray replaceObjectAtIndex:possibleImports - j withObject:doImportKey]; } break; case 2: // try to align header and table target field names via Levenshtein distance @@ -914,11 +921,12 @@ static NSUInteger SPSourceColumnTypeInteger = 1; [self updateFieldMappingButtonCell]; [self updateFieldMappingOperatorOptions]; - // Set all operators to doNotImport + // Set all operators to doNotImportKey [fieldMappingOperatorArray removeAllObjects]; for (i=0; i < [fieldMappingTableColumnNames count]; i++) - [fieldMappingOperatorArray addObject:doImport]; + [fieldMappingOperatorArray addObject:doImportKey]; + [self _setupFieldMappingPopUpMenus]; [fieldMapperTableView reloadData]; [self validateImportButton]; } @@ -929,7 +937,7 @@ static NSUInteger SPSourceColumnTypeInteger = 1; - (IBAction)addNewColumn:(id)sender { - [fieldMappingOperatorArray addObject:doNotImport]; + [fieldMappingOperatorArray addObject:doNotImportKey]; [fieldMappingTableColumnNames addObject:NSLocalizedString(@"New Column Name", @"new column name placeholder string")]; [fieldMappingTableTypes addObject:@"VARCHAR(255)"]; [fieldMappingTableDefaultValues addObject:@""]; @@ -939,6 +947,7 @@ static NSUInteger SPSourceColumnTypeInteger = 1; [fieldMappingArray addObject:[NSNumber numberWithInteger:newIndex]]; [toBeEditedRowIndexes addIndex:newIndex]; + [self _setupFieldMappingPopUpMenus]; [fieldMapperTableView reloadData]; [fieldMapperTableView editColumn:2 row:newIndex withEvent:nil select:YES]; @@ -977,6 +986,7 @@ static NSUInteger SPSourceColumnTypeInteger = 1; currentIndex = [toBeEditedRowIndexes indexGreaterThanIndex:currentIndex]; } + [self _setupFieldMappingPopUpMenus]; [fieldMapperTableView reloadData]; } @@ -1175,9 +1185,9 @@ static NSUInteger SPSourceColumnTypeInteger = 1; [fieldMappingArray replaceObjectAtIndex:[fieldMapperTableView selectedRow] withObject:[NSNumber numberWithInteger:[globalValuesTableView selectedRow]+numberOfImportColumns]]; - // Set corresponding operator to doImport if not set to isEqual - if([fieldMappingOperatorArray objectAtIndex:[fieldMapperTableView selectedRow]] != isEqual) - [fieldMappingOperatorArray replaceObjectAtIndex:[fieldMapperTableView selectedRow] withObject:doImport]; + // Set corresponding operator to doImport if not set to isEqualKey + if(![isEqualKey isEqualToNumber:[fieldMappingOperatorArray objectAtIndex:[fieldMapperTableView selectedRow]]]) + [fieldMappingOperatorArray replaceObjectAtIndex:[fieldMapperTableView selectedRow] withObject:doImportKey]; [fieldMapperTableView reloadData]; @@ -1444,7 +1454,7 @@ static NSUInteger SPSourceColumnTypeInteger = 1; // Set best match [fieldMappingArray replaceObjectAtIndex:match.location withObject:[NSNumber numberWithInteger:match.length]]; - [fieldMappingOperatorArray replaceObjectAtIndex:match.location withObject:doImport]; + [fieldMappingOperatorArray replaceObjectAtIndex:match.location withObject:doImportKey]; // Remember matched pair [matchedTable addObject:[m objectForKey:@"table"]]; @@ -1508,6 +1518,7 @@ static NSUInteger SPSourceColumnTypeInteger = 1; [fieldMappingButtonOptions addObject:[NSString stringWithFormat:@"%li. %@", (long)i+1, NSArrayObjectAtIndex(fieldMappingGlobalValues, i)]]; } + [self _setupFieldMappingPopUpMenus]; [fieldMapperTableView reloadData]; } @@ -1562,7 +1573,7 @@ static NSUInteger SPSourceColumnTypeInteger = 1; return; } for (NSUInteger i = 0; i < [fieldMappingTableColumnNames count]; i++) { - if (![[fieldMappingTableColumnNames objectAtIndex:i] length] && [fieldMappingOperatorArray objectAtIndex:i] == doImport) { + if (![[fieldMappingTableColumnNames objectAtIndex:i] length] && [doImportKey isEqualToNumber:[fieldMappingOperatorArray objectAtIndex:i]]) { [importButton setEnabled:NO]; return; } @@ -1578,7 +1589,7 @@ static NSUInteger SPSourceColumnTypeInteger = 1; if ([[self selectedImportMethod] isEqualToString:@"UPDATE"]) { enableImportButton = NO; for(id op in fieldMappingOperatorArray) { - if(op == isEqual) { + if([isEqualKey isEqualToNumber:op]) { enableImportButton = YES; break; } @@ -1654,9 +1665,9 @@ static NSUInteger SPSourceColumnTypeInteger = 1; && [fieldMappingOperatorArray count] && [fieldMappingTableColumnNames count]) { NSUInteger i; - NSNumber *globalValue = doImport; - if([fieldMappingOperatorArray objectAtIndex:0] == doImport) - globalValue = doNotImport; + NSNumber *globalValue = doImportKey; + if([doImportKey isEqualToNumber:[fieldMappingOperatorArray objectAtIndex:0]]) + globalValue = doNotImportKey; [fieldMappingOperatorArray removeAllObjects]; for(i=0; i < [fieldMappingTableColumnNames count]; i++) [fieldMappingOperatorArray addObject:globalValue]; @@ -1671,7 +1682,7 @@ static NSUInteger SPSourceColumnTypeInteger = 1; if(aTableView == fieldMapperTableView) { - if ([fieldMappingOperatorArray objectAtIndex:rowIndex] == doNotImport) return [NSString stringWithFormat:@"DEFAULT: %@", [fieldMappingTableDefaultValues objectAtIndex:rowIndex]]; + if ([doNotImportKey isEqual:[fieldMappingOperatorArray objectAtIndex:rowIndex]]) return [NSString stringWithFormat:@"DEFAULT: %@", [fieldMappingTableDefaultValues objectAtIndex:rowIndex]]; if([[aTableColumn identifier] isEqualToString:SPTableViewImportValueColumnID] && [importFieldNamesHeaderSwitch state] == NSOnState) { @@ -1695,11 +1706,11 @@ static NSUInteger SPSourceColumnTypeInteger = 1; } else if([[aTableColumn identifier] isEqualToString:SPTableViewOperatorColumnID]) { - if([aCell objectValue] == doImport) + if([doImportKey isEqual:[aCell objectValue]]) return NSLocalizedString(@"Import field", @"import field operator tooltip"); - else if([aCell objectValue] == doNotImport) + else if([doNotImportKey isEqual:[aCell objectValue]]) return NSLocalizedString(@"Ignore field", @"ignore field label"); - else if([aCell objectValue] == isEqual) + else if([isEqualKey isEqual:[aCell objectValue]]) return NSLocalizedString(@"Do UPDATE where field contents match", @"do update operator tooltip"); else return @""; @@ -1715,32 +1726,64 @@ static NSUInteger SPSourceColumnTypeInteger = 1; return @""; } +- (void)menuNeedsUpdate:(NSMenu *)aMenu +{ + // Note: matching aMenu with "==" will most likely not work, as NSTableView copies it. + // This technique is based on: http://www.corbinstreehouse.com/blog/2005/07/dynamically-populating-an-nspopupbuttoncell-in-an-nstableview/ + + NSInteger rowIndex = [fieldMapperTableView selectedRow]; + if(rowIndex < 0) + return; + + NSInteger rowIndexInMenu = firstDefaultItemOffset + rowIndex; + for (NSInteger i = firstDefaultItemOffset; i < [aMenu numberOfItems]; i++) { + [[aMenu itemAtIndex:i] setHidden:(i != rowIndexInMenu)]; + } +} + +- (void)_setupFieldMappingPopUpMenus +{ + NSPopUpButtonCell *c = [[fieldMapperTableView tableColumnWithIdentifier:SPTableViewImportValueColumnID] dataCell]; + NSMenu *m = [c menu]; + [m setAutoenablesItems:NO]; + [c removeAllItems]; + [c addItemsWithTitles:fieldMappingButtonOptions]; + + [m addItem:[NSMenuItem separatorItem]]; + + [c addItemWithTitle:NSLocalizedString(@"Ignore Field", @"ignore field label")]; + [c addItemWithTitle:NSLocalizedString(@"Ignore all Fields", @"ignore all fields menu item")]; + [c addItemWithTitle:NSLocalizedString(@"Import all Fields", @"import all fields menu item")]; + if([[self selectedImportMethod] isEqualToString:@"UPDATE"]) + [c addItemWithTitle:NSLocalizedString(@"Match Field", @"match field menu item")]; + + [m addItem:[NSMenuItem separatorItem]]; + + NSMenuItem *menuItem = [m addItemWithTitle:NSLocalizedString(@"Add Value or Expression…", @"add global value or expression menu item") action:@selector(addGlobalSourceVariable:) keyEquivalent:@"g"]; + [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; + + //create all menu items for the "DEFAULT" rows. We will use menuNeedsUpdate: to hide all items that are not needed. + //This works because NSTableView will copy the menu before showing it, so menuNeedsUpdate: will work on a disposable copy + //while the full menu is never shown (but it's items are displayed in the table view) + firstDefaultItemOffset = [m numberOfItems]; + for (id item in fieldMappingTableDefaultValues) { + NSString *label = [NSString stringWithFormat:NSLocalizedString(@"Default: %@",@"import : csv field mapping : field default value"), item]; + NSMenuItem *defaultItem = [m addItemWithTitle:label action:NULL keyEquivalent:@""]; + [defaultItem setEnabled:NO]; + } + + NSPopUpButtonCell *optsCell = [[fieldMapperTableView tableColumnWithIdentifier:SPTableViewOperatorColumnID] dataCell]; + [optsCell removeAllItems]; + [optsCell addItemsWithTitles:fieldMappingOperatorOptions]; +} + - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex { if(aTableView == fieldMapperTableView) { if ([[aTableColumn identifier] isEqualToString:SPTableViewTargetFieldColumnID]) { - if([toBeEditedRowIndexes containsIndex:rowIndex]) { - NSTextFieldCell *b = [[[NSTextFieldCell alloc] initTextCell:[fieldMappingTableColumnNames objectAtIndex:rowIndex]] autorelease]; - [b setEditable:YES]; - [b setFont:[NSFont systemFontOfSize:12]]; - [aTableColumn setDataCell:b]; - return b; - } - if(newTableMode) { - NSTextFieldCell *b = [[[NSTextFieldCell alloc] initTextCell:[fieldMappingTableColumnNames objectAtIndex:rowIndex]] autorelease]; - [b setEditable:YES]; - [b setFont:[NSFont systemFontOfSize:12]]; - [aTableColumn setDataCell:b]; - return b; - } else { - if ([[aTableColumn dataCell] isKindOfClass:[NSPopUpButtonCell class]]) { - [(NSPopUpButton *)[aTableColumn dataCell] removeAllItems]; - [(NSPopUpButtonCell *)[aTableColumn dataCell] addItemWithTitle:[fieldMappingTableColumnNames objectAtIndex:rowIndex]]; - } - return [fieldMappingTableColumnNames objectAtIndex:rowIndex]; - } + return [fieldMappingTableColumnNames objectAtIndex:rowIndex]; } else if ([[aTableColumn identifier] isEqualToString:SPTableViewTypeColumnID]) { @@ -1765,45 +1808,20 @@ static NSUInteger SPSourceColumnTypeInteger = 1; else if ([[aTableColumn identifier] isEqualToString:SPTableViewImportValueColumnID]) { - // Check if all global value was deleted, if so set assigned field as doNotImport + // Check if all global value was deleted, if so set assigned field as doNotImportKey if([[fieldMappingArray objectAtIndex:rowIndex] unsignedIntegerValue] >= [fieldMappingButtonOptions count]) { - [fieldMappingOperatorArray replaceObjectAtIndex:rowIndex withObject:doNotImport]; + [fieldMappingOperatorArray replaceObjectAtIndex:rowIndex withObject:doNotImportKey]; } - if ([[aTableColumn dataCell] isKindOfClass:[NSPopUpButtonCell class]]) { - - NSPopUpButtonCell *c = [aTableColumn dataCell]; - NSMenu *m = [c menu]; - [m setAutoenablesItems:NO]; - [c removeAllItems]; - [c addItemsWithTitles:fieldMappingButtonOptions]; - [m addItem:[NSMenuItem separatorItem]]; - [c addItemWithTitle:NSLocalizedString(@"Ignore Field", @"ignore field label")]; - [c addItemWithTitle:NSLocalizedString(@"Ignore all Fields", @"ignore all fields menu item")]; - [c addItemWithTitle:NSLocalizedString(@"Import all Fields", @"import all fields menu item")]; - if([[self selectedImportMethod] isEqualToString:@"UPDATE"]) - [c addItemWithTitle:NSLocalizedString(@"Match Field", @"match field menu item")]; - [m addItem:[NSMenuItem separatorItem]]; - NSMenuItem *menuItem = [m addItemWithTitle:NSLocalizedString(@"Add Value or Expression…", @"add global value or expression menu item") action:@selector(addGlobalSourceVariable:) keyEquivalent:@"g"]; - [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; - [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 if not - // UPDATE was chosen otherwise hide it. - if([fieldMappingOperatorArray objectAtIndex:rowIndex] != doNotImport) - return [fieldMappingArray objectAtIndex:rowIndex]; - else if(![[self selectedImportMethod] isEqualToString:@"UPDATE"]) - return [NSNumber numberWithInteger:[c numberOfItems]-1]; - - } + // If user doesn't want to import it show its DEFAULT value if not + // UPDATE was chosen otherwise hide it. + if(![doNotImportKey isEqualToNumber:[fieldMappingOperatorArray objectAtIndex:rowIndex]]) + return [fieldMappingArray objectAtIndex:rowIndex]; + else if(![[self selectedImportMethod] isEqualToString:@"UPDATE"]) + return [NSNumber numberWithInteger:firstDefaultItemOffset+rowIndex]; } else if ([[aTableColumn identifier] isEqualToString:SPTableViewOperatorColumnID]) { - if ([[aTableColumn dataCell] isKindOfClass:[NSPopUpButtonCell class]]) { - [(NSPopUpButtonCell *)[aTableColumn dataCell] removeAllItems]; - [(NSPopUpButtonCell *)[aTableColumn dataCell] addItemsWithTitles:fieldMappingOperatorOptions]; - } return [fieldMappingOperatorArray objectAtIndex:rowIndex]; } } @@ -1845,16 +1863,16 @@ static NSUInteger SPSourceColumnTypeInteger = 1; if(aTableView == fieldMapperTableView) { if ([[aTableColumn identifier] isEqualToString:SPTableViewImportValueColumnID]) { if([anObject integerValue] > (NSInteger)[fieldMappingButtonOptions count]) { - // Ignore field - set operator to doNotImport + // Ignore field - set operator to doNotImportKey if([anObject integerValue] == (NSInteger)[fieldMappingButtonOptions count]+1) { lastDisabledCSVFieldcolumn = [fieldMappingArray objectAtIndex:rowIndex]; - [fieldMappingOperatorArray replaceObjectAtIndex:rowIndex withObject:doNotImport]; + [fieldMappingOperatorArray replaceObjectAtIndex:rowIndex withObject:doNotImportKey]; [aTableView performSelector:@selector(reloadData) withObject:nil afterDelay:0.0]; } - // Ignore all field - set all operator to doNotImport + // Ignore all field - set all operator to doNotImportKey else if([anObject integerValue] == (NSInteger)[fieldMappingButtonOptions count]+2) { NSUInteger i; - NSNumber *globalValue = doNotImport; + NSNumber *globalValue = doNotImportKey; [fieldMappingOperatorArray removeAllObjects]; for(i=0; i < [fieldMappingTableColumnNames count]; i++) [fieldMappingOperatorArray addObject:globalValue]; @@ -1863,14 +1881,14 @@ static NSUInteger SPSourceColumnTypeInteger = 1; // Import all field - set all operator to doImport else if([anObject integerValue] == (NSInteger)[fieldMappingButtonOptions count]+3) { NSUInteger i; - NSNumber *globalValue = doImport; + NSNumber *globalValue = doImportKey; [fieldMappingOperatorArray removeAllObjects]; for(i=0; i < [fieldMappingTableColumnNames count]; i++) [fieldMappingOperatorArray addObject:globalValue]; [aTableView performSelector:@selector(reloadData) withObject:nil afterDelay:0.0]; } else if([[self selectedImportMethod] isEqualToString:@"UPDATE"] && [anObject integerValue] == (NSInteger)[fieldMappingButtonOptions count]+4) { - [fieldMappingOperatorArray replaceObjectAtIndex:rowIndex withObject:isEqual]; + [fieldMappingOperatorArray replaceObjectAtIndex:rowIndex withObject:isEqualKey]; [aTableView performSelector:@selector(reloadData) withObject:nil afterDelay:0.0]; } // Add global value @@ -1890,8 +1908,8 @@ static NSUInteger SPSourceColumnTypeInteger = 1; [fieldMappingArray replaceObjectAtIndex:rowIndex withObject:anObject]; // If user _changed_ the csv file column set the operator to doImport if not set to = - if([(NSNumber*)anObject integerValue] > -1 && NSArrayObjectAtIndex(fieldMappingOperatorArray, rowIndex) != isEqual) - [fieldMappingOperatorArray replaceObjectAtIndex:rowIndex withObject:doImport]; + if([(NSNumber*)anObject integerValue] > -1 && ![isEqualKey isEqualToNumber:NSArrayObjectAtIndex(fieldMappingOperatorArray, rowIndex)]) + [fieldMappingOperatorArray replaceObjectAtIndex:rowIndex withObject:doImportKey]; [self validateImportButton]; @@ -1918,11 +1936,11 @@ static NSUInteger SPSourceColumnTypeInteger = 1; } else if ([[aTableColumn identifier] isEqualToString:SPTableViewOperatorColumnID]) { - if([fieldMappingOperatorArray objectAtIndex:rowIndex] == doNotImport) { + if([doNotImportKey isEqualToNumber:[fieldMappingOperatorArray objectAtIndex:rowIndex]]) { [fieldMappingOperatorArray replaceObjectAtIndex:rowIndex withObject:anObject]; [fieldMappingArray replaceObjectAtIndex:rowIndex withObject:lastDisabledCSVFieldcolumn]; } else { - if(anObject == doNotImport) lastDisabledCSVFieldcolumn = [fieldMappingArray objectAtIndex:rowIndex]; + if([doNotImportKey isEqual:anObject]) lastDisabledCSVFieldcolumn = [fieldMappingArray objectAtIndex:rowIndex]; [fieldMappingOperatorArray replaceObjectAtIndex:rowIndex withObject:anObject]; } [self validateImportButton]; |