Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfManager/XspfMRuleEditorDelegate.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 138 - (hide annotations) (download)
Wed Dec 9 13:14:05 2009 UTC (14 years, 4 months ago) by masaki
File size: 21420 byte(s)
[???] NSRuleEditorテスト中
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 *XspfMREDRowsKey = @"rows";
16     static NSString *XspfMREDCriteriaKey = @"criteria";
17     static NSString *XspfMREDDisplayValuesKey = @"displayValues";
18     static NSString *XspfMREDRowTypeKey = @"rowType";
19     static NSString *XspfMREDSubrowsKey = @"subrows";
20     static NSString *XspfMREDValueKey = @"value";
21     static NSString *XspfMREDPredicateRowsKey = @"predicateRows";
22     static NSString *XspfMREDNameKey = @"name";
23    
24     static NSString *XspfMStringPredicateIsEqualOperator = @"is";
25     static NSString *XspfMStringPredicateIsNotEqualOperator = @"is not";
26     static NSString *XspfMStringPredicateContainsOperator = @"contains";
27     static NSString *XspfMStringPredicateBeginsWithOperator = @"begins with";
28     static NSString *XspfMStringPredicateEndsWithOperator = @"ends with";
29    
30     //static NSString *XspfMAbDatePredicatePicker01 = @"date";
31     //static NSString *XspfMAbDatePredicatePicker02 = @"beginDate";
32     //static NSString *XspfMAbDatePredicatePicker03 = @"endDate";
33     //static NSString *XspfMAbDatePredicateIsEqualOperator = @"is the date";
34     //static NSString *XspfMAbDatePredicateLessThanOperator = @"is after the date";
35     //static NSString *XspfMAbDatePredicateGreaterThanOperator = @"is before the date";
36     //static NSString *XspfMAbDatePredicateBetweenOperator = @"is in the range";
37     //static NSString *XspfMAbDatePredicateAndField = @"andField";
38    
39    
40 masaki 137 - (NSExpression *)rangeUnitFromDisplayValues:(NSArray *)displayValues option:(NSNumber *)optionValue
41     {
42     NSInteger option = [optionValue integerValue];
43    
44     NSString *variable = nil;
45     id value02 = [displayValues objectAtIndex:2];
46     id value03 = [displayValues objectAtIndex:3];
47     id value04 = nil, value05 = nil;
48     switch(option) {
49     case 0:
50 masaki 138 variable = [NSString stringWithFormat:@"%d-%@-ago", [value02 intValue], value03];
51 masaki 137 break;
52     case 1:
53 masaki 138 variable = [NSString stringWithFormat:@"%d-%@", [value02 intValue], value03];
54     break;
55 masaki 137 case 2:
56 masaki 138 variable = [NSString stringWithFormat:@"not-%d-%@", [value02 intValue], value03];
57 masaki 137 break;
58     case 3:
59     value04 = [displayValues objectAtIndex:4];
60     value05 = [displayValues objectAtIndex:5];
61 masaki 138 variable = [NSString stringWithFormat:@"%d-%@-%d-%@", [value02 intValue], value03, [value04 intValue], value05];
62 masaki 137 break;
63     }
64    
65     return [NSExpression expressionForVariable:variable];
66     }
67 masaki 124 - (NSExpression *)rangeDateFromDisplayValues:(NSArray *)displayValues
68     {
69     id field01 = nil;
70     id field02 = nil;
71    
72     Class datepickerclass = [NSDatePicker class];
73     for(id v in displayValues) {
74     if([v isKindOfClass:datepickerclass]) {
75     if([v tag] == 0) {
76     field01 = v;
77     } else {
78     field02 = v;
79     }
80     }
81     }
82    
83     if(!field01 || !field02) return nil;
84    
85     id value01, value02;
86     value01 = [field01 dateValue]; value02 = [field02 dateValue];
87     if([value01 compare:value02] == NSOrderedDescending) {
88     id t = value02;
89     value02 = value01;
90     value01 = t;
91     }
92    
93     id expression01, expression02;
94 masaki 133 expression01 = [NSExpression expressionForConstantValue:value01];
95     expression02 = [NSExpression expressionForConstantValue:value02];
96 masaki 124
97     return [NSExpression expressionForAggregate:[NSArray arrayWithObjects:expression01, expression02, nil]];
98     }
99 masaki 132 - (NSExpression *)relatedDate:(NSNumber *)typeValue
100     {
101     NSString *variable = nil;
102     NSInteger type = [typeValue integerValue];
103     switch(type) {
104     case 0:
105     variable = @"TODAY";
106     break;
107     case 1:
108     variable = @"YESTERDAY";
109     break;
110     case 2:
111     variable = @"THISWEEK";
112     break;
113     case 3:
114     variable = @"LASTWEEK";
115     break;
116     }
117    
118     return [NSExpression expressionForVariable:variable];
119     }
120    
121 masaki 124 - (NSView *)textField
122     {
123     id text = [[[NSTextField alloc] initWithFrame:NSMakeRect(0,0,100,19)] autorelease];
124     [[text cell] setControlSize:NSSmallControlSize];
125     [text setFont:[NSFont controlContentFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
126 masaki 126 [text setStringValue:@"1234567890"];
127 masaki 124 [text sizeToFit];
128     [text setStringValue:@""];
129     [text setDelegate:self];
130    
131     return text;
132     }
133     - (NSView *)datePicker
134     {
135     id date = [[[NSDatePicker alloc] initWithFrame:NSMakeRect(0,0,100,19)] autorelease];
136     [[date cell] setControlSize:NSSmallControlSize];
137     [date setFont:[NSFont controlContentFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
138     [date setDatePickerElements:NSYearMonthDayDatePickerElementFlag];
139     [date setDrawsBackground:YES];
140     [date setDateValue:[NSDate dateWithTimeIntervalSinceNow:0.0]];
141     [date sizeToFit];
142     [date setDelegate:self];
143    
144     return date;
145     }
146     - (NSView *)ratingIndicator
147     {
148     id rate = [[[NSLevelIndicator alloc] initWithFrame:NSMakeRect(0,0,100,19)] autorelease];
149     id cell = [rate cell];
150     [cell setControlSize:NSSmallControlSize];
151     [rate setFont:[NSFont controlContentFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
152     [rate setMinValue:0];
153     [rate setMaxValue:5];
154     [cell setLevelIndicatorStyle:NSRatingLevelIndicatorStyle];
155     [cell setEditable:YES];
156     [rate sizeToFit];
157    
158     return rate;
159     }
160     - (NSView *)numberField
161     {
162 masaki 134 id text = [[[NSTextField alloc] initWithFrame:NSMakeRect(0,0,100,19)] autorelease];
163     [[text cell] setControlSize:NSSmallControlSize];
164     [text setFont:[NSFont controlContentFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
165     [text setStringValue:@"123"];
166     NSNumberFormatter *formatter = [[[NSNumberFormatter alloc] init] autorelease];
167     [formatter setNumberStyle:NSNumberFormatterDecimalStyle];
168     [formatter setMinimum:[NSNumber numberWithInt:0]];
169     [text setFormatter:formatter];
170     [text sizeToFit];
171     [text setStringValue:@"1"];
172     [text setDelegate:self];
173    
174     return text;
175 masaki 124 }
176    
177 masaki 128
178 masaki 124 - (NSDictionary *)buildRows:(NSArray *)template
179     {
180     NSMutableDictionary *result = [NSMutableDictionary dictionary];
181     for(id row in template) {
182 masaki 125 id criteria = [row valueForKey:XspfMREDCriteriaKey];
183     id name = [row valueForKey:XspfMREDNameKey];
184 masaki 124 [result setObject:criteria forKey:name];
185     }
186    
187     return result;
188     }
189 masaki 126 - (id)criteriaWithKeyPath:(NSString *)keypath
190     {
191     NSString *key = nil;
192     if([keypath isEqualToString:@"title"]) {
193     key = @"String";
194     } else if([keypath isEqualToString:@"rating"]) {
195     key = @"Rate";
196     }
197     if(key) {
198     id row = [rowTemplate valueForKey:key];
199 masaki 133 id c = [[[row objectAtIndex:0] mutableCopy] autorelease];
200 masaki 126 [c setValue:keypath forKey:XspfMREDValueKey];
201     return [NSArray arrayWithObject:c];
202     }
203    
204     if([[NSArray arrayWithObjects:@"lastPlayDate", @"modificationDate", @"creationDate", nil] containsObject:keypath]) {
205 masaki 132 id keys = [NSArray arrayWithObjects:@"AbDate", /*@"RlDate",*/ nil];
206 masaki 126 id result = [NSMutableArray array];
207     for(key in keys) {
208     id row = [rowTemplate valueForKey:key];
209 masaki 133 id c = [[[row objectAtIndex:0] mutableCopy] autorelease];
210 masaki 126 [c setValue:keypath forKey:XspfMREDValueKey];
211     [result addObject:c];
212     }
213    
214     return result;
215     }
216    
217     return nil;
218     }
219 masaki 120 - (void)awakeFromNib
220     {
221     if(!compound) {
222     compound = [[XspfMCompound alloc] init];
223     }
224 masaki 124
225     rowIDs = [[NSMutableArray array] retain];
226     rowFields = [[NSMutableDictionary dictionary] retain];
227    
228     NSBundle *m = [NSBundle mainBundle];
229     NSString *path = [m pathForResource:@"LibraryRowTemplate" ofType:@"plist"];
230     NSArray *rowsTemplate = [NSArray arrayWithContentsOfFile:path];
231     if(!rowsTemplate) {
232     exit(12345);
233 masaki 120 }
234 masaki 124
235     rowTemplate = [[self buildRows:rowsTemplate] retain];
236    
237     // NSLog(@"rowTemplate =>\n%@", rowTemplate);
238    
239     NSMutableArray *newRows = [NSMutableArray array];
240    
241 masaki 126 id c = [self criteriaWithKeyPath:@"title"];
242     if(c) [newRows addObjectsFromArray:c];
243 masaki 124
244     for(id keyPath in [NSArray arrayWithObjects:@"lastPlayDate", @"modificationDate", @"creationDate", nil]) {
245 masaki 126 c = [self criteriaWithKeyPath:keyPath];
246     if(c) [newRows addObjectsFromArray:c];
247 masaki 124 }
248    
249 masaki 126 c = [self criteriaWithKeyPath:@"rating"];
250     if(c) [newRows addObjectsFromArray:c];
251 masaki 124
252     rows = [newRows retain];
253 masaki 125
254    
255    
256     ////
257     predicateRows = [[NSMutableArray alloc] init];
258     [ruleEditor bind:XspfMREDRowsKey toObject:self withKeyPath:XspfMREDPredicateRowsKey options:nil];
259 masaki 120 }
260    
261 masaki 127 - (NSArray *)displayValuesWithPredicate:(NSComparisonPredicate *)predicate
262     {
263     id value02 = nil; id value03 = nil;
264     id leftKeyPath = [[predicate leftExpression] keyPath];
265    
266     switch([predicate predicateOperatorType]) {
267     case NSEqualToPredicateOperatorType:
268     value02 = XspfMStringPredicateIsEqualOperator;
269     break;
270     case NSNotEqualToPredicateOperatorType:
271     value02 = XspfMStringPredicateIsNotEqualOperator;
272     break;
273     case NSContainsPredicateOperatorType:
274     value02 = XspfMStringPredicateContainsOperator;
275     break;
276     case NSBeginsWithPredicateOperatorType:
277     value02 = XspfMStringPredicateBeginsWithOperator;
278     break;
279     case NSEndsWithPredicateOperatorType:
280     value02 = XspfMStringPredicateEndsWithOperator;
281     break;
282     }
283     id rightConstant = [[predicate rightExpression] constantValue];
284     value03 = [self textField];
285     [value03 setObjectValue:rightConstant];
286    
287     id disp = [NSArray arrayWithObjects:leftKeyPath, value02, value03, nil];
288    
289     return disp;
290     }
291     - (NSArray *)ratingDisplayValuesWithPredicate:(NSComparisonPredicate *)predicate
292     {
293     id value02 = nil; id value03 = nil;
294     id leftKeyPath = [[predicate leftExpression] keyPath];
295    
296     switch([predicate predicateOperatorType]) {
297     case NSEqualToPredicateOperatorType:
298     value02 = XspfMStringPredicateIsEqualOperator;
299     break;
300     case NSGreaterThanPredicateOperatorType:
301     value02 = @"is greater than";
302     break;
303     case NSLessThanPredicateOperatorType:
304     value02 = @"is less than";
305     break;
306     }
307     id rightConstant = [[predicate rightExpression] constantValue];
308     value03 = [self ratingIndicator];
309     [value03 setObjectValue:rightConstant];
310    
311     id disp = [NSArray arrayWithObjects:leftKeyPath, value02, value03, nil];
312    
313     return disp;
314     }
315 masaki 138 - (void)resolveVariable:(NSString *)variable value02:(id *)value02 value03:(id *)value03 value04:(id *)value04 value05:(id *)value05 value06:(id *)value06 value07:(id *)value07
316     {
317     NSArray *words = [variable componentsSeparatedByString:@"-"];
318    
319     switch([words count]) {
320     case 2:
321     *value02 = @"is in the last";
322     *value03 = [self numberField];
323     [*value03 setTag:2000];
324     [*value03 setStringValue:[words objectAtIndex:0]];
325     *value04 = [words objectAtIndex:1];
326     break;
327     case 3:
328     if([[words objectAtIndex:0] isEqualToString:@"not"]) {
329     *value02 = @"is not in the last";
330     *value03 = [self numberField];
331     [*value03 setTag:2000];
332     [*value03 setStringValue:[words objectAtIndex:1]];
333     *value04 = [words objectAtIndex:2];
334     } else {
335     *value02 = @"is exactly";
336     *value03 = [self numberField];
337     [*value03 setTag:2000];
338     [*value03 setStringValue:[words objectAtIndex:0]];
339     *value04 = [words objectAtIndex:1];
340     *value05 = @"ago";
341     }
342     break;
343     case 4:
344     *value02 = @"is between";
345     *value03 = [self numberField];
346     [*value03 setTag:2000];
347     [*value03 setStringValue:[words objectAtIndex:0]];
348     *value04 = @"and";
349     *value05 = [self numberField];
350     [*value05 setTag:2100];
351     [*value05 setStringValue:[words objectAtIndex:2]];
352     *value06 = [words objectAtIndex:3];
353     *value07 = @"ago";
354     break;
355     }
356     }
357    
358 masaki 132 - (NSArray *)dateRangeDisplayValuesWithPredicate:(NSComparisonPredicate *)predicate
359     {
360     id leftKeyPath = [[predicate leftExpression] keyPath];
361     id rightVar = [[predicate rightExpression] variable];
362    
363     id value02 = nil;
364     id value03 = nil;
365     id value04 = nil;
366     id value05 = nil;
367     id value06 = nil;
368     id value07 = nil;
369    
370     if([rightVar isEqualToString:@"TODAY"]) {
371     value02 = @"is today";
372     } else if([rightVar isEqualToString:@"YESTERDAY"]) {
373     value02 = @"is yesterday";
374     } else if([rightVar isEqualToString:@"THISWEEK"]) {
375     value02 = @"is this week";
376     } else if([rightVar isEqualToString:@"LASTWEEK"]) {
377     value02 = @"is last week";
378 masaki 138 } else {
379     [self resolveVariable:rightVar value02:&value02 value03:&value03 value04:&value04 value05:&value05 value06:&value06 value07:&value07];
380 masaki 132 }
381    
382     return [NSArray arrayWithObjects:leftKeyPath, value02, value03, value04, value05, value06, value07, nil];
383     }
384    
385 masaki 127 - (NSArray *)dateDisplayValuesWithPredicate:(NSComparisonPredicate *)predicate
386     {
387     id value02 = nil; id value03 = nil;
388     id leftKeyPath = [[predicate leftExpression] keyPath];
389    
390     switch([predicate predicateOperatorType]) {
391     case NSEqualToPredicateOperatorType:
392     value02 = @"is the date";
393     break;
394     case NSGreaterThanPredicateOperatorType:
395     value02 = @"is after the date";
396     break;
397     case NSLessThanPredicateOperatorType:
398     value02 = @"is before the date";
399     break;
400     case NSBetweenPredicateOperatorType:
401     return [self dateRangeDisplayValuesWithPredicate:predicate];
402    
403     }
404     id rightConstant = [[predicate rightExpression] constantValue];
405     value03 = [self datePicker];
406     [value03 setObjectValue:rightConstant];
407    
408     id disp = [NSArray arrayWithObjects:leftKeyPath, value02, value03, nil];
409    
410     return disp;
411     }
412    
413 masaki 125 - (id)buildRowsFromPredicate:(id)predicate
414     {
415     if([predicate isKindOfClass:[NSCompoundPredicate class]]) {
416     id subrows = [NSMutableArray array];
417    
418     id value = nil;
419     switch([predicate compoundPredicateType]) {
420     case NSNotPredicateType:
421     // ?
422     break;
423     case NSAndPredicateType:
424     value = @"All";
425     break;
426     case NSOrPredicateType:
427     value = @"Any";
428     break;
429     }
430    
431     NSArray *sub = [predicate subpredicates];
432     for(id p in sub) {
433     [subrows addObject:[self buildRowsFromPredicate:p]];
434     }
435    
436     id criteria = [NSArray arrayWithObjects:value, @"of the following are true", nil];
437 masaki 127 id type = [NSNumber numberWithInt:NSRuleEditorRowTypeCompound];
438 masaki 125
439     id result = [NSMutableDictionary dictionaryWithObjectsAndKeys:
440     criteria, XspfMREDCriteriaKey,
441     criteria, XspfMREDDisplayValuesKey,
442     type, XspfMREDRowTypeKey,
443     subrows, XspfMREDSubrowsKey,
444     nil];
445    
446     return result;
447     } else if([predicate isKindOfClass:[NSComparisonPredicate class]]) {
448     id leftKeyPath = [[predicate leftExpression] keyPath];
449     if(!leftKeyPath) return [NSArray array];
450 masaki 128
451     NSArray *disp = nil;
452 masaki 127 if([leftKeyPath isEqualToString:@"title"]) {
453 masaki 128 disp = [self displayValuesWithPredicate:predicate];
454 masaki 125 }
455 masaki 127 if([leftKeyPath isEqualToString:@"rating"]) {
456 masaki 128 disp = [self ratingDisplayValuesWithPredicate:predicate];
457 masaki 127 }
458 masaki 132 if([[NSArray arrayWithObjects:@"lastPlayDate", @"modificationDate", @"creationDate", nil] containsObject:leftKeyPath]) {
459 masaki 128 disp = [self dateDisplayValuesWithPredicate:predicate];
460 masaki 138 NSLog(@"dispalyValues -> %@", disp);
461 masaki 128 }
462    
463     if(disp) {
464 masaki 127 NSArray *row = [self criteriaWithKeyPath:leftKeyPath];
465     NSMutableDictionary *criterion = [NSMutableDictionary dictionaryWithObjectsAndKeys:
466     row, XspfMREDCriteriaKey,
467     disp, XspfMREDDisplayValuesKey,
468     [NSNumber numberWithInt:NSRuleEditorRowTypeSimple], XspfMREDRowTypeKey,
469     nil];
470     return criterion;
471     }
472 masaki 125
473     } else if([predicate isKindOfClass:[NSPredicate class]]) {
474     NSLog(@"--> %@", predicate);
475     } else {
476     NSLog(@"???predicate class is %@", NSStringFromClass([predicate class]));
477     }
478    
479     return [NSArray array];
480     }
481 masaki 123 - (void)setPredicate:(id)predicate
482     {
483 masaki 126 NSLog(@"predicate -> (%@) %@", NSStringFromClass([predicate class]), predicate);
484 masaki 123
485 masaki 125 id hoge = [self buildRowsFromPredicate:predicate];
486     id new = [NSArray arrayWithObject:hoge];
487    
488     [self willChangeValueForKey:XspfMREDPredicateRowsKey];
489     [predicateRows release];
490     predicateRows = [new retain];
491     [self didChangeValueForKey:XspfMREDPredicateRowsKey];
492     [ruleEditor reloadCriteria];
493 masaki 123 }
494 masaki 125 - (void)setPredicateRows:(id)p
495     {
496     NSLog(@"new -> %@", p);
497     [predicateRows release];
498     predicateRows = [p retain];
499     }
500    
501     #pragma mark#### NSRleEditor Delegate ####
502 masaki 124 - (NSInteger)ruleEditor:(NSRuleEditor *)editor
503     numberOfChildrenForCriterion:(id)criterion
504     withRowType:(NSRuleEditorRowType)rowType
505     {
506     NSInteger result = 0;
507    
508     if(rowType == NSRuleEditorRowTypeCompound) {
509     return [compound numberOfChildrenForChild:criterion];
510     }
511    
512     if(!criterion) {
513     result = [rows count];
514     } else {
515 masaki 125 result = [[criterion valueForKey:XspfMREDCriteriaKey] count];
516 masaki 124 }
517    
518     // NSLog(@"numner\tcriterion -> %@, type -> %d, result -> %d", criterion, rowType, result);
519    
520     return result;
521     }
522    
523     - (id)ruleEditor:(NSRuleEditor *)editor
524     child:(NSInteger)index
525     forCriterion:(id)criterion
526     withRowType:(NSRuleEditorRowType)rowType
527     {
528     id result = nil;
529    
530     if(rowType == NSRuleEditorRowTypeCompound) {
531     return [compound childForChild:criterion atIndex:index];
532     }
533    
534     if(!criterion) {
535     result = [rows objectAtIndex:index];
536     } else {
537 masaki 125 result = [[criterion valueForKey:XspfMREDCriteriaKey] objectAtIndex:index];
538 masaki 124 }
539    
540     // NSLog(@"child\tindex -> %d, criterion -> %@, type -> %d, result -> %@", index, criterion, rowType, result);
541    
542     return result;
543     }
544     - (id)ruleEditor:(NSRuleEditor *)editor
545     displayValueForCriterion:(id)criterion
546     inRow:(NSInteger)row
547     {
548     id result = nil;
549    
550     NSRuleEditorRowType rowType = [editor rowTypeForRow:row];
551     if(rowType == NSRuleEditorRowTypeCompound) {
552     return [compound displayValueForChild:criterion];
553     }
554    
555     if(!criterion) {
556     //
557     } else {
558 masaki 125 result = [criterion valueForKey:XspfMREDValueKey];
559 masaki 124 }
560    
561 masaki 132 if([result isEqualToString:@"separator"]) {
562     return [NSMenuItem separatorItem];
563     }
564    
565 masaki 124 // create or find field object.
566     do {
567     Class searchClass = Nil;
568     SEL defaultSEL = Nil;
569     NSInteger tag = 0;
570    
571 masaki 125 if([result hasPrefix:@"textField"]) {
572 masaki 124 searchClass = [NSTextField class];
573     defaultSEL = @selector(textField);
574     } else if([result hasPrefix:@"dateField"]) {
575     searchClass = [NSDatePicker class];
576     defaultSEL = @selector(datePicker);
577     if(![result isEqualToString:@"dateField"]) { // result == dateField02
578     tag = 1000;
579     }
580     } else if([result hasPrefix:@"rateField"]) {
581     searchClass = [NSLevelIndicator class];
582     defaultSEL = @selector(ratingIndicator);
583 masaki 134 } else if([result hasPrefix:@"numberField"]) {
584     searchClass = [NSTextField class];
585     defaultSEL = @selector(numberField);
586     if([result isEqualToString:@"numberField"]) {
587     tag = 2000;
588     } else { // result == numberField02
589     tag = 2100;
590     }
591 masaki 124 }
592     if(!searchClass) break;
593    
594     id displayValues = [editor displayValuesForRow:row];
595     id field = nil;
596     for(id v in displayValues) {
597     if([v isKindOfClass:searchClass] && [v tag] == tag) {
598     field = v;
599     }
600     }
601     result = field ? field :[self performSelector:defaultSEL];
602     if(tag != 0) [result setTag:tag];
603     } while(NO);
604    
605     // NSLog(@"display\tcriterion -> %@, row -> %d, result -> %@", criterion, row, result);
606    
607     return result;
608     }
609     - (NSDictionary *)ruleEditor:(NSRuleEditor *)editor
610     predicatePartsForCriterion:(id)criterion
611     withDisplayValue:(id)displayValue
612     inRow:(NSInteger)row
613     {
614     id result = nil;
615    
616     NSRuleEditorRowType rowType = [editor rowTypeForRow:row];
617     if(rowType == NSRuleEditorRowTypeCompound) {
618     return [compound predicateForChild:criterion withDisplayValue:displayValue];
619     }
620    
621 masaki 132 if([criterion valueForKey:@"XspfMIgnoreExpression"]) return nil;
622    
623 masaki 124 result = [NSMutableDictionary dictionary];
624 masaki 132
625 masaki 124 if([criterion valueForKey:@"NSRuleEditorPredicateOperatorType"]) {
626     [result setValue:[criterion valueForKey:@"NSRuleEditorPredicateOperatorType"] forKey:@"NSRuleEditorPredicateOperatorType"];
627     }
628     if([criterion valueForKey:@"NSRuleEditorPredicateOptions"]) {
629     [result setValue:[criterion valueForKey:@"NSRuleEditorPredicateOptions"] forKey:@"NSRuleEditorPredicateOptions"];
630     }
631     if([criterion valueForKey:@"NSRuleEditorPredicateLeftExpression"]) {
632     id value = [criterion valueForKey:@"NSRuleEditorPredicateLeftExpression"];
633     id exp = nil;
634 masaki 125 if([value isEqual:XspfMREDValueKey]) {
635 masaki 124 exp = [NSExpression expressionForKeyPath:displayValue];
636     } else {
637     exp = [NSExpression expressionForKeyPath:[criterion valueForKey:@"NSRuleEditorPredicateLeft"]];
638     }
639     if(exp) {
640     [result setValue:exp forKey:@"NSRuleEditorPredicateLeftExpression"];
641     }
642     }
643     if([criterion valueForKey:@"NSRuleEditorPredicateRightExpression"]) {
644     id selector = [criterion valueForKey:@"NSRuleEditorPredicateRightExpression"];
645     id exp = nil;
646     if(NSSelectorFromString(selector)) {
647     exp = [NSExpression expressionForConstantValue:[displayValue performSelector:NSSelectorFromString(selector)]];
648     } else {
649     exp = [NSExpression expressionForConstantValue:[criterion valueForKey:@"NSRuleEditorPredicateRightExpression"]];
650     }
651     if(exp) {
652     [result setValue:exp forKey:@"NSRuleEditorPredicateRightExpression"];
653     }
654     }
655     if([criterion valueForKey:@"XspfMPredicateRightExpression"]) {
656     SEL selector = NSSelectorFromString([criterion valueForKey:@"XspfMPredicateRightExpression"]);
657     id arg01 = [criterion valueForKey:@"XspfMRightExpressionArg01"];
658 masaki 137 id arg02 = [criterion valueForKey:@"XspfMRightExpressionArg02"];
659 masaki 124
660 masaki 137
661     if(arg02 && arg01) {
662 masaki 132 if([arg01 isEqual:XspfMREDDisplayValuesKey]) {
663 masaki 124 arg01 = [editor displayValuesForRow:row];
664     }
665 masaki 137 if([arg02 isEqual:XspfMREDDisplayValuesKey]) {
666     arg02 = [editor displayValuesForRow:row];
667     }
668     id r = [self performSelector:selector withObject:arg01 withObject:arg02];
669     [result setValue:r forKey:@"NSRuleEditorPredicateRightExpression"];
670     } else if(arg01) {
671     if([arg01 isEqual:XspfMREDDisplayValuesKey]) {
672     arg01 = [editor displayValuesForRow:row];
673     }
674 masaki 124 id r = [self performSelector:selector withObject:arg01];
675     [result setValue:r forKey:@"NSRuleEditorPredicateRightExpression"];
676     } else {
677     id r = [self performSelector:selector];
678     [result setValue:r forKey:@"NSRuleEditorPredicateRightExpression"];
679     }
680     }
681    
682 masaki 125 // NSLog(@"predicate\tcriterion -> %@, value -> %@, row -> %d, result -> %@", criterion, displayValue, row, result);
683 masaki 124
684     return result;
685     }
686     - (void)ruleEditorRowsDidChange:(NSNotification *)notification
687     {
688     //
689     }
690    
691 masaki 120 @end

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