Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfManager/XspfMRuleEditorDelegate.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 366 - (hide annotations) (download)
Sat May 22 12:12:11 2010 UTC (13 years, 10 months ago) by masakih
File size: 9156 byte(s)
XspfMRuleEditorDelegateだけを知っていれば他は知らなくてもいいようにした。
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     + (void)setUseLablel:(BOOL)flag
89     {
90     [XspfMRule setUseLablel:flag];
91     }
92     + (void)setLabelKeyPath:(NSString *)keyPath
93     {
94     [XspfMRule setLabelKeyPath:keyPath];
95     }
96 masakih 362
97 masaki 120 - (void)awakeFromNib
98     {
99 masakih 348 NSBundle *mainBundle = [NSBundle mainBundle];
100     NSString *templatePath = [mainBundle pathForResource:@"LibraryRowTemplate" ofType:@"plist"];
101     rowTemplate = [[XspfMRuleRowTemplate rowTemplateWithPath:templatePath] retain];
102 masaki 166 compounds = [[XspfMRule compoundRule] retain];
103 masakih 362
104 masaki 125 predicateRows = [[NSMutableArray alloc] init];
105 masaki 159 [ruleEditor bind:@"rows" toObject:self withKeyPath:XspfMREDPredicateRowsKey options:nil];
106 masaki 120 }
107 masakih 348 - (void)dealloc
108 masaki 150 {
109 masakih 348 [ruleEditor unbind:@"rows"];
110     [simples release];
111     [compounds release];
112     [predicateRows release];
113     [rowTemplate release];
114 masaki 150
115 masakih 348 [super dealloc];
116 masaki 150 }
117    
118 masakih 366 - (NSArray *)simples
119     {
120     if(simples) return simples;
121    
122     NSMutableArray *newRows = [NSMutableArray array];
123     for(id keyPath in [XspfMRule leftKeys]) {
124     id c = [rowTemplate criteriaForKeyPath:keyPath];
125     if(c) [newRows addObjectsFromArray:c];
126     }
127    
128     simples = [[NSArray alloc] initWithArray:newRows];
129    
130     return simples;
131     }
132 masakih 348 - (void)setPredicateRows:(id)p
133 masaki 123 {
134 masakih 348 if([predicateRows isEqual:p]) return;
135 masaki 123
136 masaki 125 [predicateRows release];
137 masakih 348 predicateRows = [p retain];
138 masaki 123 }
139 masakih 348 - (void)setPredicate:(id)predicate
140 masaki 125 {
141 masakih 348 XspfMRuleRowsBuilder *builder = [XspfMRuleRowsBuilder builderWithPredicate:predicate];
142     builder.rowTemplate = rowTemplate;
143     [builder build];
144 masakih 352 id new = [NSMutableArray arrayWithObject:[builder row]];
145 masakih 348
146     [self setPredicateRows:new];
147 masaki 125 }
148    
149     #pragma mark#### NSRleEditor Delegate ####
150 masaki 152
151 masaki 124 - (NSInteger)ruleEditor:(NSRuleEditor *)editor
152     numberOfChildrenForCriterion:(id)criterion
153     withRowType:(NSRuleEditorRowType)rowType
154     {
155     NSInteger result = 0;
156    
157     if(!criterion) {
158 masaki 166 if(rowType == NSRuleEditorRowTypeCompound) {
159     result = [compounds count];
160     } else {
161 masakih 366 result = [[self simples] count];
162 masaki 166 }
163 masaki 143 } else {
164 masaki 152 result = [criterion numberOfChildren];
165 masaki 124 }
166    
167     return result;
168     }
169    
170     - (id)ruleEditor:(NSRuleEditor *)editor
171     child:(NSInteger)index
172     forCriterion:(id)criterion
173     withRowType:(NSRuleEditorRowType)rowType
174     {
175     id result = nil;
176    
177     if(!criterion) {
178 masaki 166 if(rowType == NSRuleEditorRowTypeCompound) {
179     result = [compounds objectAtIndex:index];
180     } else {
181 masakih 366 result = [[self simples] objectAtIndex:index];
182 masaki 166 }
183 masaki 143 } else {
184 masaki 152 result = [criterion childAtIndex:index];
185 masaki 124 }
186 masakih 348
187 masaki 124 return result;
188     }
189     - (id)ruleEditor:(NSRuleEditor *)editor
190     displayValueForCriterion:(id)criterion
191     inRow:(NSInteger)row
192     {
193 masakih 348 id result = [criterion displayValueForRuleEditor:editor inRow:row];
194 masaki 143
195 masaki 124 return result;
196     }
197     - (NSDictionary *)ruleEditor:(NSRuleEditor *)editor
198     predicatePartsForCriterion:(id)criterion
199     withDisplayValue:(id)displayValue
200     inRow:(NSInteger)row
201     {
202 masakih 348 id result = [criterion predicatePartsWithDisplayValue:displayValue forRuleEditor:editor inRow:row];
203 masaki 124
204     return result;
205     }
206     - (void)ruleEditorRowsDidChange:(NSNotification *)notification
207     {
208     //
209     }
210 masakih 348
211     #pragma mark---- Debugging ----
212     - (void)resolveExpression:(id)exp
213     {
214     NSString *message = nil;
215    
216     switch([exp expressionType]) {
217     case NSConstantValueExpressionType:
218     message = [NSString stringWithFormat:@"constant -> %@", [exp constantValue]];
219     break;
220     case NSEvaluatedObjectExpressionType:
221     message = [NSString stringWithFormat:@"constant -> %@", [exp constantValue]];
222     break;
223     case NSVariableExpressionType:
224     message = [NSString stringWithFormat:@"variable -> %@", [exp variable]];
225     break;
226     case NSKeyPathExpressionType:
227     message = [NSString stringWithFormat:@"keyPath -> %@", [exp keyPath]];
228     break;
229     case NSFunctionExpressionType:
230     message = [NSString stringWithFormat:@"oprand -> %@(%@), function -> %@, arguments -> %@",
231     [exp operand], NSStringFromClass([[exp operand] class]),
232     [exp function], [exp arguments]];
233     break;
234     case NSAggregateExpressionType:
235     message = [NSString stringWithFormat:@"collection -> %@", [exp collection]];
236     break;
237     }
238    
239     fprintf(stderr, "%s\n", [message UTF8String]);
240     }
241     - (void)resolvePredicate:(id)predicate
242     {
243     if([predicate isKindOfClass:[NSCompoundPredicate class]]) {
244     NSArray *sub = [predicate subpredicates];
245     for(id p in sub) {
246     [self resolvePredicate:p];
247     }
248     } else if([predicate isKindOfClass:[NSComparisonPredicate class]]) {
249     id left = [predicate leftExpression];
250     id right = [predicate rightExpression];
251     SEL sel = Nil;
252     if([predicate predicateOperatorType] == NSCustomSelectorPredicateOperatorType) {
253     sel = [predicate customSelector];
254     }
255     fprintf(stderr, "left ->\t");
256     [self resolveExpression:left];
257     if(sel) {
258     fprintf(stderr, "%s\n", [[NSString stringWithFormat:@"SEL -> %@", NSStringFromSelector(sel)] UTF8String]);
259     } else {
260     fprintf(stderr, "%s\n", [[NSString stringWithFormat:@"type -> %d, opt -> %d, mod -> %d", [predicate predicateOperatorType], [predicate options], [predicate comparisonPredicateModifier]] UTF8String]);
261     }
262     fprintf(stderr, "right ->\t");
263     [self resolveExpression:right];
264     fprintf(stderr, "end resolve.\n");
265     }
266     }
267 masaki 150 @end

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