aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Interfaces/English.lproj/DataMigrationDialog.xib230
-rw-r--r--Source/SPFieldMapperController.h32
-rw-r--r--Source/SPFieldMapperController.m106
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 @@
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="14"/>
+ <integer value="42"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -30,7 +30,7 @@
<object class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSCustomObject" id="1001">
- <string key="NSClassName">TableDocument</string>
+ <string key="NSClassName">SPFieldMapperController</string>
</object>
<object class="NSCustomObject" id="1003">
<string key="NSClassName">FirstResponder</string>
@@ -174,7 +174,7 @@
<object class="NSMutableArray" key="NSTableColumns">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSTableColumn" id="790992768">
- <string key="NSIdentifier">value</string>
+ <string key="NSIdentifier">import_value</string>
<double key="NSWidth">216</double>
<double key="NSMinWidth">15</double>
<double key="NSMaxWidth">1000</double>
@@ -250,7 +250,7 @@
<reference key="NSTableView" ref="678921094"/>
</object>
<object class="NSTableColumn" id="185178480">
- <string key="NSIdentifier">field</string>
+ <string key="NSIdentifier">target_field</string>
<double key="NSWidth">220</double>
<double key="NSMinWidth">10</double>
<double key="NSMaxWidth">3.4028234663852886e+38</double>
@@ -344,7 +344,7 @@
<int key="NSsFlags">257</int>
<reference key="NSTarget" ref="495172082"/>
<string key="NSAction">_doScroller:</string>
- <double key="NSCurValue">0.037825059145689011</double>
+ <double key="NSCurValue">0.035674519836902618</double>
<double key="NSPercent">0.99047619104385376</double>
</object>
<object class="NSClipView" id="622202999">
@@ -537,21 +537,22 @@
<string key="NSKeyEquivalent"/>
<int key="NSPeriodicDelay">400</int>
<int key="NSPeriodicInterval">75</int>
- <object class="NSMenuItem" key="NSMenuItem" id="1004582521">
+ <object class="NSMenuItem" key="NSMenuItem" id="604589401">
<reference key="NSMenu" ref="519018523"/>
- <string key="NSTitle">INSERT</string>
+ <string key="NSTitle">UPDATE</string>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
<int key="NSState">1</int>
- <object class="NSCustomResource" key="NSOnImage" id="597600036">
+ <object class="NSCustomResource" key="NSOnImage" id="74411591">
<string key="NSClassName">NSImage</string>
<string key="NSResourceName">NSMenuCheckmark</string>
</object>
- <object class="NSCustomResource" key="NSMixedImage" id="577467422">
+ <object class="NSCustomResource" key="NSMixedImage" id="715110738">
<string key="NSClassName">NSImage</string>
<string key="NSResourceName">NSMenuMixedState</string>
</object>
<string key="NSAction">_popUpItemAction:</string>
+ <int key="NSTag">2</int>
<reference key="NSTarget" ref="1033308908"/>
</object>
<bool key="NSMenuItemRespectAlignment">YES</bool>
@@ -559,31 +560,31 @@
<string key="NSTitle">OtherViews</string>
<object class="NSMutableArray" key="NSMenuItems">
<bool key="EncodedWithXMLCoder">YES</bool>
- <reference ref="1004582521"/>
- <object class="NSMenuItem" id="167502619">
+ <object class="NSMenuItem" id="1004582521">
<reference key="NSMenu" ref="519018523"/>
- <string key="NSTitle">REPLACE</string>
+ <string key="NSTitle">INSERT</string>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
- <reference key="NSOnImage" ref="597600036"/>
- <reference key="NSMixedImage" ref="577467422"/>
+ <reference key="NSOnImage" ref="74411591"/>
+ <reference key="NSMixedImage" ref="715110738"/>
<string key="NSAction">_popUpItemAction:</string>
- <int key="NSTag">1</int>
<reference key="NSTarget" ref="1033308908"/>
</object>
- <object class="NSMenuItem" id="604589401">
+ <object class="NSMenuItem" id="167502619">
<reference key="NSMenu" ref="519018523"/>
- <string key="NSTitle">UPDATE</string>
+ <string key="NSTitle">REPLACE</string>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
- <reference key="NSOnImage" ref="597600036"/>
- <reference key="NSMixedImage" ref="577467422"/>
+ <reference key="NSOnImage" ref="74411591"/>
+ <reference key="NSMixedImage" ref="715110738"/>
<string key="NSAction">_popUpItemAction:</string>
- <int key="NSTag">2</int>
+ <int key="NSTag">1</int>
<reference key="NSTarget" ref="1033308908"/>
</object>
+ <reference ref="604589401"/>
</object>
</object>
+ <int key="NSSelectedIndex">2</int>
<int key="NSPreferredEdge">1</int>
<bool key="NSUsesItemFromMenu">YES</bool>
<bool key="NSAltersState">YES</bool>
@@ -707,6 +708,134 @@
<object class="IBObjectContainer" key="IBDocument.Objects">
<object class="NSMutableArray" key="connectionRecords">
<bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">tableTargetPopup</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="549705971"/>
+ </object>
+ <int key="connectionID">58</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">changeTableTarget:</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="549705971"/>
+ </object>
+ <int key="connectionID">59</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">fileSourcePath</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="697948389"/>
+ </object>
+ <int key="connectionID">60</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">importMethodPopup</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="599385609"/>
+ </object>
+ <int key="connectionID">61</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">changeImportMethod:</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="599385609"/>
+ </object>
+ <int key="connectionID">62</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">recordCountLabel</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="186404366"/>
+ </object>
+ <int key="connectionID">65</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">rowUpButton</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="116285743"/>
+ </object>
+ <int key="connectionID">66</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">rowDownButton</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="834757891"/>
+ </object>
+ <int key="connectionID">67</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">stepRow:</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="834757891"/>
+ </object>
+ <int key="connectionID">68</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">stepRow:</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="116285743"/>
+ </object>
+ <int key="connectionID">69</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">fieldMapperTableView</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="678921094"/>
+ </object>
+ <int key="connectionID">70</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">delegate</string>
+ <reference key="source" ref="678921094"/>
+ <reference key="destination" ref="1001"/>
+ </object>
+ <int key="connectionID">71</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">dataSource</string>
+ <reference key="source" ref="678921094"/>
+ <reference key="destination" ref="1001"/>
+ </object>
+ <int key="connectionID">72</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">fieldMapperView</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="420604405"/>
+ </object>
+ <int key="connectionID">73</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">closeSheet:</string>
+ <reference key="source" ref="1003"/>
+ <reference key="destination" ref="341819846"/>
+ </object>
+ <int key="connectionID">74</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">closeSheet:</string>
+ <reference key="source" ref="1003"/>
+ <reference key="destination" ref="920273776"/>
+ </object>
+ <int key="connectionID">75</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -1152,9 +1281,9 @@
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{503, 302}, {465, 311}}</string>
+ <string>{{210, 424}, {465, 311}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{503, 302}, {465, 311}}</string>
+ <string>{{210, 424}, {465, 311}}</string>
<integer value="1"/>
<string>{{387, 725}, {432, 282}}</string>
<integer value="0"/>
@@ -1183,7 +1312,7 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{234, 355}, {126, 54}}</string>
+ <string>{{302, 438}, {126, 54}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -1237,7 +1366,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">57</int>
+ <int key="maxID">75</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -1426,6 +1555,59 @@
</object>
</object>
</object>
+ <object class="NSMutableArray" key="referencedPartialClassDescriptionsV3.1+">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBPartialClassDescription">
+ <string key="className">SPFieldMapperController</string>
+ <string key="superclassName">NSWindowController</string>
+ <object class="NSMutableDictionary" key="actions">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>changeImportMethod:</string>
+ <string>changeTableTarget:</string>
+ <string>closeSheet:</string>
+ <string>stepRow:</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>id</string>
+ <string>id</string>
+ <string>id</string>
+ <string>id</string>
+ </object>
+ </object>
+ <object class="NSMutableDictionary" key="outlets">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>fieldMapperTableView</string>
+ <string>fieldMapperView</string>
+ <string>fileSourcePath</string>
+ <string>importMethodPopup</string>
+ <string>recordCountLabel</string>
+ <string>rowDownButton</string>
+ <string>rowUpButton</string>
+ <string>tableTargetPopup</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>id</string>
+ <string>id</string>
+ <string>id</string>
+ <string>id</string>
+ <string>id</string>
+ <string>id</string>
+ <string>id</string>
+ <string>id</string>
+ </object>
+ </object>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBDocumentRelativeSource</string>
+ <string key="minorKey">../../Source/SPFieldMapperController.h</string>
+ </object>
+ </object>
+ </object>
</object>
<int key="IBDocument.localizationMode">0</int>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencies">
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