26 CPArray _allTemplates;
28 CPArray _rootHeaderTrees;
33 #pragma mark public methods 52 - (CPArray)rowTemplates
62 - (void)setRowTemplates:(
id)rowTemplates
64 if (_allTemplates == rowTemplates)
67 _allTemplates = rowTemplates;
69 [
self _updateItemsByCompoundTemplates];
70 [
self _updateItemsBySimpleTemplates];
72 if ([
self numberOfRows] > 0)
75 [
self _reflectPredicate:predicate];
80 + (Class)_binderClassForBinding:(
CPString)aBinding
82 if (aBinding == CPValueBinding)
85 return [
super _binderClassForBinding:aBinding];
90 if (aBinding == CPValueBinding)
93 return [
super _replacementKeyPathForBinding:aBinding];
96 - (void)_initRuleEditorShared
98 [
super _initRuleEditorShared];
100 _rootTrees = [CPArray array];
101 _rootHeaderTrees = [CPArray array];
104 - (id)initWithFrame:(CGRect)aFrame
106 self = [
super initWithFrame:aFrame];
110 _allTemplates = [CPArray arrayWithObject:initialTemplate];
118 return [
super predicate];
121 - (void)_updateItemsBySimpleTemplates
124 count = [_allTemplates count],
129 var t = _allTemplates[count];
131 [templates insertObject:t atIndex:0];
134 var trees = [
self _constructTreesForTemplates:templates];
135 if ([trees count] > 0)
136 _rootTrees = [
self _mergeTree:trees];
139 - (void)_updateItemsByCompoundTemplates
142 count = [_allTemplates count],
147 var t = _allTemplates[count];
149 [templates insertObject:t atIndex:0];
152 var trees = [
self _constructTreesForTemplates:templates];
153 if ([trees count] > 0)
154 _rootHeaderTrees = [
self _mergeTree:trees];
157 - (CPArray)_constructTreesForTemplates:(
id)templates
160 count = [templates count];
162 for (var i = 0; i < count; i++)
164 var tree = [
self _constructTreeForTemplate:templates[i]];
165 [trees addObjectsFromArray:tree];
177 var icount = [aTree count];
178 for (var i = 0; i < icount; i++)
180 var anode = [aTree objectAtIndex:i],
181 jcount = [mergedTree count],
184 for (var j = 0; j < jcount; j++)
186 var mergednode = [mergedTree objectAtIndex:j];
188 if ([[mergednode title] isEqualToString:[anode title]])
190 var children1 = [mergednode children],
191 children2 = [anode children],
192 children12 = [children1 arrayByAddingObjectsFromArray:children2],
193 mergedChildren = [
self _mergeTree:children12];
195 [mergednode setChildren:mergedChildren];
201 [mergedTree addObject:anode];
209 var tree = [CPArray array],
211 count = [templateViews count];
215 var children = [CPArray array],
220 templateView = [templateViews objectAtIndex:count],
221 isPopup = [templateView isKindOfClass:[CPPopUpButton class]];
225 itemArray = [[templateView itemArray] valueForKey:@"title"];
226 itemsCount = [itemArray count];
230 for (; menuIndex < itemsCount; menuIndex++)
232 var item = [_CPPredicateEditorTree new];
233 [item setIndexIntoTemplate:count];
234 [item setTemplate:aTemplate];
235 [item setMenuItemIndex:menuIndex];
237 [item setTitle:[itemArray objectAtIndex:menuIndex]];
239 [children addObject:item];
242 [children makeObjectsPerformSelector:@selector(setChildren:) withObject:tree];
249 #pragma mark Set the Predicate 251 - (void)setObjectValue:(
id)objectValue
253 var ov = [
self objectValue];
254 if ((ov == nil) != (objectValue == nil) || ![ov
isEqual:objectValue])
256 [
self _setPredicate:objectValue];
257 [
self _reflectPredicate:objectValue];
261 - (void)_reflectPredicate:(
id)predicate
263 var animation = _currentAnimation;
264 _currentAnimation = nil;
267 if (predicate != nil)
271 predicate = [[
CPCompoundPredicate alloc] initWithType:[
self _compoundPredicateTypeForRootRows] subpredicates:[CPArray arrayWithObject:predicate]];
273 var row = [
self _rowObjectFromPredicate:predicate];
275 [_boundArrayOwner setValue:[CPArray arrayWithObject:row] forKey:_boundArrayKeyPath];
278 [
self setAnimation:animation];
281 - (id)_rowObjectFromPredicate:(CPPredicate)predicate
287 if (matchedTemplate == nil)
290 var copyTemplate = [matchedTemplate copy],
291 subpredicates = [matchedTemplate displayableSubpredicatesOfPredicate:predicate];
293 if (subpredicates == nil)
295 [copyTemplate _setComparisonPredicate:predicate];
300 [copyTemplate _setCompoundPredicate:predicate];
304 var row = [
self _rowFromTemplate:copyTemplate originalTemplate:matchedTemplate withRowType:type];
306 if (subpredicates == nil)
309 var count = [subpredicates count],
312 for (var i = 0; i < count; i++)
314 var subrow = [
self _rowObjectFromPredicate:subpredicates[i]];
316 [subrows addObject:subrow];
319 [row setValue:subrows forKey:[
super subrowsKeyPath]];
326 var criteria = [CPArray array],
327 values = [CPArray array],
334 while ((count = [rootItems count]) > 0)
337 for (var i = 0; i < count; i++)
339 treeChild = [rootItems objectAtIndex:i];
341 var currentView = [templateViews objectAtIndex:[treeChild indexIntoTemplate]],
342 title = [treeChild title];
344 if (title == nil || [title
isEqual:[currentView titleOfSelectedItem]])
346 var node = [_CPPredicateEditorRowNode rowNodeFromTree:treeChild];
347 [node applyTemplate:aTemplate withViews:templateViews forOriginalTemplate:originalTemplate];
349 [criteria addObject:node];
350 [values addObject:[node displayValue]];
355 rootItems = [treeChild children];
359 @"criteria": criteria,
360 @"displayValues": values,
367 #pragma mark Get the predicate 369 - (void)_updatePredicate
371 [
self _updatePredicateFromRows];
374 - (void)_updatePredicateFromRows
376 var rootRowsArray = [
super _rootRowsArray],
379 count2 = count = [rootRowsArray count],
384 var item = [rootRowsArray objectAtIndex:count],
385 subpredicate = [
self _predicateFromRowItem:item];
387 if (subpredicate != nil)
388 [subpredicates insertObject:subpredicate atIndex:0];
392 predicate = [subpredicates lastObject];
394 predicate = [[
CPCompoundPredicate alloc] initWithType:[
self _compoundPredicateTypeForRootRows] subpredicates:subpredicates];
396 [
self _setPredicate:predicate];
399 - (id)_predicateFromRowItem:(
id)rowItem
401 var subpredicates = [CPArray array],
402 rowType = [rowItem valueForKey:_typeKeyPath];
406 var subrows = [rowItem valueForKey:_subrowsArrayKeyPath],
407 count = [subrows count];
409 for (var i = 0; i < count; i++)
411 var subrow = [subrows objectAtIndex:i],
412 predicate = [
self _predicateFromRowItem:subrow];
414 [subpredicates addObject:predicate];
418 var criteria = [rowItem valueForKey:_itemsKeyPath],
419 displayValues = [rowItem valueForKey:_valuesKeyPath],
420 count = [criteria count],
421 lastItem = [criteria lastObject],
422 template = [lastItem templateForRow],
423 templateViews = [template templateViews];
425 for (var j = 0; j < count; j++)
427 var view = [templateViews objectAtIndex:j],
428 value = [displayValues objectAtIndex:j];
429 [[criteria objectAtIndex:j] setTemplateViews:templateViews];
432 [view selectItemWithTitle:value];
433 else if ([view respondsToSelector:
@selector(setObjectValue:)])
434 [view setObjectValue:[value objectValue]];
437 return [template predicateWithSubpredicates:subpredicates];
440 - (CPCompoundPredicateType)_compoundPredicateTypeForRootRows
445 #pragma mark Control delegate 447 - (void)_sendRuleAction
449 [
super _sendRuleAction];
452 - (BOOL)_sendsActionOnIncompleteTextChange
480 #pragma mark RuleEditor delegate methods 482 - (int)_queryNumberOfChildrenOfItem:(
id)rowItem withRowType:(CPRuleEditorRowType)type
487 return [trees count];
489 return [[rowItem children] count];
492 - (id)_queryChild:(
int)childIndex ofItem:(
id)rowItem withRowType:(CPRuleEditorRowType)type
497 return [_CPPredicateEditorRowNode rowNodeFromTree:trees[childIndex]];
500 return [[rowItem children] objectAtIndex:childIndex];
503 - (id)_queryValueForItem:(
id)rowItem inRow:(CPInteger)rowIndex
505 return [rowItem displayValue];
510 var CPPredicateTemplatesKey =
@"CPPredicateTemplates";
514 - (id)initWithCoder:(
CPCoder)aCoder
516 self = [
super initWithCoder:aCoder];
520 var nibTemplates = [aCoder decodeObjectForKey:CPPredicateTemplatesKey];
522 if (nibTemplates != nil)
523 [
self setRowTemplates:nibTemplates];
529 - (void)encodeWithCoder:(
CPCoder)aCoder
531 [
super encodeWithCoder:aCoder];
532 [aCoder encodeObject:_allTemplates forKey:CPPredicateTemplatesKey];
541 - (void)setPlaceholderValue:(
id)aValue withMarker:(
CPString)aMarker forBinding:(
CPString)aBinding
543 [_source _reflectPredicate:nil];
546 - (void)setValue:(
id)aValue forBinding:(
CPString)aBinding
548 [_source _reflectPredicate:aValue];
561 return _predicateTarget;
567 - (void)setTarget:(
id)aValue
569 _predicateTarget = aValue;
577 return _predicateAction;
583 - (void)setAction:(
SEL)aValue
585 _predicateAction = aValue;
id initWithCompoundTypes:(CPArray compoundTypes)
Initializes and returns a row template suitable for displaying compound predicates.
CPRuleEditorNestingModeList
CPRuleEditorRowType CPRuleEditorRowTypeSimple
CPRuleEditorNestingModeCompound
CPRuleEditorNestingModeSimple
CPPredicate predicate()
Returns the predicate for the receiver.
CPCompoundPredicate is a subclass of CPPredicate used to represent logical “gate” operations (AND/O...
CPRuleEditorRowTypeCompound
An immutable string (collection of characters).
A view for creating and configuring criteria.
Defines methods for use when archiving & restoring (enc/decoding).
CPComparisonPredicate is a subclass of CPPredicate used to compare expressions.
CPArray templateViews()
Returns the views for the receiver.