Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfManager/XspfMRuleEditorDelegate.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 123 - (hide annotations) (download)
Mon Nov 30 13:43:48 2009 UTC (14 years, 4 months ago) by masaki
File size: 4496 byte(s)
[???] RuleEditorテスト中 :-)
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 masaki 123 - (void)showPredicate:(id)predicate
37     {
38     if([predicate isKindOfClass:[NSCompoundPredicate class]]) {
39     NSArray *sub = [predicate subpredicates];
40     NSLog(@"-> %d(%d)\n|\n-->",[predicate compoundPredicateType], [sub count]);
41     for(id p in sub) {
42     if([p isKindOfClass:[NSCompoundPredicate class]]) {
43     [self showPredicate:p];
44     } else if([p isKindOfClass:[NSComparisonPredicate class]]) {
45     NSLog(@"--> (Comparision) ope->%d, mod->%d, left->%@, right->%@, SEL->%s, opt->%u",
46     [p predicateOperatorType], [p comparisonPredicateModifier],
47     [p leftExpression], [p rightExpression],
48     [p customSelector], [p options]);
49     } else if([p isKindOfClass:[NSPredicate class]]) {
50     NSLog(@"--> %@", p);
51     } else {
52     NSLog(@"predicate class is %@", NSStringFromClass([p class]));
53     }
54     }
55     } else {
56     NSLog(@"???predicate class is %@", NSStringFromClass([predicate class]));
57     }
58     }
59     - (void)setPredicate:(id)predicate
60     {
61     NSLog(@"predicate -> %@", predicate);
62     // NSLog(@"Predicate class is %@", [predicate class]);
63    
64     [self showPredicate:predicate];
65     }
66 masaki 120 #pragma mark#### NSRuleEditor Delegate ####
67     - (NSInteger)ruleEditor:(NSRuleEditor *)editor
68     numberOfChildrenForCriterion:(id)criterion
69     withRowType:(NSRuleEditorRowType)rowType
70     {
71     NSInteger result = 0;
72    
73     if(rowType == NSRuleEditorRowTypeCompound) {
74     result = [compound numberOfChildrenForChild:criterion];
75     goto end;
76     }
77    
78     if(!criterion) {
79     result = [simples count];
80     goto end;
81     return result;
82     }
83    
84     for(id s in simples) {
85     if([s isMyChild:criterion]) result += [s numberOfChildrenForChild:criterion];
86     }
87    
88     end:
89     // NSLog(@"numner\tcriterion -> %@, type -> %d, result -> %d", criterion, rowType, result);
90    
91     return result;
92     }
93     - (id)ruleEditor:(NSRuleEditor *)editor
94     child:(NSInteger)index
95     forCriterion:(id)criterion
96     withRowType:(NSRuleEditorRowType)rowType
97     {
98     id result = nil;
99    
100     if(rowType == NSRuleEditorRowTypeCompound) {
101     result = [compound childForChild:criterion atIndex:index];
102     goto end;
103     }
104    
105     if(!criterion) {
106     id s = [simples objectAtIndex:index];
107     result = [s childForChild:criterion atIndex:index];
108     goto end;
109     }
110    
111     for(id s in simples) {
112     if([s isMyChild:criterion]) {
113     result = [s childForChild:criterion atIndex:index];
114     goto end;
115     }
116     }
117    
118     end:
119     // NSLog(@"child\tindex -> %d, criterion -> %@, type -> %d, result -> %@", index, criterion, rowType, result);
120    
121     return result;
122     }
123     - (id)ruleEditor:(NSRuleEditor *)editor
124     displayValueForCriterion:(id)criterion
125     inRow:(NSInteger)row
126     {
127     id result = nil;
128    
129     NSRuleEditorRowType rowType = [editor rowTypeForRow:row];
130     if(rowType == NSRuleEditorRowTypeCompound) {
131     result = [compound displayValueForChild:criterion];
132     goto end;
133     }
134    
135     for(id s in simples) {
136     if([s isMyChild:criterion]) {
137     result = [s displayValueForChild:criterion];
138     goto end;
139     }
140     }
141    
142     end:
143     // NSLog(@"display\tcriterion -> %@, row -> %d, result -> %@", criterion, row, result);
144     return result;
145     }
146    
147 masaki 121 - (NSDictionary *)ruleEditor:(NSRuleEditor *)editor
148     predicatePartsForCriterion:(id)criterion
149     withDisplayValue:(id)value
150     inRow:(NSInteger)row
151     {
152     id result = nil;
153    
154     NSRuleEditorRowType rowType = [editor rowTypeForRow:row];
155     if(rowType == NSRuleEditorRowTypeCompound) {
156     result = [compound predicateForChild:criterion withDisplayValue:value];
157     goto end;
158     }
159    
160     for(id s in simples) {
161     if([s isMyChild:criterion]) {
162     result = [s predicateForChild:criterion withDisplayValue:value];
163     goto end;
164     }
165     }
166    
167     end:
168     // NSLog(@"predicate\tcriterion -> %@, value -> %@, row -> %d, result -> %@", criterion, value, row, result);
169    
170     return result;
171     }
172 masaki 120 @end

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