Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfManager/XspfMRuleEditorDelegate.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 338 - (hide annotations) (download)
Sun Feb 14 15:18:05 2010 UTC (14 years, 2 months ago) by masaki
File size: 6261 byte(s)
[Mod] ライブラリの条件変更に必要な項目を一カ所に集約した。
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 masaki 338 NSString *key = [XspfMRule templateKeyForLeftKeyPath:keypath];
31 masaki 126 if(key) {
32     id row = [rowTemplate valueForKey:key];
33 masaki 152 id c = [[[row childAtIndex:0] copy] autorelease];
34     [c setValue:keypath];
35 masaki 126 return [NSArray arrayWithObject:c];
36     }
37    
38     return nil;
39     }
40 masaki 120 - (void)awakeFromNib
41     {
42 masaki 124 NSBundle *m = [NSBundle mainBundle];
43     NSString *path = [m pathForResource:@"LibraryRowTemplate" ofType:@"plist"];
44     NSArray *rowsTemplate = [NSArray arrayWithContentsOfFile:path];
45     if(!rowsTemplate) {
46     exit(12345);
47 masaki 120 }
48 masaki 124
49 masaki 152 [self buildRows:rowsTemplate];
50    
51 masaki 124 NSMutableArray *newRows = [NSMutableArray array];
52    
53 masaki 338 for(id keyPath in [XspfMRule leftKeys]) {
54 masaki 243 id c = [self criteriaWithKeyPath:keyPath];
55 masaki 126 if(c) [newRows addObjectsFromArray:c];
56 masaki 124 }
57 masaki 243
58 masaki 152 simples = [newRows retain];
59 masaki 166
60     compounds = [[XspfMRule compoundRule] retain];
61 masaki 152
62 masaki 125 ////
63     predicateRows = [[NSMutableArray alloc] init];
64 masaki 159 [ruleEditor bind:@"rows" toObject:self withKeyPath:XspfMREDPredicateRowsKey options:nil];
65 masaki 120 }
66    
67 masaki 150 - (void)resolveExpression:(id)exp
68     {
69     NSString *message = nil;
70    
71     switch([exp expressionType]) {
72     case NSConstantValueExpressionType:
73     message = [NSString stringWithFormat:@"constant -> %@", [exp constantValue]];
74     break;
75     case NSEvaluatedObjectExpressionType:
76     message = [NSString stringWithFormat:@"constant -> %@", [exp constantValue]];
77     break;
78     case NSVariableExpressionType:
79     message = [NSString stringWithFormat:@"variable -> %@", [exp variable]];
80     break;
81     case NSKeyPathExpressionType:
82     message = [NSString stringWithFormat:@"keyPath -> %@", [exp keyPath]];
83     break;
84     case NSFunctionExpressionType:
85 masaki 154 message = [NSString stringWithFormat:@"oprand -> %@(%@), function -> %@, arguments -> %@",
86 masaki 150 [exp operand], NSStringFromClass([[exp operand] class]),
87     [exp function], [exp arguments]];
88     break;
89     case NSAggregateExpressionType:
90     message = [NSString stringWithFormat:@"collection -> %@", [exp collection]];
91     break;
92     }
93    
94     fprintf(stderr, "%s\n", [message UTF8String]);
95     }
96     - (void)resolvePredicate:(id)predicate
97     {
98     if([predicate isKindOfClass:[NSCompoundPredicate class]]) {
99     NSArray *sub = [predicate subpredicates];
100     for(id p in sub) {
101     [self resolvePredicate:p];
102     }
103     } else if([predicate isKindOfClass:[NSComparisonPredicate class]]) {
104     id left = [predicate leftExpression];
105     id right = [predicate rightExpression];
106     SEL sel = Nil;
107     if([predicate predicateOperatorType] == NSCustomSelectorPredicateOperatorType) {
108     sel = [predicate customSelector];
109     }
110     fprintf(stderr, "left ->\t");
111     [self resolveExpression:left];
112     if(sel) {
113     fprintf(stderr, "%s\n", [[NSString stringWithFormat:@"SEL -> %@", NSStringFromSelector(sel)] UTF8String]);
114     } else {
115     fprintf(stderr, "%s\n", [[NSString stringWithFormat:@"type -> %d, opt -> %d, mod -> %d", [predicate predicateOperatorType], [predicate options], [predicate comparisonPredicateModifier]] UTF8String]);
116     }
117     fprintf(stderr, "right ->\t");
118     [self resolveExpression:right];
119     fprintf(stderr, "end resolve.\n");
120     }
121     }
122    
123 masaki 123 - (void)setPredicate:(id)predicate
124     {
125 masaki 187 HMLog(HMLogLevelDebug, @"predicate -> (%@) %@", NSStringFromClass([predicate class]), predicate);
126 masaki 243 // [self resolvePredicate:predicate];
127 masaki 123
128 masaki 153 id new = [XspfMRule ruleEditorRowsFromPredicate:predicate withRowTemplate:rowTemplate];
129 masaki 125
130     [self willChangeValueForKey:XspfMREDPredicateRowsKey];
131     [predicateRows release];
132     predicateRows = [new retain];
133     [self didChangeValueForKey:XspfMREDPredicateRowsKey];
134 masaki 146 // [ruleEditor reloadCriteria];
135 masaki 123 }
136 masaki 125 - (void)setPredicateRows:(id)p
137     {
138 masaki 187 // HMLog(HMLogLevelDebug, @"new -> %@", p);
139 masaki 125 [predicateRows release];
140     predicateRows = [p retain];
141     }
142    
143     #pragma mark#### NSRleEditor Delegate ####
144 masaki 152
145 masaki 124 - (NSInteger)ruleEditor:(NSRuleEditor *)editor
146     numberOfChildrenForCriterion:(id)criterion
147     withRowType:(NSRuleEditorRowType)rowType
148     {
149     NSInteger result = 0;
150    
151     if(!criterion) {
152 masaki 166 if(rowType == NSRuleEditorRowTypeCompound) {
153     result = [compounds count];
154     } else {
155     result = [simples count];
156     }
157 masaki 143 } else {
158 masaki 152 result = [criterion numberOfChildren];
159 masaki 124 }
160    
161 masaki 187 // HMLog(HMLogLevelDebug, @"numner\tcriterion -> %@, type -> %d, result -> %d", criterion, rowType, result);
162 masaki 124
163     return result;
164     }
165    
166     - (id)ruleEditor:(NSRuleEditor *)editor
167     child:(NSInteger)index
168     forCriterion:(id)criterion
169     withRowType:(NSRuleEditorRowType)rowType
170     {
171     id result = nil;
172    
173     if(!criterion) {
174 masaki 166 if(rowType == NSRuleEditorRowTypeCompound) {
175     result = [compounds objectAtIndex:index];
176     } else {
177     result = [simples objectAtIndex:index];
178     }
179 masaki 143 } else {
180 masaki 152 result = [criterion childAtIndex:index];
181 masaki 124 }
182    
183 masaki 187 // HMLog(HMLogLevelDebug, @"child\tindex -> %d, criterion -> %@, type -> %d, result -> %@", index, criterion, rowType, result);
184 masaki 124
185     return result;
186     }
187     - (id)ruleEditor:(NSRuleEditor *)editor
188     displayValueForCriterion:(id)criterion
189     inRow:(NSInteger)row
190     {
191     id result = nil;
192 masaki 143
193     if(!criterion) {
194     //
195     } else {
196 masaki 152 result = [criterion displayValueForRuleEditor:editor inRow:row];
197 masaki 143 }
198    
199 masaki 187 // HMLog(HMLogLevelDebug, @"display\tcriterion -> %@, row -> %d, result -> %@", criterion, row, result);
200 masaki 143
201 masaki 124 return result;
202     }
203     - (NSDictionary *)ruleEditor:(NSRuleEditor *)editor
204     predicatePartsForCriterion:(id)criterion
205     withDisplayValue:(id)displayValue
206     inRow:(NSInteger)row
207     {
208     id result = nil;
209    
210 masaki 152 result = [criterion predicatePartsWithDisplayValue:displayValue forRuleEditor:editor inRow:row];
211 masaki 187 // HMLog(HMLogLevelDebug, @"predicate\tresult -> %@", result);
212 masaki 143
213 masaki 187 // HMLog(HMLogLevelDebug, @"predicate\tcriterion -> %@, value -> %@, row -> %d, result -> %@", criterion, displayValue, row, result);
214 masaki 143
215 masaki 124 return result;
216     }
217     - (void)ruleEditorRowsDidChange:(NSNotification *)notification
218     {
219     //
220     }
221 masaki 150 @end

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