Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfManager/XspfMRuleEditorDelegate.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 166 - (hide annotations) (download)
Sun Dec 20 04:01:27 2009 UTC (14 years, 4 months ago) by masaki
File size: 7274 byte(s)
[Mod] NSRuleEditorRowTypeCompoundの時もXspfMRuleを使用するように変更。
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 masaki 125
15     static NSString *XspfMREDPredicateRowsKey = @"predicateRows";
16    
17 masaki 124 - (NSDictionary *)buildRows:(NSArray *)template
18     {
19     NSMutableDictionary *result = [NSMutableDictionary dictionary];
20     for(id row in template) {
21 masaki 159 id name = [row valueForKey:@"name"];
22 masaki 152 id rule = [XspfMRule ruleWithPlist:row];
23     [result setObject:rule forKey:name];
24 masaki 124 }
25 masaki 152 rowTemplate = [result retain];
26 masaki 124 return result;
27     }
28 masaki 126 - (id)criteriaWithKeyPath:(NSString *)keypath
29     {
30     NSString *key = nil;
31     if([keypath isEqualToString:@"title"]) {
32     key = @"String";
33     } else if([keypath isEqualToString:@"rating"]) {
34     key = @"Rate";
35 masaki 152 } else if([[NSArray arrayWithObjects:@"lastPlayDate", @"modificationDate", @"creationDate", nil] containsObject:keypath]) {
36     key = @"AbDate";
37 masaki 126 }
38     if(key) {
39     id row = [rowTemplate valueForKey:key];
40 masaki 152 id c = [[[row childAtIndex:0] copy] autorelease];
41     [c setValue:keypath];
42 masaki 126 return [NSArray arrayWithObject:c];
43     }
44    
45     return nil;
46     }
47 masaki 120 - (void)awakeFromNib
48     {
49 masaki 166 // if(!compound) {
50     // compound = [[XspfMCompound alloc] init];
51     // }
52 masaki 152
53 masaki 124 NSBundle *m = [NSBundle mainBundle];
54     NSString *path = [m pathForResource:@"LibraryRowTemplate" ofType:@"plist"];
55     NSArray *rowsTemplate = [NSArray arrayWithContentsOfFile:path];
56     if(!rowsTemplate) {
57     exit(12345);
58 masaki 120 }
59 masaki 124
60 masaki 152 [self buildRows:rowsTemplate];
61    
62 masaki 124 NSMutableArray *newRows = [NSMutableArray array];
63    
64 masaki 126 id c = [self criteriaWithKeyPath:@"title"];
65     if(c) [newRows addObjectsFromArray:c];
66 masaki 124
67     for(id keyPath in [NSArray arrayWithObjects:@"lastPlayDate", @"modificationDate", @"creationDate", nil]) {
68 masaki 126 c = [self criteriaWithKeyPath:keyPath];
69     if(c) [newRows addObjectsFromArray:c];
70 masaki 124 }
71    
72 masaki 126 c = [self criteriaWithKeyPath:@"rating"];
73     if(c) [newRows addObjectsFromArray:c];
74 masaki 124
75 masaki 152 simples = [newRows retain];
76 masaki 166
77     compounds = [[XspfMRule compoundRule] retain];
78 masaki 152
79 masaki 125 ////
80     predicateRows = [[NSMutableArray alloc] init];
81 masaki 159 [ruleEditor bind:@"rows" toObject:self withKeyPath:XspfMREDPredicateRowsKey options:nil];
82 masaki 120 }
83    
84 masaki 150 - (void)resolveExpression:(id)exp
85     {
86     NSString *message = nil;
87    
88     switch([exp expressionType]) {
89     case NSConstantValueExpressionType:
90     message = [NSString stringWithFormat:@"constant -> %@", [exp constantValue]];
91     break;
92     case NSEvaluatedObjectExpressionType:
93     message = [NSString stringWithFormat:@"constant -> %@", [exp constantValue]];
94     break;
95     case NSVariableExpressionType:
96     message = [NSString stringWithFormat:@"variable -> %@", [exp variable]];
97     break;
98     case NSKeyPathExpressionType:
99     message = [NSString stringWithFormat:@"keyPath -> %@", [exp keyPath]];
100     break;
101     case NSFunctionExpressionType:
102 masaki 154 message = [NSString stringWithFormat:@"oprand -> %@(%@), function -> %@, arguments -> %@",
103 masaki 150 [exp operand], NSStringFromClass([[exp operand] class]),
104     [exp function], [exp arguments]];
105     break;
106     case NSAggregateExpressionType:
107     message = [NSString stringWithFormat:@"collection -> %@", [exp collection]];
108     break;
109     }
110    
111     fprintf(stderr, "%s\n", [message UTF8String]);
112     }
113     - (void)resolvePredicate:(id)predicate
114     {
115     if([predicate isKindOfClass:[NSCompoundPredicate class]]) {
116     NSArray *sub = [predicate subpredicates];
117     for(id p in sub) {
118     [self resolvePredicate:p];
119     }
120     } else if([predicate isKindOfClass:[NSComparisonPredicate class]]) {
121     id left = [predicate leftExpression];
122     id right = [predicate rightExpression];
123     SEL sel = Nil;
124     if([predicate predicateOperatorType] == NSCustomSelectorPredicateOperatorType) {
125     sel = [predicate customSelector];
126     }
127     fprintf(stderr, "left ->\t");
128     [self resolveExpression:left];
129     if(sel) {
130     fprintf(stderr, "%s\n", [[NSString stringWithFormat:@"SEL -> %@", NSStringFromSelector(sel)] UTF8String]);
131     } else {
132     fprintf(stderr, "%s\n", [[NSString stringWithFormat:@"type -> %d, opt -> %d, mod -> %d", [predicate predicateOperatorType], [predicate options], [predicate comparisonPredicateModifier]] UTF8String]);
133     }
134     fprintf(stderr, "right ->\t");
135     [self resolveExpression:right];
136     fprintf(stderr, "end resolve.\n");
137     }
138     }
139    
140 masaki 123 - (void)setPredicate:(id)predicate
141     {
142 masaki 150 NSLog(@"predicate -> (%@) %@", NSStringFromClass([predicate class]), predicate);
143     [self resolvePredicate:predicate];
144 masaki 123
145 masaki 153 id new = [XspfMRule ruleEditorRowsFromPredicate:predicate withRowTemplate:rowTemplate];
146 masaki 125
147     [self willChangeValueForKey:XspfMREDPredicateRowsKey];
148     [predicateRows release];
149     predicateRows = [new retain];
150     [self didChangeValueForKey:XspfMREDPredicateRowsKey];
151 masaki 146 // [ruleEditor reloadCriteria];
152 masaki 123 }
153 masaki 125 - (void)setPredicateRows:(id)p
154     {
155 masaki 147 // NSLog(@"new -> %@", p);
156 masaki 125 [predicateRows release];
157     predicateRows = [p retain];
158     }
159    
160     #pragma mark#### NSRleEditor Delegate ####
161 masaki 152
162 masaki 124 - (NSInteger)ruleEditor:(NSRuleEditor *)editor
163     numberOfChildrenForCriterion:(id)criterion
164     withRowType:(NSRuleEditorRowType)rowType
165     {
166     NSInteger result = 0;
167    
168 masaki 166 // if(rowType == NSRuleEditorRowTypeCompound) {
169     // return [compound numberOfChildrenForChild:criterion];
170     // }
171 masaki 143
172 masaki 124 if(!criterion) {
173 masaki 166 if(rowType == NSRuleEditorRowTypeCompound) {
174     result = [compounds count];
175     } else {
176     result = [simples count];
177     }
178 masaki 143 } else {
179 masaki 152 result = [criterion numberOfChildren];
180 masaki 124 }
181    
182 masaki 152 // NSLog(@"numner\tcriterion -> %@, type -> %d, result -> %d", criterion, rowType, result);
183 masaki 124
184     return result;
185     }
186    
187     - (id)ruleEditor:(NSRuleEditor *)editor
188     child:(NSInteger)index
189     forCriterion:(id)criterion
190     withRowType:(NSRuleEditorRowType)rowType
191     {
192     id result = nil;
193    
194 masaki 166 // if(rowType == NSRuleEditorRowTypeCompound) {
195     // return [compound childForChild:criterion atIndex:index];
196     // }
197 masaki 143
198 masaki 124 if(!criterion) {
199 masaki 166 if(rowType == NSRuleEditorRowTypeCompound) {
200     result = [compounds objectAtIndex:index];
201     } else {
202     result = [simples objectAtIndex:index];
203     }
204 masaki 143 } else {
205 masaki 152 result = [criterion childAtIndex:index];
206 masaki 124 }
207    
208 masaki 152 // NSLog(@"child\tindex -> %d, criterion -> %@, type -> %d, result -> %@", index, criterion, rowType, result);
209 masaki 124
210     return result;
211     }
212     - (id)ruleEditor:(NSRuleEditor *)editor
213     displayValueForCriterion:(id)criterion
214     inRow:(NSInteger)row
215     {
216     id result = nil;
217 masaki 143
218 masaki 166 // NSRuleEditorRowType rowType = [editor rowTypeForRow:row];
219     // if(rowType == NSRuleEditorRowTypeCompound) {
220     // return [compound displayValueForChild:criterion];
221     // }
222 masaki 143
223     if(!criterion) {
224     //
225     } else {
226 masaki 152 result = [criterion displayValueForRuleEditor:editor inRow:row];
227 masaki 143 }
228    
229 masaki 152 // NSLog(@"display\tcriterion -> %@, row -> %d, result -> %@", criterion, row, result);
230 masaki 143
231 masaki 124 return result;
232     }
233     - (NSDictionary *)ruleEditor:(NSRuleEditor *)editor
234     predicatePartsForCriterion:(id)criterion
235     withDisplayValue:(id)displayValue
236     inRow:(NSInteger)row
237     {
238     id result = nil;
239    
240 masaki 166 // NSRuleEditorRowType rowType = [editor rowTypeForRow:row];
241     // if(rowType == NSRuleEditorRowTypeCompound) {
242     // return [compound predicateForChild:criterion withDisplayValue:displayValue];
243     // }
244 masaki 143
245 masaki 152 result = [criterion predicatePartsWithDisplayValue:displayValue forRuleEditor:editor inRow:row];
246 masaki 153 // NSLog(@"predicate\tresult -> %@", result);
247 masaki 143
248 masaki 152 // NSLog(@"predicate\tcriterion -> %@, value -> %@, row -> %d, result -> %@", criterion, displayValue, row, result);
249 masaki 143
250 masaki 124 return result;
251     }
252     - (void)ruleEditorRowsDidChange:(NSNotification *)notification
253     {
254     //
255     }
256 masaki 150 @end

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26