From 0672e261a6f66e3d8f6a188a476518c40f411b09 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Tue, 28 Sep 2010 17:26:48 +0000 Subject: =?UTF-8?q?=E2=80=A2=20enabled=20Filter=20Table=20approach=20(Cont?= =?UTF-8?q?ent=20View=20>=20=E2=8C=98F)=20for=20testing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interfaces/English.lproj/DBView.xib | 115 ++++++++++++++++++++++++++++-------- Source/SPTableContent.h | 3 +- Source/SPTableContent.m | 58 ++++++++++++++---- 3 files changed, 140 insertions(+), 36 deletions(-) diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index 19cd1ac2..9729fba6 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -23,8 +23,7 @@ YES - - + YES @@ -48,7 +47,7 @@ NSApplication - + 274 YES @@ -6084,7 +6083,6 @@ {943, 549} - NSView @@ -9741,7 +9739,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 292 - {{68, 27}, {139, 18}} + {{68, 27}, {158, 18}} YES @@ -9751,11 +9749,11 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 1211912703 - 130 + 268435586 - + n 200 25 @@ -9763,7 +9761,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 292 - {{68, 9}, {139, 18}} + {{68, 9}, {158, 18}} YES @@ -9773,11 +9771,11 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 1211912703 - 130 + 268435586 - + d 200 25 @@ -9820,6 +9818,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 + YES Set Default Operator 1048576 @@ -9855,6 +9854,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 + YES Swap Table s 1572864 @@ -9868,6 +9868,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 + 4 YES 1 YES @@ -15401,14 +15402,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 7526 - - - tableFilterExecute: - - - - 7527 - filterTableWindow @@ -15521,6 +15514,30 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 7579 + + + filterTable: + + + + 7580 + + + + filterTableFilterButton + + + + 7581 + + + + filterTableDistinctCheckbox + + + + 7582 + @@ -23051,7 +23068,9 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 7502.windowTemplate.minSize 7503.IBPluginDependency 7504.IBPluginDependency + 7505.IBAttributePlaceholdersKey 7505.IBPluginDependency + 7506.IBAttributePlaceholdersKey 7506.IBPluginDependency 7507.IBPluginDependency 7508.IBPluginDependency @@ -23076,6 +23095,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 7525.IBPluginDependency 7533.IBPluginDependency 7534.IBPluginDependency + 7537.IBAttributePlaceholdersKey 7537.IBPluginDependency 7538.IBPluginDependency 7563.IBPluginDependency @@ -23087,6 +23107,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 7568.IBPluginDependency 7569.IBPluginDependency 7570.IBPluginDependency + 7577.IBAttributePlaceholdersKey 7577.IBPluginDependency 7578.IBPluginDependency 858.IBPluginDependency @@ -24421,7 +24442,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{977, 203}, {943, 549}} + {{119, 203}, {943, 549}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -24736,15 +24757,31 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{242, 511}, {480, 270}} + {{85, 438}, {480, 270}} com.apple.InterfaceBuilder.CocoaPlugin - {{242, 511}, {480, 270}} + {{85, 438}, {480, 270}} {340, 170} com.apple.InterfaceBuilder.CocoaPlugin com.brandonwalkin.BWToolkit + + ToolTip + + ToolTip + + Clear all Filter Criterias (⌘⌫) + + com.brandonwalkin.BWToolkit + + ToolTip + + ToolTip + + Apply Filter to current Table (⌘F) + + com.brandonwalkin.BWToolkit com.brandonwalkin.BWToolkit com.brandonwalkin.BWToolkit @@ -24769,17 +24806,33 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + If set negate entire WHERE clause (⌘N) + + com.brandonwalkin.BWToolkit com.brandonwalkin.BWToolkit com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{429, 466}, {188, 81}} + {{88, 384}, {228, 98}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Table Data will be queried by using SELECT DISTINCT (⌘D) + + com.brandonwalkin.BWToolkit com.brandonwalkin.BWToolkit com.apple.InterfaceBuilder.CocoaPlugin @@ -24820,7 +24873,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 - 7579 + 7582 @@ -30198,6 +30251,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 swapFilterTable: tableFilterClear: tableFilterExecute: + toggleDistinctSelect: toggleFilterField: toggleLookAllFieldsMode: toggleNegateClause: @@ -30221,6 +30275,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 id id id + id @@ -30239,6 +30294,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 swapFilterTable: tableFilterClear: tableFilterExecute: + toggleDistinctSelect: toggleFilterField: toggleLookAllFieldsMode: toggleNegateClause: @@ -30294,6 +30350,10 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 tableFilterExecute: id + + toggleDistinctSelect: + id + toggleFilterField: id @@ -30327,6 +30387,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 fieldField filterButton filterTableClearButton + filterTableDistinctCheckbox filterTableFilterButton filterTableGearLookAllFields filterTableNegateCheckbox @@ -30368,6 +30429,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 NSPopUpButton id NSButton + id NSButton NSMenuItem id @@ -30412,6 +30474,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 fieldField filterButton filterTableClearButton + filterTableDistinctCheckbox filterTableFilterButton filterTableGearLookAllFields filterTableNegateCheckbox @@ -30486,6 +30549,10 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 filterTableClearButton NSButton + + filterTableDistinctCheckbox + id + filterTableFilterButton NSButton @@ -31721,7 +31788,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 YES - {10, 10} + {15, 15} {8, 8} {32, 32} {128, 128} diff --git a/Source/SPTableContent.h b/Source/SPTableContent.h index e6d41ca9..8e5b7af7 100644 --- a/Source/SPTableContent.h +++ b/Source/SPTableContent.h @@ -104,6 +104,7 @@ BOOL filterTableDistinct; NSString *filterTableDefaultOperator; NSString *lastEditedFilterTableValue; + NSInteger activeFilter; // 0 = default filter; 1 = filter table BOOL sortColumnToRestoreIsAsc; BOOL tableRowsSelectable; @@ -216,6 +217,6 @@ - (NSArray*)fieldEditStatusForRow:(NSInteger)rowIndex andColumn:(NSInteger)columnIndex; -- (void)updateFilterTableClause:(NSString*)currentValue; +- (void)updateFilterTableClause:(id)currentValue; @end diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m index b63c6062..d72a17dd 100644 --- a/Source/SPTableContent.m +++ b/Source/SPTableContent.m @@ -75,6 +75,7 @@ filterTableNegate = NO; filterTableDistinct = NO; lastEditedFilterTableValue = nil; + activeFilter = 0; selectedTable = nil; sortCol = nil; @@ -378,10 +379,14 @@ while ([[tableContentView tableColumns] count]) { [tableContentView removeTableColumn:NSArrayObjectAtIndex([tableContentView tableColumns], 0)]; } + // Remove existing columns from the filter table while ([[filterTableView tableColumns] count]) { [filterTableView removeTableColumn:NSArrayObjectAtIndex([filterTableView tableColumns], 0)]; } + // Clear filter table data [filterTableData removeAllObjects]; + [filterTableWhereClause setString:@""]; + activeFilter = 0; // Retrieve the field names and types for this table from the data cache. This is used when requesting all data as part // of the fieldListForQuery method, and also to decide whether or not to preserve the current filter/sort settings. @@ -620,7 +625,7 @@ [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:tableDocumentInstance]; // Start construction of the query string - queryString = [NSMutableString stringWithFormat:@"SELECT %@ FROM %@", [self fieldListForQuery], [selectedTable backtickQuotedString]]; + queryString = [NSMutableString stringWithFormat:@"SELECT %@%@ FROM %@", (activeFilter == 1 && [self tableFilterString] && [filterTableDistinctCheckbox state] == NSOnState) ? @"DISTINCT " : @"", [self fieldListForQuery], [selectedTable backtickQuotedString]]; // Add a filter string if appropriate filterString = [self tableFilterString]; @@ -840,6 +845,19 @@ - (NSString *)tableFilterString { + // Call did come from filter table and is filter table window still open? + if(activeFilter == 1 && [filterTableWindow isVisible]) { + + if([[[filterTableWhereClause textStorage] string] length]) + if([filterTableNegateCheckbox state] == NSOnState) + return [NSString stringWithFormat:@"NOT (%@)", [[filterTableWhereClause textStorage] string]]; + else + return [[filterTableWhereClause textStorage] string]; + else + return nil; + + } + // If the clause has the placeholder $BINARY that placeholder will be replaced // by BINARY if the user pressed ⇧ while invoking 'Filter' otherwise it will // replaced by @"". @@ -1213,6 +1231,12 @@ */ - (IBAction)filterTable:(id)sender { + + if(sender == filterTableFilterButton) + activeFilter = 1; + else + activeFilter = 0; + NSString *taskString; if ([tableDocumentInstance isWorking]) return; @@ -2857,8 +2881,7 @@ - (IBAction)toggleLookAllFieldsMode:(id)sender { - NSLog(@"ddd %@", lastEditedFilterTableValue); - // [self tableFilterClear:nil]; + [self updateFilterTableClause:sender]; } #pragma mark - @@ -3921,7 +3944,7 @@ if(lastEditedFilterTableValue) [lastEditedFilterTableValue release]; lastEditedFilterTableValue = [[NSString stringWithString:str] retain]; } - [self updateFilterTableClause:lastEditedFilterTableValue]; + [self updateFilterTableClause:str]; } } @@ -4066,9 +4089,9 @@ } /** - * Update WHERE clause in Filter Table Window - TODO not yet finished - initial approach only by HansJB + * Update WHERE clause in Filter Table Window */ -- (void)updateFilterTableClause:(NSString*)currentValue +- (void)updateFilterTableClause:(id)currentValue { NSMutableString *clause = [NSMutableString string]; NSInteger numberOfRows = [self numberOfRowsInTableView:filterTableView]; @@ -4076,10 +4099,19 @@ NSInteger numberOfValues = 0; NSRange opRange; + BOOL lookInAllFields = NO; + NSString *re1 = @"^\\s*(<|>|!?=)\\s*(.*?)\\s*$"; NSString *re2 = @"(?i)^\\s*(.*)\\s+(.*?)\\s*$"; NSCharacterSet *whiteSpaceCharSet = [NSCharacterSet whitespaceAndNewlineCharacterSet]; + if(currentValue == filterTableGearLookAllFields) { + numberOfRows = 1; + lookInAllFields = YES; + } + + [filterTableWhereClause setString:@""]; + for(NSInteger i=0; i