Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfManager/XspfMRuleEditorDelegate.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 367 - (hide annotations) (download)
Sat May 22 12:19:24 2010 UTC (13 years, 10 months ago) by masakih
File size: 9244 byte(s)
Ratingキーパスを変更可能にした。\
1 masaki 120 //
2     // XspfMRuleEditorDelegate.m
3     // XspfManager
4     //
5     // Created by Hori,Masaki on 09/11/28.
6     //
7    
8 masakih 350 /*
9 masakih 365 This source code is release under the New BSD License.
10 masakih 350 Copyright (c) 2009-2010, masakih
11     All rights reserved.
12    
13 masakih 365 ソースコード形式かバイナリ形式か、変更するかしないかを問わず、以下の条件を満たす場合に
14     限り、再頒布および使用が許可されます。
15    
16     1, ソースコードを再頒布する場合、上記の著作権表示、本条件一覧、および下記免責条項を含
17     めること。
18     2, バイナリ形式で再頒布する場合、頒布物に付属のドキュメント等の資料に、上記の著作権表
19     示、本条件一覧、および下記免責条項を含めること。
20     3, 書面による特別の許可なしに、本ソフトウェアから派生した製品の宣伝または販売促進に、
21     コントリビューターの名前を使用してはならない。
22     本ソフトウェアは、著作権者およびコントリビューターによって「現状のまま」提供されており、
23     明示黙示を問わず、商業的な使用可能性、および特定の目的に対する適合性に関する暗黙の保証
24     も含め、またそれに限定されない、いかなる保証もありません。著作権者もコントリビューター
25     も、事由のいかんを問わず、 損害発生の原因いかんを問わず、かつ責任の根拠が契約であるか
26     厳格責任であるか(過失その他の)不法行為であるかを問わず、仮にそのような損害が発生する
27     可能性を知らされていたとしても、本ソフトウェアの使用によって発生した(代替品または代用
28     サービスの調達、使用の喪失、データの喪失、利益の喪失、業務の中断も含め、またそれに限定
29     されない)直接損害、間接損害、偶発的な損害、特別損害、懲罰的損害、または結果損害につい
30     て、一切責任を負わないものとします。
31 masakih 350 -------------------------------------------------------------------
32     Copyright (c) 2009-2010, masakih
33     All rights reserved.
34    
35 masakih 365 Redistribution and use in source and binary forms, with or without
36     modification, are permitted provided that the following conditions
37     are met:
38 masakih 350
39 masakih 365 1, Redistributions of source code must retain the above copyright
40     notice, this list of conditions and the following disclaimer.
41     2, Redistributions in binary form must reproduce the above copyright
42     notice, this list of conditions and the following disclaimer in
43     the documentation and/or other materials provided with the
44     distribution.
45     3, The names of its contributors may be used to endorse or promote
46     products derived from this software without specific prior
47     written permission.
48     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
49     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
50     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
51     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
52     COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
53     INCIDENTAL, SPECIAL,EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
54     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
55     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
56     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
58     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
59     POSSIBILITY OF SUCH DAMAGE.
60 masakih 350 */
61    
62 masaki 120 #import "XspfMRuleEditorDelegate.h"
63    
64 masakih 348 #import "XspfMRule.h"
65     #import "XspfMRuleRowsBuilder.h"
66     #import "XspfMRuleRowTemplate.h"
67 masaki 120
68     @implementation XspfMRuleEditorDelegate
69 masaki 125
70     static NSString *XspfMREDPredicateRowsKey = @"predicateRows";
71    
72 masakih 366 + (void)registerStringTypeKeyPaths:(NSArray *)keyPaths
73 masaki 124 {
74 masakih 366 [XspfMRule registerStringTypeKeyPaths:keyPaths];
75 masaki 124 }
76 masakih 366 + (void)registerDateTypeKeyPaths:(NSArray *)keyPaths
77     {
78     [XspfMRule registerDateTypeKeyPaths:keyPaths];
79     }
80     + (void)registerNumberTypeKeyPaths:(NSArray *)keyPaths
81     {
82     [XspfMRule registerNumberTypeKeyPaths:keyPaths];
83     }
84     + (void)setUseRating:(BOOL)flag
85     {
86     [XspfMRule setUseRating:flag];
87     }
88 masakih 367 + (void)setRatingKeyPath:(NSString *)keyPath
89     {
90     [XspfMRule setRatingKeyPath:keyPath];
91     }
92 masakih 366 + (void)setUseLablel:(BOOL)flag
93     {
94     [XspfMRule setUseLablel:flag];
95     }
96     + (void)setLabelKeyPath:(NSString *)keyPath
97     {
98     [XspfMRule setLabelKeyPath:keyPath];
99     }
100 masakih 362
101 masaki 120 - (void)awakeFromNib
102     {
103 masakih 348 NSBundle *mainBundle = [NSBundle mainBundle];
104     NSString *templatePath = [mainBundle pathForResource:@"LibraryRowTemplate" ofType:@"plist"];
105     rowTemplate = [[XspfMRuleRowTemplate rowTemplateWithPath:templatePath] retain];
106 masaki 166 compounds = [[XspfMRule compoundRule] retain];
107 masakih 362
108 masaki 125 predicateRows = [[NSMutableArray alloc] init];
109 masaki 159 [ruleEditor bind:@"rows" toObject:self withKeyPath:XspfMREDPredicateRowsKey options:nil];
110 masaki 120 }
111 masakih 348 - (void)dealloc
112 masaki 150 {
113 masakih 348 [ruleEditor unbind:@"rows"];
114     [simples release];
115     [compounds release];
116     [predicateRows release];
117     [rowTemplate release];
118 masaki 150
119 masakih 348 [super dealloc];
120 masaki 150 }
121    
122 masakih 366 - (NSArray *)simples
123     {
124     if(simples) return simples;
125    
126     NSMutableArray *newRows = [NSMutableArray array];
127     for(id keyPath in [XspfMRule leftKeys]) {
128     id c = [rowTemplate criteriaForKeyPath:keyPath];
129     if(c) [newRows addObjectsFromArray:c];
130     }
131    
132     simples = [[NSArray alloc] initWithArray:newRows];
133    
134     return simples;
135     }
136 masakih 348 - (void)setPredicateRows:(id)p
137 masaki 123 {
138 masakih 348 if([predicateRows isEqual:p]) return;
139 masaki 123
140 masaki 125 [predicateRows release];
141 masakih 348 predicateRows = [p retain];
142 masaki 123 }
143 masakih 348 - (void)setPredicate:(id)predicate
144 masaki 125 {
145 masakih 348 XspfMRuleRowsBuilder *builder = [XspfMRuleRowsBuilder builderWithPredicate:predicate];
146     builder.rowTemplate = rowTemplate;
147     [builder build];
148 masakih 352 id new = [NSMutableArray arrayWithObject:[builder row]];
149 masakih 348
150     [self setPredicateRows:new];
151 masaki 125 }
152    
153     #pragma mark#### NSRleEditor Delegate ####
154 masaki 152
155 masaki 124 - (NSInteger)ruleEditor:(NSRuleEditor *)editor
156     numberOfChildrenForCriterion:(id)criterion
157     withRowType:(NSRuleEditorRowType)rowType
158     {
159     NSInteger result = 0;
160    
161     if(!criterion) {
162 masaki 166 if(rowType == NSRuleEditorRowTypeCompound) {
163     result = [compounds count];
164     } else {
165 masakih 366 result = [[self simples] count];
166 masaki 166 }
167 masaki 143 } else {
168 masaki 152 result = [criterion numberOfChildren];
169 masaki 124 }
170    
171     return result;
172     }
173    
174     - (id)ruleEditor:(NSRuleEditor *)editor
175     child:(NSInteger)index
176     forCriterion:(id)criterion
177     withRowType:(NSRuleEditorRowType)rowType
178     {
179     id result = nil;
180    
181     if(!criterion) {
182 masaki 166 if(rowType == NSRuleEditorRowTypeCompound) {
183     result = [compounds objectAtIndex:index];
184     } else {
185 masakih 366 result = [[self simples] objectAtIndex:index];
186 masaki 166 }
187 masaki 143 } else {
188 masaki 152 result = [criterion childAtIndex:index];
189 masaki 124 }
190 masakih 348
191 masaki 124 return result;
192     }
193     - (id)ruleEditor:(NSRuleEditor *)editor
194     displayValueForCriterion:(id)criterion
195     inRow:(NSInteger)row
196     {
197 masakih 348 id result = [criterion displayValueForRuleEditor:editor inRow:row];
198 masaki 143
199 masaki 124 return result;
200     }
201     - (NSDictionary *)ruleEditor:(NSRuleEditor *)editor
202     predicatePartsForCriterion:(id)criterion
203     withDisplayValue:(id)displayValue
204     inRow:(NSInteger)row
205     {
206 masakih 348 id result = [criterion predicatePartsWithDisplayValue:displayValue forRuleEditor:editor inRow:row];
207 masaki 124
208     return result;
209     }
210     - (void)ruleEditorRowsDidChange:(NSNotification *)notification
211     {
212     //
213     }
214 masakih 348
215     #pragma mark---- Debugging ----
216     - (void)resolveExpression:(id)exp
217     {
218     NSString *message = nil;
219    
220     switch([exp expressionType]) {
221     case NSConstantValueExpressionType:
222     message = [NSString stringWithFormat:@"constant -> %@", [exp constantValue]];
223     break;
224     case NSEvaluatedObjectExpressionType:
225     message = [NSString stringWithFormat:@"constant -> %@", [exp constantValue]];
226     break;
227     case NSVariableExpressionType:
228     message = [NSString stringWithFormat:@"variable -> %@", [exp variable]];
229     break;
230     case NSKeyPathExpressionType:
231     message = [NSString stringWithFormat:@"keyPath -> %@", [exp keyPath]];
232     break;
233     case NSFunctionExpressionType:
234     message = [NSString stringWithFormat:@"oprand -> %@(%@), function -> %@, arguments -> %@",
235     [exp operand], NSStringFromClass([[exp operand] class]),
236     [exp function], [exp arguments]];
237     break;
238     case NSAggregateExpressionType:
239     message = [NSString stringWithFormat:@"collection -> %@", [exp collection]];
240     break;
241     }
242    
243     fprintf(stderr, "%s\n", [message UTF8String]);
244     }
245     - (void)resolvePredicate:(id)predicate
246     {
247     if([predicate isKindOfClass:[NSCompoundPredicate class]]) {
248     NSArray *sub = [predicate subpredicates];
249     for(id p in sub) {
250     [self resolvePredicate:p];
251     }
252     } else if([predicate isKindOfClass:[NSComparisonPredicate class]]) {
253     id left = [predicate leftExpression];
254     id right = [predicate rightExpression];
255     SEL sel = Nil;
256     if([predicate predicateOperatorType] == NSCustomSelectorPredicateOperatorType) {
257     sel = [predicate customSelector];
258     }
259     fprintf(stderr, "left ->\t");
260     [self resolveExpression:left];
261     if(sel) {
262     fprintf(stderr, "%s\n", [[NSString stringWithFormat:@"SEL -> %@", NSStringFromSelector(sel)] UTF8String]);
263     } else {
264     fprintf(stderr, "%s\n", [[NSString stringWithFormat:@"type -> %d, opt -> %d, mod -> %d", [predicate predicateOperatorType], [predicate options], [predicate comparisonPredicateModifier]] UTF8String]);
265     }
266     fprintf(stderr, "right ->\t");
267     [self resolveExpression:right];
268     fprintf(stderr, "end resolve.\n");
269     }
270     }
271 masaki 150 @end

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