| 1 |
masaki |
120 |
// |
| 2 |
|
|
// XspfMRuleEditorDelegate.m |
| 3 |
|
|
// XspfManager |
| 4 |
|
|
// |
| 5 |
|
|
// Created by Hori,Masaki on 09/11/28. |
| 6 |
|
|
// Copyright 2009 masakih. All rights reserved. |
| 7 |
|
|
// |
| 8 |
|
|
|
| 9 |
|
|
#import "XspfMRuleEditorDelegate.h" |
| 10 |
|
|
|
| 11 |
|
|
#import "XspfMRuleEditorRow.h" |
| 12 |
|
|
|
| 13 |
|
|
@implementation XspfMRuleEditorDelegate |
| 14 |
|
|
|
| 15 |
|
|
- (void)awakeFromNib |
| 16 |
|
|
{ |
| 17 |
|
|
if(!compound) { |
| 18 |
|
|
compound = [[XspfMCompound alloc] init]; |
| 19 |
|
|
} |
| 20 |
|
|
if(!simples) { |
| 21 |
|
|
simples = [NSMutableArray array]; |
| 22 |
|
|
[simples retain]; |
| 23 |
|
|
|
| 24 |
|
|
XspfMStringPredicate *pre; |
| 25 |
|
|
pre = [XspfMStringPredicate simpleWithKeyPath:@"title" rightType:0 operator:0]; |
| 26 |
|
|
[simples addObject:pre]; |
| 27 |
masaki |
121 |
pre = [XspfMAbsoluteDatePredicate simpleWithKeyPath:@"lastPlayDate" rightType:0 operator:0]; |
| 28 |
|
|
[simples addObject:pre]; |
| 29 |
|
|
pre = [XspfMAbsoluteDatePredicate simpleWithKeyPath:@"modificationDate" rightType:0 operator:0]; |
| 30 |
|
|
[simples addObject:pre]; |
| 31 |
masaki |
120 |
pre = [XspfMAbsoluteDatePredicate simpleWithKeyPath:@"creationDate" rightType:0 operator:0]; |
| 32 |
|
|
[simples addObject:pre]; |
| 33 |
|
|
} |
| 34 |
|
|
} |
| 35 |
|
|
|
| 36 |
|
|
#pragma mark#### NSRuleEditor Delegate #### |
| 37 |
|
|
- (NSInteger)ruleEditor:(NSRuleEditor *)editor |
| 38 |
|
|
numberOfChildrenForCriterion:(id)criterion |
| 39 |
|
|
withRowType:(NSRuleEditorRowType)rowType |
| 40 |
|
|
{ |
| 41 |
|
|
NSInteger result = 0; |
| 42 |
|
|
|
| 43 |
|
|
if(rowType == NSRuleEditorRowTypeCompound) { |
| 44 |
|
|
result = [compound numberOfChildrenForChild:criterion]; |
| 45 |
|
|
goto end; |
| 46 |
|
|
} |
| 47 |
|
|
|
| 48 |
|
|
if(!criterion) { |
| 49 |
|
|
result = [simples count]; |
| 50 |
|
|
goto end; |
| 51 |
|
|
return result; |
| 52 |
|
|
} |
| 53 |
|
|
|
| 54 |
|
|
for(id s in simples) { |
| 55 |
|
|
if([s isMyChild:criterion]) result += [s numberOfChildrenForChild:criterion]; |
| 56 |
|
|
} |
| 57 |
|
|
|
| 58 |
|
|
end: |
| 59 |
|
|
// NSLog(@"numner\tcriterion -> %@, type -> %d, result -> %d", criterion, rowType, result); |
| 60 |
|
|
|
| 61 |
|
|
return result; |
| 62 |
|
|
} |
| 63 |
|
|
- (id)ruleEditor:(NSRuleEditor *)editor |
| 64 |
|
|
child:(NSInteger)index |
| 65 |
|
|
forCriterion:(id)criterion |
| 66 |
|
|
withRowType:(NSRuleEditorRowType)rowType |
| 67 |
|
|
{ |
| 68 |
|
|
id result = nil; |
| 69 |
|
|
|
| 70 |
|
|
if(rowType == NSRuleEditorRowTypeCompound) { |
| 71 |
|
|
result = [compound childForChild:criterion atIndex:index]; |
| 72 |
|
|
goto end; |
| 73 |
|
|
} |
| 74 |
|
|
|
| 75 |
|
|
if(!criterion) { |
| 76 |
|
|
id s = [simples objectAtIndex:index]; |
| 77 |
|
|
result = [s childForChild:criterion atIndex:index]; |
| 78 |
|
|
goto end; |
| 79 |
|
|
} |
| 80 |
|
|
|
| 81 |
|
|
for(id s in simples) { |
| 82 |
|
|
if([s isMyChild:criterion]) { |
| 83 |
|
|
result = [s childForChild:criterion atIndex:index]; |
| 84 |
|
|
goto end; |
| 85 |
|
|
} |
| 86 |
|
|
} |
| 87 |
|
|
|
| 88 |
|
|
end: |
| 89 |
|
|
// NSLog(@"child\tindex -> %d, criterion -> %@, type -> %d, result -> %@", index, criterion, rowType, result); |
| 90 |
|
|
|
| 91 |
|
|
return result; |
| 92 |
|
|
} |
| 93 |
|
|
- (id)ruleEditor:(NSRuleEditor *)editor |
| 94 |
|
|
displayValueForCriterion:(id)criterion |
| 95 |
|
|
inRow:(NSInteger)row |
| 96 |
|
|
{ |
| 97 |
|
|
id result = nil; |
| 98 |
|
|
|
| 99 |
|
|
NSRuleEditorRowType rowType = [editor rowTypeForRow:row]; |
| 100 |
|
|
if(rowType == NSRuleEditorRowTypeCompound) { |
| 101 |
|
|
result = [compound displayValueForChild:criterion]; |
| 102 |
|
|
goto end; |
| 103 |
|
|
} |
| 104 |
|
|
|
| 105 |
|
|
for(id s in simples) { |
| 106 |
|
|
if([s isMyChild:criterion]) { |
| 107 |
|
|
result = [s displayValueForChild:criterion]; |
| 108 |
|
|
goto end; |
| 109 |
|
|
} |
| 110 |
|
|
} |
| 111 |
|
|
|
| 112 |
|
|
end: |
| 113 |
|
|
// NSLog(@"display\tcriterion -> %@, row -> %d, result -> %@", criterion, row, result); |
| 114 |
|
|
return result; |
| 115 |
|
|
} |
| 116 |
|
|
|
| 117 |
masaki |
121 |
- (NSDictionary *)ruleEditor:(NSRuleEditor *)editor |
| 118 |
|
|
predicatePartsForCriterion:(id)criterion |
| 119 |
|
|
withDisplayValue:(id)value |
| 120 |
|
|
inRow:(NSInteger)row |
| 121 |
|
|
{ |
| 122 |
|
|
id result = nil; |
| 123 |
|
|
|
| 124 |
|
|
NSRuleEditorRowType rowType = [editor rowTypeForRow:row]; |
| 125 |
|
|
if(rowType == NSRuleEditorRowTypeCompound) { |
| 126 |
|
|
result = [compound predicateForChild:criterion withDisplayValue:value]; |
| 127 |
|
|
goto end; |
| 128 |
|
|
} |
| 129 |
|
|
|
| 130 |
|
|
for(id s in simples) { |
| 131 |
|
|
if([s isMyChild:criterion]) { |
| 132 |
|
|
result = [s predicateForChild:criterion withDisplayValue:value]; |
| 133 |
|
|
goto end; |
| 134 |
|
|
} |
| 135 |
|
|
} |
| 136 |
|
|
|
| 137 |
|
|
end: |
| 138 |
|
|
// NSLog(@"predicate\tcriterion -> %@, value -> %@, row -> %d, result -> %@", criterion, value, row, result); |
| 139 |
|
|
|
| 140 |
|
|
return result; |
| 141 |
|
|
} |
| 142 |
masaki |
120 |
@end |