Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/AppKit.framework |
Availability | Available in Mac OS X v10.5 and later. |
Declared in | NSPredicateEditorRowTemplate.h |
Companion guides | |
Related sample code |
NSPredicateEditorRowTemplate
describes available predicates and how to display them.
You can create instances of NSPredicateEditorRowTemplate
programmatically or in Interface Builder. By default, a non-compound row template has three views: a popup (or static text field) on the left, a popup or static text field for operators, and either a popup or other view on the right. You can subclass NSPredicateEditorRowTemplate
to create a row template with different numbers or types of views.
NSPredicateEditorRowTemplate
is a concrete class, but it has five primitive methods which are called by NSPredicateEditor
: templateViews
, matchForPredicate:
, setPredicate:
, displayableSubpredicatesOfPredicate:
, and predicateWithSubpredicates:
. NSPredicateEditorRowTemplate
implements all of them, but you can override them for custom templates. The primitive methods are used by an instance of NSPredicateEditor
as follows.
First, an instance of NSPredicateEditor
is created, and some row templates are set on it—either through a nib file or programmatically. The first thing predicate editor does is ask each of the templates for their views, using templateViews
.
After setting up the predicate editor, you typically send it a setObjectValue:
message to restore a saved predicate. NSPredicateEditor
needs to determine which of its templates should display each predicate in the predicate tree. It does this by sending each of its row templates a matchForPredicate:
message and choosing the one that returns the highest value.
After finding the best match for a predicate, NSPredicateEditor
copies that template to get fresh views, inserts them into the proper row, and then sets the predicate on the template using setPredicate:
. Within that method, the NSPredicateEditorRowTemplate
object must set its views' values to represent that predicate.
NSPredicateEditorRowTemplate
next asks the template for the “displayable sub-predicates” of the predicate by sending a displayableSubpredicatesOfPredicate:
message. If a template represents a predicate in its entirety, or if the predicate has no subpredicates, it can return nil
for this. Otherwise, it should return a list of predicates to be made into sub-rows of that template's row. The whole process repeats for each sub-predicate.
At this point, the user sees the predicate that was saved. If the user then makes some changes to the views of the templates, this causes NSPredicateEditor
to recompute its predicate by asking each of the templates to return the predicate represented by the new view values, passing in the subpredicates represented by the sub-rows (an empty array if there are none, or nil
if they aren't supported by that predicate type):
– initWithLeftExpressions:rightExpressions:modifier:operators:options:
– initWithLeftExpressions:rightExpressionAttributeType:modifier:operators:options:
– initWithCompoundTypes:
– matchForPredicate:
– templateViews
– setPredicate:
– displayableSubpredicatesOfPredicate:
– predicateWithSubpredicates:
– leftExpressions
– rightExpressions
– compoundTypes
– modifier
– operators
– options
– rightExpressionAttributeType
Returns an array of predicate templates for the given attribute key paths for a given entity.
+ (NSArray *)templatesWithAttributeKeyPaths:(NSArray *)keyPaths inEntityDescription:(NSEntityDescription *)entityDescription
An array of attribute key paths originating at entityDescription. The key paths may cross relationships but must terminate in attributes.
A Core Data entity description.
An array of predicate templates for keyPaths originating at entityDescription.
This method determines which key paths in the entity description can use the same views (that is, share the same attribute type). For each of these groups, it instantiates individual templates via initWithLeftExpressions:rightExpressions:modifier:operators:options:
.
NSPredicateEditorRowTemplate.h
Returns the compound predicate types for the receiver.
- (NSArray *)compoundTypes
An array of NSNumber
objects specifying compound predicate types. See Compound_Predicate_Types
for possible values.
NSPredicateEditorRowTemplate.h
Returns the subpredicates that should be made sub-rows of a given predicate.
- (NSArray *)displayableSubpredicatesOfPredicate:(NSPredicate *)predicate
A predicate object.
The subpredicates that should be made sub-rows of predicate. For compound predicates (instances of NSCompoundPredicate
), the array of subpredicates; for other types of predicate, returns nil
. If a template represents a predicate in its entirety, or if the predicate has no subpredicates, returns nil
.
You can override this method to create custom templates that handle complicated compound predicates.
NSPredicateEditorRowTemplate.h
Initializes and returns a row template suitable for displaying compound predicates.
- (id)initWithCompoundTypes:(NSArray *)compoundTypes
An array of NSNumber
objects specifying compound predicate types. See Compound_Predicate_Types
for possible values.
A row template initialized for displaying compound predicates of the types specified by compoundTypes.
NSPredicateEditor
contains such a template by default.
NSPredicateEditorRowTemplate.h
Initializes and returns a “pop-up-pop-up-view”-style row template.
- (id)initWithLeftExpressions:(NSArray *)leftExpressions rightExpressionAttributeType:(NSAttributeType)attributeType modifier:(NSComparisonPredicateModifier)modifier operators:(NSArray *)operators options:(NSUInteger)options
An array of NSExpression
objects that represent the left hand side of a predicate.
An attribute type for the right hand side of a predicate. This value dictates the type of view created, and how the control’s object value is coerced before putting it into a predicate.
A modifier for the predicate (see NSComparisonPredicateModifier
for possible values).
An array of NSNumber
objects specifying the operator type (see NSPredicateOperatorType
for possible values).
Options for the predicate (see NSComparisonPredicate_Options
for possible values).
A row template initialized using the given arguments.
The type of attributeType dictates the type of view created. For example, NSDateAttributeType
will create an NSDatePicker
object, NSInteger64AttributeType
will create a short text field, and NSStringAttributeType
will produce a longer text field. You can resize the views as you want.
Predicates do not automatically coerce types for you. For example, comparing a number to a string will raise an exception. Therefore, the attribute type is also needed to determine how the control's object value must be coerced before putting it into a predicate.
NSPredicateEditorRowTemplate.h
Initializes and returns a “pop-up-pop-up-pop-up”-style row template.
- (id)initWithLeftExpressions:(NSArray *)leftExpressions rightExpressions:(NSArray *)rightExpressions modifier:(NSComparisonPredicateModifier)modifier operators:(NSArray *)operators options:(NSUInteger)options
An array of NSExpression
objects that represent the left hand side of a predicate.
An array of NSExpression
objects that represent the right hand side of a predicate.
A modifier for the predicate (see NSComparisonPredicateModifier
for possible values).
An array of NSNumber
objects specifying the operator type (see NSPredicateOperatorType
for possible values).
Options for the predicate (see NSComparisonPredicate_Options
for possible values).
A row template of the “pop-up-pop-up-pop-up”-form, with the left and right popups representing the left and right expression arrays leftExpressions and rightExpressions, and the center popup representing the operators.
NSPredicateEditorRowTemplate.h
Returns the left hand expressions for the receiver.
- (NSArray *)leftExpressions
The left hand expressions for the receiver
NSPredicateEditorRowTemplate.h
Returns a positive number if the receiver can represent a given predicate, and 0
if it cannot.
- (double)matchForPredicate:(NSPredicate *)predicate
A positive number if the template can represent predicate, and 0
if it cannot.
By default, returns values in the range 0
to 1
.
The highest match among all the templates determines which template is responsible for displaying the predicate. You can override this to determine which predicates your custom template handles.
NSPredicateEditorRowTemplate.h
Returns the comparison predicate modifier for the receiver.
- (NSComparisonPredicateModifier)modifier
The comparison predicate modifier for the receiver.
NSPredicateEditorRowTemplate.h
Returns the array of operators for the receiver.
- (NSArray *)operators
The array of operators for the receiver.
NSPredicateEditorRowTemplate.h
Returns the comparison predicate options for the receiver.
- (NSUInteger)options
The comparison predicate options for the receiver. See NSComparisonPredicate_Options
for possible values. Returns 0
if this does not apply (for example, for a compound template initialized with initWithCompoundTypes:
).
NSPredicateEditorRowTemplate.h
Returns the predicate represented by the receiver’s views' values and the given sub-predicates.
- (NSPredicate *)predicateWithSubpredicates:(NSArray *)subpredicates
An array of predicates.
The predicate represented by the values of the template's views and the given subpredicates. You can override this method to return the predicate represented by your custom views.
This method is only called if matchForPredicate:
returned a positive value for the receiver.
You can override this method to return the predicate represented by a custom view.
NSPredicateEditorRowTemplate.h
Returns the attribute type of the receiver’s right expression.
- (NSAttributeType)rightExpressionAttributeType
The attribute type of the receiver’s right expression.
NSPredicateEditorRowTemplate.h
Returns the right hand expressions for the receiver.
- (NSArray *)rightExpressions
The right hand expressions for the receiver
NSPredicateEditorRowTemplate.h
Sets the value of the views according to the given predicate.
- (void)setPredicate:(NSPredicate *)predicate
The predicate value for the receiver.
This method is only called if matchForPredicate:
returned a positive value for the receiver.
You can override this to set the values of custom views.
NSPredicateEditorRowTemplate.h
Returns the views for the receiver.
- (NSArray *)templateViews
The views for the receiver.
Instances of NSPopUpButton
are treated specially by NSPredicateEditor
; their menu items are merged into a single popup button, and matching menu item titles are combined. In this way, a single tree is built from the separate templates.
NSPredicateEditorRowTemplate.h
© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-01-12)