Re: NSPredicateEditorRowTemplate and dynamic templateViews

2010-03-30 Thread Dave DeLong
I'm still struggling with this.  Does anyone know how I can either:

1.  Use custom comparators in an NSPredicateEditorRowTemplate or
2.  Have two templates with the same left expression and operator, but 
different right expression types?

Thanks,

Dave

On Mar 12, 2010, at 7:29 PM, Dave DeLong wrote:

 My date row templates allow me to do:
 
 aDate is after aSpecificDate and aDate is in the last 30 days
 
 Both of these are technically: aDate  anotherDate
 
 When I -init these custom row templates, I need to pass in an array of 
 operators.  I can't init both of these templates with a GreaterThan operator 
 (I tried, and it complained).  There's an operator listed in the 
 documentation, NSCustomSelectorPredicateOperatorType, which is presumably 
 used with an NSComparisonPredicate, but there's very very little in there 
 about how to use that from within an NSPredicateEditorRowTemplate.  Can that 
 operator type be used in a EditorRowTemplate (my attempts to do so have 
 resulted in HIToolbox generating an Unknown Predicate Type exception)?  If 
 not, how can I have two different kinds of greater than comparisons in the 
 same row template?


smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

NSPredicateEditorRowTemplate and dynamic templateViews

2010-03-12 Thread Dave DeLong
Hi everyone,

I'm trying to build a custom predicate editor row template that lets me do 
predicates like in the last 30 days or since {aDate}.  For the simple date 
comparison, I'm returning an NSDatePicker as the third view in my templateViews.

My problem is that I only want to return the NSDatePicker if the operator is =, 
!=, , =, , or =.  If the operator is in the last (a custom operator), I 
want to return 4 template views: the first two being the standard keypath + 
operator views, but the last two being an NSTextField (with NSNumberFormatter 
attached) and an NSPopUpButton (with the units: days, weeks, months, etc).

I thought that I'd just be able to check which item was selected in the 
operators popup and return the appropriate views based on the current operator.

Unfortunately, it seems like the predicateEditor invokes templateViews *before* 
the operator actually changes.  In other words, if the operator is =, and I 
switch it to =, then when templateViews is invoked, the operators popup still 
says =, and won't say = until it's changed again.

So my question is this:  how can I dynamically modify my row's templateViews to 
accurately reflect the current operator?  I *could* post a notification from 
the RowTemplate that the editor needs redrawing, and then have my controller 
capture that notification and invoke reloadPredicate on my predicate editor, 
but that seems like a really hackish work-around.

Any recommendations?

(for an example of what I'm describing, try creating a new smart playlist in 
iTunes and fiddling around with the operators corresponding to the Date Added 
attribute)

Thanks!

Dave

smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: NSPredicateEditorRowTemplate and dynamic templateViews

2010-03-12 Thread Peter Ammon

On Mar 12, 2010, at 1:47 PM, Dave DeLong wrote:

 Hi everyone,
 
 I'm trying to build a custom predicate editor row template that lets me do 
 predicates like in the last 30 days or since {aDate}.  For the simple 
 date comparison, I'm returning an NSDatePicker as the third view in my 
 templateViews.
 
 My problem is that I only want to return the NSDatePicker if the operator is 
 =, !=, , =, , or =.  If the operator is in the last (a custom 
 operator), I want to return 4 template views: the first two being the 
 standard keypath + operator views, but the last two being an NSTextField 
 (with NSNumberFormatter attached) and an NSPopUpButton (with the units: days, 
 weeks, months, etc).
 
 I thought that I'd just be able to check which item was selected in the 
 operators popup and return the appropriate views based on the current 
 operator.
 
 Unfortunately, it seems like the predicateEditor invokes templateViews 
 *before* the operator actually changes.  In other words, if the operator is 
 =, and I switch it to =, then when templateViews is invoked, the operators 
 popup still says =, and won't say = until it's changed again.
 
 So my question is this:  how can I dynamically modify my row's templateViews 
 to accurately reflect the current operator?  I *could* post a notification 
 from the RowTemplate that the editor needs redrawing, and then have my 
 controller capture that notification and invoke reloadPredicate on my 
 predicate editor, but that seems like a really hackish work-around.
 
 Any recommendations?
 
 (for an example of what I'm describing, try creating a new smart playlist in 
 iTunes and fiddling around with the operators corresponding to the Date Added 
 attribute)
 
 Thanks!

What you want to do here is to create two separate templates.  One looks like 
this:

[Creation Date, Modification Date]  [=, !=, , =, , =]   
{NSDatePicker}

The other looks like this:

[Creation Date, Modification Date]  [in the last]   {NSTextField}   
[days, weeks, months]


The first template is responsible for predicates with the standard operators, 
and the second one is responsible for predicates with the custom operator.  At 
runtime, NSPredicateEditor will merge the templates together, and the second 
popup will show a union of all the operators of your date templates.

Hope that helps,
-Peter

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSPredicateEditorRowTemplate and dynamic templateViews

2010-03-12 Thread Dave DeLong
This seems so obvious in retrospect that I can't believe I didn't think of that.

Thank you so much!

Dave

On Mar 12, 2010, at 2:57 PM, Peter Ammon wrote:

 What you want to do here is to create two separate templates.  One looks 
 like this:
 
   [Creation Date, Modification Date]  [=, !=, , =, , =]   
 {NSDatePicker}
 
 The other looks like this:
 
   [Creation Date, Modification Date]  [in the last]   {NSTextField}   
 [days, weeks, months]
 
 
 The first template is responsible for predicates with the standard operators, 
 and the second one is responsible for predicates with the custom operator.  
 At runtime, NSPredicateEditor will merge the templates together, and the 
 second popup will show a union of all the operators of your date templates.
 
 Hope that helps,
 -Peter
 



smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

NSPredicateEditorRowTemplate and CoreData

2010-01-25 Thread Carmen Cerino Jr.
I am trying to generate predicate editor templates for my Core Data entities. 
In my code I have the following:

NSEntityDescription *descrip = [NSEntityDescription 
entityForName:@Person inManagedObjectContext:managedObjectContext];
NSArray *templates = [NSPredicateEditorRowTemplate 
templatesWithAttributeKeyPaths:[NSArray arrayWithObjects:@name, @age, nil] 
inEntityDescription:descrip];

[ibPredicateEditor setRowTemplates: templates];

NSPredicate *p = [NSPredicate predicateWithFormat:@name like 'John'];

[ibPredicateEditor setObjectValue:p];

Printing out the contents of the templates array gives me the following:
CFArray 0x1002d7400 [0x7fff70ff5f20]{type = immutable, count = 2, 
values = (
0 : NSPredicateEditorRowTemplate 0x10025c090: [name] [99, 4, 
5, 8, 9] NSStringAttributeType
1 : NSPredicateEditorRowTemplate 0x1002d2dc0: [age] [4, 5, 0, 
2, 1, 3] NSInteger16AttributeType
)}

When this code executes I get the following on the console:
Warning - unable to find template matching predicate name LIKE Worsley

The interface for doing this looks extremely straight forward, so I can't seem 
to figure out what I am doing wrong. Any help would be greatly appreciated!

Cheers,
Carmen___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


set the label for the left hand expression / popup in an NSPredicateEditorRowTemplate?

2010-01-13 Thread Mike Chambers
I am looking for some input on how to set the label for the left hand
expression / popup in an NSPredicateEditorRowTemplate.

I need to programmatically create a NSPredicateEditorRowTemplate so I
can populate the right side expression / drop down with dynamically
generated values.

In my subclass, I populate the values like so:

---
-(id)initWithArray:(NSArray *)arr
{
NSString *keyPath = @professions;

NSMutableArray *expressions = [NSMutableArray arrayWithCapacity:[arr 
count]];
for(NSString *s in arr)
{
[expressions addObject:[NSExpression 
expressionForConstantValue:s]];
}   

if(!(self = [super initWithLeftExpressions:[NSArray
arrayWithObjects:[NSExpression expressionForKeyPath:keyPath], nil]
  
rightExpressions:expressions
  
modifier:NSDirectPredicateModifier
 
operators:[NSArray arrayWithObjects:

[NSNumber numberWithInt:NSContainsPredicateOperatorType],nil]
   
options:NSCaseInsensitivePredicateOption
 ]))
{
return nil;
}

//...
}
---

I then add this to the NSPredicateEditor, and it works as expect.
However, the left column in the editor for this row shows
professions (the key value). I want it to show Profession. If I
was using IB this would be very simple, as I could just rename it in
the popup.

How can I set the label for the left hand name in the editor?

Do I have to completely override all of the
NSPredicateEditorRowTemplate methods and manage all of the popups /
controls myself? I only need to change the label. Ive been trying to
figure this out off ad on for the past week, and havent come up with
any solutions other than override all APIs.

mike
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: set the label for the left hand expression / popup in an NSPredicateEditorRowTemplate?

2010-01-13 Thread Peter Ammon

On Jan 13, 2010, at 3:46 PM, Mike Chambers wrote:
 [...]
 I then add this to the NSPredicateEditor, and it works as expect.
 However, the left column in the editor for this row shows
 professions (the key value). I want it to show Profession. If I
 was using IB this would be very simple, as I could just rename it in
 the popup.
 
 How can I set the label for the left hand name in the editor?

You can simply change the title of the menu item in the NSPopUpButton.  You can 
access the first popup button with [[template templateViews] objectAtIndex:0].

-Peter

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Customizing left expression title in NSPredicateEditorRowTemplate

2009-12-28 Thread Mike Chambers
I have am creating a simple NSPredicateEditorRowTemplate instance that
I instantiate like so:


NSMutableArray *seriesExpressions = [NSMutableArray
arrayWithCapacity:[series count]];
for(NSString *s in series)
{
[seriesExpressions addObject:[NSExpression 
expressionForConstantValue:s]];
}

NSPredicateEditorRowTemplate * template =
[NSPredicateEditorRowTemplate alloc] initWithLeftExpressions:[NSArray
arrayWithObjects:[NSExpression expressionForKeyPath:@series], nil]
 rightExpressions:seriesExpressions
 
modifier:NSDirectPredicateModifier
operators:[NSArray 
arrayWithObject:[NSNumber
numberWithInt:NSEqualToPredicateOperatorType]]
  
options:NSCaseInsensitivePredicateOption];
 ];


Basically, the left expression is a key path named series and the
right expression is an Array of possible values.

This works great, except, I want the popup in the NSPredicateEditor to
display Series and not the keypath series. I know how to do this
in Interface Builder, but since my right expressions are from a data
source, I cannot set this in interface builder.

How can I change the display title for the right expression?

I tried subclassing NSPredicateEditorRowTemplate and then overriding:

---
- (NSArray *)templateViews
{
NSMutableArray* myviews = [[super templateViews] mutableCopy];  

if(firstRun)
{
[myviews replaceObjectAtIndex:0 withObject:popup];
firstRun = FALSE;
}

return myviews;
}

with popup initiated like so:

---
NSMenu *popupMenu = [[[NSMenu allocWithZone:[NSMenu menuZone]]
initWithTitle:@Series] autorelease];

NSMenuItem *menuItem = [[[NSMenuItem alloc] initWithTitle:@Series
action:nil keyEquivalent:@] autorelease];
[menuItem setRepresentedObject:[NSExpression 
expressionForKeyPath:@series]];
[menuItem setEnabled:YES];

[popupMenu addItem:menuItem];

popup = [[NSPopUpButton alloc] initWithFrame:NSZeroRect pullsDown:NO];
[popup setMenu:popupMenu];  
--

but this generates the following exception:


--
we were not able to find a popup item at view index 0 with title
Series.  Available items are: CFArray 0x115d780b0
[0x7fff7062bf20]{type = immutable, count = 1, values = (
0 : NSMenuItem: 0x115d73dc0 series
-

So, two questions:

1. Am I on the right track?
2. If not, how can I change the displayed title for the left expression?

mike
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Customizing left expression title in NSPredicateEditorRowTemplate

2009-12-28 Thread Mike Chambers
ok. I got this working by adding:

- (id)copyWithZone:(NSZone *)zone {
return [self retain];
}

to my template subclass.

Can anyone tell me if I am approaching this the correct way?

mike

On Mon, Dec 28, 2009 at 2:42 PM, Mike Chambers mikechamb...@gmail.com wrote:
 I have am creating a simple NSPredicateEditorRowTemplate instance that
 I instantiate like so:

 
 NSMutableArray *seriesExpressions = [NSMutableArray
 arrayWithCapacity:[series count]];
 for(NSString *s in series)
 {
        [seriesExpressions addObject:[NSExpression 
 expressionForConstantValue:s]];
 }

 NSPredicateEditorRowTemplate * template =
 [NSPredicateEditorRowTemplate alloc] initWithLeftExpressions:[NSArray
 arrayWithObjects:[NSExpression expressionForKeyPath:@series], nil]
                                         rightExpressions:seriesExpressions
                                                         
 modifier:NSDirectPredicateModifier
                                                        operators:[NSArray 
 arrayWithObject:[NSNumber
 numberWithInt:NSEqualToPredicateOperatorType]]
                                                          
 options:NSCaseInsensitivePredicateOption];
                 ];
 

 Basically, the left expression is a key path named series and the
 right expression is an Array of possible values.

 This works great, except, I want the popup in the NSPredicateEditor to
 display Series and not the keypath series. I know how to do this
 in Interface Builder, but since my right expressions are from a data
 source, I cannot set this in interface builder.

 How can I change the display title for the right expression?

 I tried subclassing NSPredicateEditorRowTemplate and then overriding:

 ---
 - (NSArray *)templateViews
 {
        NSMutableArray* myviews = [[super templateViews] mutableCopy];

        if(firstRun)
        {
                [myviews replaceObjectAtIndex:0 withObject:popup];
                firstRun = FALSE;
        }

        return myviews;
 }

 with popup initiated like so:

 ---
        NSMenu *popupMenu = [[[NSMenu allocWithZone:[NSMenu menuZone]]
 initWithTitle:@Series] autorelease];

        NSMenuItem *menuItem = [[[NSMenuItem alloc] initWithTitle:@Series
 action:nil keyEquivalent:@] autorelease];
        [menuItem setRepresentedObject:[NSExpression 
 expressionForKeyPath:@series]];
        [menuItem setEnabled:YES];

        [popupMenu addItem:menuItem];

        popup = [[NSPopUpButton alloc] initWithFrame:NSZeroRect pullsDown:NO];
        [popup setMenu:popupMenu];
 --

 but this generates the following exception:


 --
 we were not able to find a popup item at view index 0 with title
 Series.  Available items are: CFArray 0x115d780b0
 [0x7fff7062bf20]{type = immutable, count = 1, values = (
        0 : NSMenuItem: 0x115d73dc0 series
 -

 So, two questions:

 1. Am I on the right track?
 2. If not, how can I change the displayed title for the left expression?

 mike

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSPredicateEditorRowTemplate and dynamic popups

2009-11-13 Thread Dave DeLong
Hi everyone,

I have an NSPredicateEditor, with some standard row templates.  I'd like to add 
a custom row template with three views:  a popup button (indicating the 
attributes this template references), a second popup button (with the 
operators), and a third popup button that's populated with a list of possible 
values.

This is very similar to a regular row template, except that the list of 
possible values is computed at runtime and can change periodically based on 
system events.

I've tried subclassing NSPredicateEditorRowTemplate, overriding -templateViews, 
and returning my 3 popup buttons (all properly populated).  This works once, 
but after the row is created, I haven't been able to figure out how to 
repopulate the popup button when the list of possible values changes.  I've 
tried setting the popup button's menu's delegate to an object that will 
repopulate it, but the delegate methods are never called.

I've also seen that when there's only one possible value, my popup button is 
replaced with a textfield.  I suppose that's OK, except that if the list of 
possible values changes, I need that textfield to change to a popup button.

How can I achieve my dynamic popup button in an NSPredicateEditorRowTemplate?

Thanks!

Dave DeLong

smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: NSPredicateEditorRowTemplate and dynamic popups

2009-11-13 Thread Jim Turner
Try this:

Create an outlet to your row template. When you need to update the
popups, make a copy of that template. Make a copy of the rowTemplates
the predicate editor currently tracks and iterate over them replacing
the template in the list that is the same class as your custom
template.  Then set this new list of templates back onto the predicate
editor.

The net effect is that the predicate editor will rebuild all the
templates it's currently using which gives you a chance to update the
popups as needed.  I don't know what'll happen when the popup
transitions to/from the text field... there's little you can do with
that as its an optimization the predicate editor does when building
it's templates (if there's only one option, why offer a choice?)

cheap-n-dirty code sample

-(void) updateTemplates {
MyRowTemplate *_newTemplate = [[myRowTemplateOutlet copy] autorelease];
NSMutableArray *rowTemplates = [[[predicateEditor rowTemplates]
mutableCopy] autorelease];

NSInteger ctr;
for( ctr=0; ctr[rowTemplates count]; ctr++ ) {
if( [[rowTemplates objectAtIndex:ctr] 
isKindOfClass:[MyRowTemplate class]] ) {
[rowTemplates replaceObjectAtIndex:ctr 
withObject:_newTemplate];
break;
}
}
[predicateEditor setRowTemplates:rowTemplates];
}


-- 
Jim
http://nukethemfromorbit.com


On Fri, Nov 13, 2009 at 10:48 AM, Dave DeLong davedel...@me.com wrote:
 Hi everyone,

 I have an NSPredicateEditor, with some standard row templates.  I'd like to 
 add a custom row template with three views:  a popup button (indicating the 
 attributes this template references), a second popup button (with the 
 operators), and a third popup button that's populated with a list of possible 
 values.

 This is very similar to a regular row template, except that the list of 
 possible values is computed at runtime and can change periodically based on 
 system events.

 I've tried subclassing NSPredicateEditorRowTemplate, overriding 
 -templateViews, and returning my 3 popup buttons (all properly populated).  
 This works once, but after the row is created, I haven't been able to figure 
 out how to repopulate the popup button when the list of possible values 
 changes.  I've tried setting the popup button's menu's delegate to an object 
 that will repopulate it, but the delegate methods are never called.

 I've also seen that when there's only one possible value, my popup button is 
 replaced with a textfield.  I suppose that's OK, except that if the list of 
 possible values changes, I need that textfield to change to a popup button.

 How can I achieve my dynamic popup button in an NSPredicateEditorRowTemplate?

 Thanks!

 Dave DeLong
 ___

 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com

 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/cocoa-dev/jturner.lists%40gmail.com

 This email sent to jturner.li...@gmail.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSPredicateEditorRowTemplate, NSPopupButton and bindings

2009-05-26 Thread Peter Ammon

Hi Martin,

Yes, that's right.

More generally, any changes to the popups after calling  
setRowTemplates: are likely to be futile.  This is because the real  
popup buttons displayed in an NSPredicateEditor are not the same popup  
buttons returned from your NSPredicateEditorRowTemplate's - 
templateViews method.  Instead, they are a conglomerate of all the  
popups at the same index in all the templates.  NSPredicateEditor does  
not notice when the template popups change, though this might be a  
nice thing to add at some point in the future.


Hope this helps,

-Peter



On May 25, 2009, at 7:57 AM, Martin Stanley wrote:


Peter,

Thanks for your response (I was hoping you would notice my post :-).

My interpretation of your response is as follows:
1- Cocoa bindings are not supported for popup views that are used in  
a NSPredicateRowtemplate, even if I am careful to make sure that the  
view is re-bound (via copyWithZone) when NSPredicateEditor creates  
its copies. This is true in spite of the fact that I managed to fill  
the popup via bindings upon initial creation.
2- One needs to observe the appropriate objects using KVO and then  
take the steps you outlined below in order to ensure that the popup  
has current values.


Can you please confirm my understanding?

Thanks,
Martin


On 22-May-09, at 10:55 PM, Peter Ammon wrote:



On May 22, 2009, at 9:37 AM, Martin Stanley wrote:

I've finally got the hang of NSPredicateEditor and custom  
NSPredicateEditorRowTemplates. (It sure took a while and many,  
many searches and head-scratchings). However, I am stuck on one  
thing and I suspect that the problem might lie in the  
NSPredicateEditor code itself; hence this post.


Here is what I am trying to do:

I have a Core Data document-based application for managing Tasks  
(to-do items). I am using NSPredicateEditor to manage a set of  
user-defined Smart Groups. I want the user to be able to build a  
predicate based on a choice from a popup button. For example the  
(sub-)predicate might look like this:

 status == Not Started

Implementing this is straightforward enough, but I the wrinkle is  
that want the right hand side of the expression to come from a  
core data entity. So, no problem, when I create the NSPopUpButton  
(in my custom NSPredicateEditorRowTemplate class) I simply fill  
the menuitems from the appropriate array controller, which in turn  
gets its data from the Core Data entity. After much learning and  
experimenting, this now works. All is well.


So, then I realize that if (in another window) the user edits the  
Core Data entity in question, the changes are not reflected in the  
NSPredicateEditor popup. Okay, this seems like a candidate for  
cocoa bindings. Again, after much searching and experimentation I  
come up the following:


Hi Martin,

NSPredicateEditor does not support editing the popups like this.   
What you should do, when the available values in the popup need to  
change, is create a new NSPredicateEditorRowTemplate that reflects  
the change, and set it on the NSPredicateEditor in place of the old  
one, with setRowTemplates:


I think you may also need to save off the predicate editor's object  
value first, and then set it back on after calling setRowTemplates:.




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSPredicateEditorRowTemplate, NSPopupButton and bindings

2009-05-25 Thread Martin Stanley

Peter,

Thanks for your response (I was hoping you would notice my post :-).

My interpretation of your response is as follows:
1- Cocoa bindings are not supported for popup views that are used in a  
NSPredicateRowtemplate, even if I am careful to make sure that the  
view is re-bound (via copyWithZone) when NSPredicateEditor creates its  
copies. This is true in spite of the fact that I managed to fill the  
popup via bindings upon initial creation.
2- One needs to observe the appropriate objects using KVO and then  
take the steps you outlined below in order to ensure that the popup  
has current values.


Can you please confirm my understanding?

Thanks,
Martin


On 22-May-09, at 10:55 PM, Peter Ammon wrote:



On May 22, 2009, at 9:37 AM, Martin Stanley wrote:

I've finally got the hang of NSPredicateEditor and custom  
NSPredicateEditorRowTemplates. (It sure took a while and many, many  
searches and head-scratchings). However, I am stuck on one thing  
and I suspect that the problem might lie in the NSPredicateEditor  
code itself; hence this post.


Here is what I am trying to do:

I have a Core Data document-based application for managing Tasks  
(to-do items). I am using NSPredicateEditor to manage a set of user- 
defined Smart Groups. I want the user to be able to build a  
predicate based on a choice from a popup button. For example the  
(sub-)predicate might look like this:

  status == Not Started

Implementing this is straightforward enough, but I the wrinkle is  
that want the right hand side of the expression to come from a core  
data entity. So, no problem, when I create the NSPopUpButton (in my  
custom NSPredicateEditorRowTemplate class) I simply fill the  
menuitems from the appropriate array controller, which in turn gets  
its data from the Core Data entity. After much learning and  
experimenting, this now works. All is well.


So, then I realize that if (in another window) the user edits the  
Core Data entity in question, the changes are not reflected in the  
NSPredicateEditor popup. Okay, this seems like a candidate for  
cocoa bindings. Again, after much searching and experimentation I  
come up the following:


Hi Martin,

NSPredicateEditor does not support editing the popups like this.   
What you should do, when the available values in the popup need to  
change, is create a new NSPredicateEditorRowTemplate that reflects  
the change, and set it on the NSPredicateEditor in place of the old  
one, with setRowTemplates:


I think you may also need to save off the predicate editor's object  
value first, and then set it back on after calling setRowTemplates:.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSPredicateEditorRowTemplate, NSPopupButton and bindings

2009-05-22 Thread Martin Stanley
I've finally got the hang of NSPredicateEditor and custom  
NSPredicateEditorRowTemplates. (It sure took a while and many, many  
searches and head-scratchings). However, I am stuck on one thing and I  
suspect that the problem might lie in the NSPredicateEditor code  
itself; hence this post.


Here is what I am trying to do:

I have a Core Data document-based application for managing Tasks (to- 
do items). I am using NSPredicateEditor to manage a set of user- 
defined Smart Groups. I want the user to be able to build a predicate  
based on a choice from a popup button. For example the (sub-)predicate  
might look like this:

status == Not Started

Implementing this is straightforward enough, but I the wrinkle is that  
want the right hand side of the expression to come from a core data  
entity. So, no problem, when I create the NSPopUpButton (in my custom  
NSPredicateEditorRowTemplate class) I simply fill the menuitems from  
the appropriate array controller, which in turn gets its data from the  
Core Data entity. After much learning and experimenting, this now  
works. All is well.


So, then I realize that if (in another window) the user edits the Core  
Data entity in question, the changes are not reflected in the  
NSPredicateEditor popup. Okay, this seems like a candidate for cocoa  
bindings. Again, after much searching and experimentation I come up  
the following:


NSPopUpButton *rightPopUp = [[NSPopUpButton alloc]  
initWithFrame:NSZeroRect pullsDown:NO];
[rightPopUp bind:@content toObject:arrayController  
withKeyPath:@arrangedObjects options:nil];
[rightPopUp bind:@contentValues toObject:arrayController  
withKeyPath:[NSString stringWithFormat:@%...@.%@, @arrangedObjects,  
[self controllerKeyPath]] options:nil];


where:
- arrayController is the array controller backed by the Core Data entity
- controllerKeyPath is an NSString which holds the keypath for the  
name of the NSManagedObject (ex. name)


This works fine in that it fills the NSPopUpButton initially. It even  
works across the copying that NSPredicateEditor seems to need to make.  
However, if I change the underlying entity in another window (which  
uses a different, but identically set up, array controller) the  
NSPopUpButton menu items do not change. If I close the Smart Groups  
window and start everything (NSPredicateEditor creation, etc.) all  
over again, it will pick up the changes in the entity.


Just to make sure that I'm not completely nuts, I put an independent  
NSPopUpButton elsewhere on the Smart Groups window and bound it (using  
IB) identically to the NSPopUpButton in the row template. This popup  
works perfectly: it updates the popup items in real time as expected.  
I also checked that all the bindings (IB and programatically) are  
actually being created by using -infoForBinding:NSContentBinding and - 
infoForBinding:NSContentValuesBinding. Everything appears to be wired  
up correctly.


I wonder if NSPredicateEditor is somehow blocking the change  
notifications from the array controller?


Does anyone have any experience trying to bind an NSPopUpButton in a  
custom NSPredicateEditorRowTemplate?


Oh, in case it matters, I am compiling for GC only.

Thanks for any advice.

Martin


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSPredicateEditorRowTemplate, NSPopupButton and bindings

2009-05-22 Thread Peter Ammon


On May 22, 2009, at 9:37 AM, Martin Stanley wrote:

I've finally got the hang of NSPredicateEditor and custom  
NSPredicateEditorRowTemplates. (It sure took a while and many, many  
searches and head-scratchings). However, I am stuck on one thing and  
I suspect that the problem might lie in the NSPredicateEditor code  
itself; hence this post.


Here is what I am trying to do:

I have a Core Data document-based application for managing Tasks (to- 
do items). I am using NSPredicateEditor to manage a set of user- 
defined Smart Groups. I want the user to be able to build a  
predicate based on a choice from a popup button. For example the  
(sub-)predicate might look like this:

   status == Not Started

Implementing this is straightforward enough, but I the wrinkle is  
that want the right hand side of the expression to come from a core  
data entity. So, no problem, when I create the NSPopUpButton (in my  
custom NSPredicateEditorRowTemplate class) I simply fill the  
menuitems from the appropriate array controller, which in turn gets  
its data from the Core Data entity. After much learning and  
experimenting, this now works. All is well.


So, then I realize that if (in another window) the user edits the  
Core Data entity in question, the changes are not reflected in the  
NSPredicateEditor popup. Okay, this seems like a candidate for cocoa  
bindings. Again, after much searching and experimentation I come up  
the following:


Hi Martin,

NSPredicateEditor does not support editing the popups like this.  What  
you should do, when the available values in the popup need to change,  
is create a new NSPredicateEditorRowTemplate that reflects the change,  
and set it on the NSPredicateEditor in place of the old one, with  
setRowTemplates:


I think you may also need to save off the predicate editor's object  
value first, and then set it back on after calling setRowTemplates:.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSPredicateEditorRowTemplate and switching views

2009-05-04 Thread Arved von Brasch

Hi Cocoa list,

I have noticed a strange bug in my NSPredicateEditorRowTemplate  
implementation.


I have implemented a Pop-Up Pop-Up Level-Indicator template row to  
allow users to sort by rating.  The relevant code is below:


@synthesize levelIndicator;

- (id)copyWithZone: (NSZone *)zone {
id newRow = [super copyWithZone: zone];
	NSLevelIndicatorCell *theCell = [[[NSLevelIndicatorCell alloc]  
initWithLevelIndicatorStyle: NSRatingLevelIndicatorStyle] autorelease];

NSRect frame = [[[self templateViews] lastObject] frame];
frame.size.width = 65;
[theCell setEditable: YES];
[theCell setMinValue: 0.0];
[theCell setMaxValue: 5.0];
	NSLevelIndicator *rating = [[[NSLevelIndicator alloc] initWithFrame:  
frame] autorelease];

[rating setCell: theCell];
if ([self levelIndicator] != nil)
[newRow setFloatValue: [[self levelIndicator] floatValue]];
[newRow setValue: rating forKey: @levelIndicator];
return newRow;
}

- (NSArray *)templateViews {
	NSMutableArray *allViews = [NSMutableArray arrayWithArray: [super  
templateViews]];

if ([self levelIndicator] != nil) {
[allViews removeLastObject];
[allViews addObject: [self levelIndicator]];
}
return allViews;
}

- (void)setPredicate: (NSPredicate *)predicate {
[super setPredicate: predicate];
	[[self levelIndicator] setObjectValue: [[(NSComparisonPredicate  
*)predicate rightExpression] constantValue]];

}

This works fine if the row template is created fresh (ie empty with no  
predicate assigned to it at creation).  If the row template is created  
in response to an edit instruction (edit an already existing  
predicate), then the row template will appear correctly, but if a  
different option is selected from the middle Pop-Up (eg is not) the  
level indicator view will disappear and will be replaced with the  
original NSTextField.


I can't see anything obvious I'm doing wrong.  As far as I can tell,  
the appropriate branch of templateViews is being called when this  
problem occurs.  Can anyone shed any light on this?


Thanks in advance,
Arved von Brasch
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: A question about NSPredicateEditor and NSPredicateEditorRowTemplate

2009-03-06 Thread David Hoerl

[following up to a Jan 08 thread]

  is it possible to modify the width of the NSTextField representing 

 a Number in a NSPredicateEditorRowTemplate ?


Yes, but not yet in Interface Builder.  To do so programatically, get 
the row template, get the text field as the last member of the row 
template's templateViews array, and set its frame to the size you want.


I hope that helps,
-Peter



Peter, I tried to do as you suggest - set the frames to what I want, 
but it has no effect. Any other suggestions?


David

PS: code

-applicationDidFinishLaunching
...
int i = 0;
NSArray *temps = [predicateEditor rowTemplates];
for(NSPredicateEditorRowTemplate *temp in temps) {
NSArray *views = [temp templateViews];
int j = 0;
int x = 0;
for(NSControl *view in views) { // I know, view is not a good 
name for this :-)
NSLog(@temp=%@ view=%@ frame: %@, temp, view, 
NSStringFromRect([view frame])); // verify all is connected

if(i==0) continue; // don't touch first one
NSRect r = [view frame];
r.origin.x = 0; // just for testing impact...
[view setFrame:r];
NSLog(@ mod frame=%@, NSStringFromRect([view frame])); 
// yes, it took

++j;
}
++i;
}
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: A question about NSPredicateEditor and NSPredicateEditorRowTemplate

2009-03-06 Thread Peter Ammon


On Mar 6, 2009, at 6:42 AM, David Hoerl wrote:


[following up to a Jan 08 thread]


 is it possible to modify the width of the NSTextField representing

a Number in a NSPredicateEditorRowTemplate ?


Yes, but not yet in Interface Builder.  To do so programatically,  
get the row template, get the text field as the last member of the  
row template's templateViews array, and set its frame to the size  
you want.


I hope that helps,
-Peter



Peter, I tried to do as you suggest - set the frames to what I want,  
but it has no effect. Any other suggestions?


David

PS: code

-applicationDidFinishLaunching
...
   int i = 0;
   NSArray *temps = [predicateEditor rowTemplates];
   for(NSPredicateEditorRowTemplate *temp in temps) {
   NSArray *views = [temp templateViews];
   int j = 0;
   int x = 0;
   for(NSControl *view in views) { // I know, view is not a good  
name for this :-)
   NSLog(@temp=%@ view=%@ frame: %@, temp, view,  
NSStringFromRect([view frame])); // verify all is connected

   if(i==0) continue; // don't touch first one
   NSRect r = [view frame];
   r.origin.x = 0; // just for testing impact...
   [view setFrame:r];
   NSLog(@ mod frame=%@, NSStringFromRect([view  
frame])); // yes, it took

   ++j;
   }
   ++i;
   }


David, the above code changes the frame origin, but not the frame  
width.  Changing the frame origin will have no effect (the origins are  
controlled by NSPredicateEditor).  But changing the width should have  
an effect.


-Peter


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSPredicateEditorRowTemplate and NSTokenField

2009-01-30 Thread Vitaly Ovchinnikov
Hello all, that's me again with my predicate editor problems :)

I subclassed predicate editor's row and replaced default text editor
with my NSTokenField in -templateViews.

Predicates, that match my template, look like: ANY Tags IN {tag1,
tag2, tag3}

In -setPredicate I fill token field with tags from predicate:
NSExpression *right = .;
[pMyTokenField setObjectValue:[right constantValue]];

In -predicateWithSubPredicates I create predicate described above with
right part from my token field. I added traces there and it builds
exactly what I need.

Now, the problem: I added observer to the predicate that I edit and it
gets called at every change of predicate, but not for my token field
template!

Predicate editor has several rows, some of them are standard -
numeric, text etc. If I change any of them - my observer gets called.
If I edit my token field, observer doesn't get called at all. If I add
some token and switch focus to another row, predicate editor calls
-predicateWithSubPredicate, I build correct predicate and... nothing.
Observer doesn't get called. If I press Enter after adding token -
observer will be called. If I switch to some other row (not with my
template) and then switch back - observer will be called. If I switch
to another row with the same template and when switch back - observer
will not be called.

I added one more control to the row - a button. It does nothing, just
takes some place. I can change my token fields and observer will not
be called. But if I press this button - observer will be called
immediately.

I tried to override -rightExpressions method and return my list of
tags, I tried to call -will/didChangeValueForKey: - nothing helped. It
seems that I need to notify somebody about the change, but have no
idea - how to do that?

Please, help me :)

P.S.: Things are a bit more complex, I have Filter objects, that hold
predicates. Predicate editor is bound to the filter and my observer
observes those filters, not the predicates themselves. I tell this to
cut ideas about incorrect observing. Observing works perfect for any
other row.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSPredicateEditorRowTemplate and NSTokenField

2009-01-30 Thread Vitaly Ovchinnikov
I finally found a solution that seems to work. I subclassed NSTokenField:

==
@implementation MyTokenField

- (void) notifyTarget: (id) sender {
NSControl *t = [self target];
[t sendAction:nil to:t];
}

- (void)textDidEndEditing:(NSNotification *)aNotification {
[super textDidEndEditing:aNotification];
[self performSelector:@selector(notifyTarget:) withObject:self
afterDelay:0];
}

@end
==

-textDidEndEditing gets called after I change something, I send
nil-action to the predicate editor and it finally calls my observer.
The only problem is that it needs some time to build predcate, so I
call it with delay.

The only thing I can't understand is why do I need to call
[t sendAction:nil to:t]
and can't call
[self sendAction:nil to:t]

the second line doesn't work (observer doesn't get called). Who should
be  sender of the action for predicate editor? Control? Row
template?


On Fri, Jan 30, 2009 at 11:21 AM, Vitaly Ovchinnikov
vitaly.ovchinni...@gmail.com wrote:

 Hello all, that's me again with my predicate editor problems :)

 I subclassed predicate editor's row and replaced default text editor
 with my NSTokenField in -templateViews.

 Predicates, that match my template, look like: ANY Tags IN {tag1,
 tag2, tag3}

 In -setPredicate I fill token field with tags from predicate:
 NSExpression *right = .;
 [pMyTokenField setObjectValue:[right constantValue]];

 In -predicateWithSubPredicates I create predicate described above with
 right part from my token field. I added traces there and it builds
 exactly what I need.

 Now, the problem: I added observer to the predicate that I edit and it
 gets called at every change of predicate, but not for my token field
 template!

 Predicate editor has several rows, some of them are standard -
 numeric, text etc. If I change any of them - my observer gets called.
 If I edit my token field, observer doesn't get called at all. If I add
 some token and switch focus to another row, predicate editor calls
 -predicateWithSubPredicate, I build correct predicate and... nothing.
 Observer doesn't get called. If I press Enter after adding token -
 observer will be called. If I switch to some other row (not with my
 template) and then switch back - observer will be called. If I switch
 to another row with the same template and when switch back - observer
 will not be called.

 I added one more control to the row - a button. It does nothing, just
 takes some place. I can change my token fields and observer will not
 be called. But if I press this button - observer will be called
 immediately.

 I tried to override -rightExpressions method and return my list of
 tags, I tried to call -will/didChangeValueForKey: - nothing helped. It
 seems that I need to notify somebody about the change, but have no
 idea - how to do that?

 Please, help me :)

 P.S.: Things are a bit more complex, I have Filter objects, that hold
 predicates. Predicate editor is bound to the filter and my observer
 observes those filters, not the predicates themselves. I tell this to
 cut ideas about incorrect observing. Observing works perfect for any
 other row.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSPredicateEditorRowTemplate for NSDate

2009-01-19 Thread Vitaly Ovchinnikov
Hey, boys and girls?
Am I the first, who use NSPredicateEditor?
I just found that there is no default template for time values...

Please somebody confirm that miracle is over and I need to code all
this data/time stuff myself :(


On Sun, Jan 18, 2009 at 7:22 PM, Vitaly Ovchinnikov
vitaly.ovchinni...@gmail.com wrote:
 Hello list,

 When I add a row template that edits date to predicate editor, it
 allows to perform simple comparisons. Like less or greater or equal
 etc. Smart folders in Finder allow to add clauses like Date is within
 last X weeks. I can't find a simple way to do the same. It seems that
 the only way is to use custom view with that implements what I want,
 but want to make sure that it is correct before I start.

 Maybe I missed something? Or maybe some standard implementation
 already exists? I googled the Internet and this list - nothing.
 Any ideas?

 Thank you.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSPredicateEditorRowTemplate for NSDate

2009-01-19 Thread Jim Turner
The miracle is over.  The out-of-the-box templates in IB only provide
three-view templates (left expression, operator, right expression).
You'll need to subclass NSPredicateEditorRowTemplate and provide the
views and logic you want to use in your template.

I did a presentation for the local CocoaHeads a while back on
NSPredicateEditor and my sample code does show a basic Date is within
N days/weeks/months/years if you'd like a starting point.

Go to http://groups.google.com/group/des-moines-cocoaheads/files   and
look for NSPredicateEditor.zip (I'd direct link but the URL is a
monster).

-- 
Jim
http://nukethemfromorbit.com


On Mon, Jan 19, 2009 at 2:13 PM, Vitaly Ovchinnikov
vitaly.ovchinni...@gmail.com wrote:
 Hey, boys and girls?
 Am I the first, who use NSPredicateEditor?
 I just found that there is no default template for time values...

 Please somebody confirm that miracle is over and I need to code all
 this data/time stuff myself :(


 On Sun, Jan 18, 2009 at 7:22 PM, Vitaly Ovchinnikov
 vitaly.ovchinni...@gmail.com wrote:
 Hello list,

 When I add a row template that edits date to predicate editor, it
 allows to perform simple comparisons. Like less or greater or equal
 etc. Smart folders in Finder allow to add clauses like Date is within
 last X weeks. I can't find a simple way to do the same. It seems that
 the only way is to use custom view with that implements what I want,
 but want to make sure that it is correct before I start.

 Maybe I missed something? Or maybe some standard implementation
 already exists? I googled the Internet and this list - nothing.
 Any ideas?

 Thank you.

 ___

 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com

 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/cocoa-dev/jturner.lists%40gmail.com

 This email sent to jturner.li...@gmail.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSPredicateEditorRowTemplate for NSDate

2009-01-19 Thread Markus Spoettl

On Jan 19, 2009, at 9:13 PM, Vitaly Ovchinnikov wrote:

Hey, boys and girls?
Am I the first, who use NSPredicateEditor?
I just found that there is no default template for time values...



I basically use this code for a date value row template (simplified  
version not tested):


NSArray *operators = [NSArray arrayWithObjects:
[NSNumber numberWithInteger:NSEqualToPredicateOperatorType],
[NSNumber numberWithInteger:NSLessThanPredicateOperatorType],
[NSNumber  
numberWithInteger:NSGreaterThanPredicateOperatorType],
[NSNumber  
numberWithInteger:NSLessThanOrEqualToPredicateOperatorType],
[NSNumber  
numberWithInteger:NSGreaterThanOrEqualToPredicateOperatorType],

nil];

   NSExpression *equipmentExpr =
[NSExpression expressionForKeyPath:@date]; -- use the key  
path appropriate for your object


   NSPredicateEditorRowTemplate *dateTemplate =
   [[[NSPredicateEditorRowTemplate alloc]
   initWithLeftExpressions:expressions
  rightExpressionAttributeType:NSDateAttributeType
  modifier:NSDirectPredicateModifier
 operators:operators
   options:0] autorelease];


NSArray *templates = [NSArray arrayWithObjects:
...
dateTemplate,
...
nil];


[editor setRowTemplates:templates];  -- editor is a  
NSPredicateEditor ivar


All is needed now is a predicate that matches the templates you  
defined and it should work. If you give the editor a predicate it  
cannot resolve using the row template you will get a console log entry  
telling you details (at least on Leopard).


Hope this helps!

Regards
Markus
--
__
Markus Spoettl



smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: NSPredicateEditorRowTemplate for NSDate

2009-01-19 Thread Peter Ammon

Hello Vitaly,

The Cocoa frameworks do not yet have any classes for specifying a  
relative date, so you will have to handle this yourself with a  
subclass of NSPredicateEditorRowTemplate.  You can leverage the  
superclass to do much of the work for you: your responsibility is  
limited to turning a RelativeDate into units (days, weeks) and a  
value in those units, and going the other direction as well.


I wrote a sample showing one way to handle relative dates.  For now it  
is at http://homepage.mac.com/gershwin/RelativeDatesPredicateEditor.zip


As to no default template for time values, this is a limitation of  
IB's support for NSPredicateEditor.  You can set up a time-editing  
NSDatePicker programmatically like so:


* Create an NSPredicateEditorRowTemplate that edits dates in IB
* Make an outlet to it
* When your code starts, set the date picker elements to what you  
want: [[[template templateViews] objectAtIndex:2]  
setDatePickerElements:elements];


This is a mechanism that NSPredicateEditor supports.

Hope this helps,
-Peter

On Jan 18, 2009, at 8:22 AM, Vitaly Ovchinnikov wrote:


Hello list,

When I add a row template that edits date to predicate editor, it
allows to perform simple comparisons. Like less or greater or equal
etc. Smart folders in Finder allow to add clauses like Date is within
last X weeks. I can't find a simple way to do the same. It seems that
the only way is to use custom view with that implements what I want,
but want to make sure that it is correct before I start.

Maybe I missed something? Or maybe some standard implementation
already exists? I googled the Internet and this list - nothing.
Any ideas?

Thank you.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/pammon%40apple.com

This email sent to pam...@apple.com


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSPredicateEditorRowTemplate for NSDate

2009-01-19 Thread Vitaly Ovchinnikov
Thanks to all for answers, now I need a few days to sleep with all these data.
Thank you.

On Tue, Jan 20, 2009 at 12:04 AM, Jim Turner jturner.li...@gmail.com wrote:
 The miracle is over.  The out-of-the-box templates in IB only provide
 three-view templates (left expression, operator, right expression).
 You'll need to subclass NSPredicateEditorRowTemplate and provide the
 views and logic you want to use in your template.

 I did a presentation for the local CocoaHeads a while back on
 NSPredicateEditor and my sample code does show a basic Date is within
 N days/weeks/months/years if you'd like a starting point.

 Go to http://groups.google.com/group/des-moines-cocoaheads/files   and
 look for NSPredicateEditor.zip (I'd direct link but the URL is a
 monster).

 --
 Jim
 http://nukethemfromorbit.com


 On Mon, Jan 19, 2009 at 2:13 PM, Vitaly Ovchinnikov
 vitaly.ovchinni...@gmail.com wrote:
 Hey, boys and girls?
 Am I the first, who use NSPredicateEditor?
 I just found that there is no default template for time values...

 Please somebody confirm that miracle is over and I need to code all
 this data/time stuff myself :(


 On Sun, Jan 18, 2009 at 7:22 PM, Vitaly Ovchinnikov
 vitaly.ovchinni...@gmail.com wrote:
 Hello list,

 When I add a row template that edits date to predicate editor, it
 allows to perform simple comparisons. Like less or greater or equal
 etc. Smart folders in Finder allow to add clauses like Date is within
 last X weeks. I can't find a simple way to do the same. It seems that
 the only way is to use custom view with that implements what I want,
 but want to make sure that it is correct before I start.

 Maybe I missed something? Or maybe some standard implementation
 already exists? I googled the Internet and this list - nothing.
 Any ideas?

 Thank you.

 ___

 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com

 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/cocoa-dev/jturner.lists%40gmail.com

 This email sent to jturner.li...@gmail.com


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSPredicateEditorRowTemplate for NSDate

2009-01-18 Thread Vitaly Ovchinnikov
Hello list,

When I add a row template that edits date to predicate editor, it
allows to perform simple comparisons. Like less or greater or equal
etc. Smart folders in Finder allow to add clauses like Date is within
last X weeks. I can't find a simple way to do the same. It seems that
the only way is to use custom view with that implements what I want,
but want to make sure that it is correct before I start.

Maybe I missed something? Or maybe some standard implementation
already exists? I googled the Internet and this list - nothing.
Any ideas?

Thank you.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Live updating NSPredicateEditorRowTemplate?

2008-12-13 Thread Guy Umbright


To close this out...

I figured it out to as good as I think it gets.  The key is to call  
NSRuleEditor::setCriteria with nil arrays.  The nil arrays force it to  
go to its data source (which for NSPredicateEditor is the row  
templates) to refill.  It does reset the row to the initial value, but  
I don't really think there is a way around that and I think it is  
valid (at least easily rationalized)  interface-wise that if you  
change the criteria mid edit of a predicate it has to reset in case  
your selected option vanished.  Not optimal, but oh well.


Example:

	[_editor setCriteria:[NSArray array] andDisplayValues:[NSArray array]  
forRowAtIndex: 1];


On Dec 8, 2008, at 8:58 PM, Peter Ammon wrote:



On Dec 8, 2008, at 6:37 PM, Guy Umbright wrote:

I am trying to create an NSPredicateEditorRowTemplate with its last  
view a  popup that contains a list of things (elsewhere in the  
window) that can be updated while the editor is being displayed.  I  
can get it so that I can add an instance of the template, update  
the list of items and add another instance which shows the updated  
list, but the original does not update.


For example, the original templates specifies A,B,C in the last  
popup.  I add a row with that template then I add a D to the list  
of items and then add another row to the Predicate Editor.  This  
new row will show me a list of A,B,C,D but the original row still  
just shows A,B,C.


Is there a way to resync that existing row with the new list of  
items in its source template?  Am I going to have to remove and re- 
add the row programmatically?


You should call -[NSPredicateEditor setRowTemplates:] with an array  
containing the new template (but not the old one).  If you want to  
preserve the predicate, you may have to save off the predicate via - 
objectValue, and then set it back; or alternatively calling  
reloadCriteria should work.


-Peter



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Live updating NSPredicateEditorRowTemplate?

2008-12-11 Thread Peter Ammon
This (terrible) message usually means that one of your templates  
contains an empty popup button, which is not allowed.


-Peter

On Dec 10, 2008, at 6:54 PM, Guy Umbright wrote:

As I mentioned, I can get new rows to add with an updated list via  
the code attached to the OP.  The problem is that if I uncomment the  
[_editor reloadCriteria]; line the last popup of the initial row  
doesn't paint and I get the following message in the debug console:


2008-12-10 20:49:41.050 prededit[12581:813] In NSPredicateEditor:  
0x126340, different number of items (2) than values (3)


Guy

On Dec 8, 2008, at 8:58 PM, Peter Ammon wrote:



On Dec 8, 2008, at 6:37 PM, Guy Umbright wrote:

I am trying to create an NSPredicateEditorRowTemplate with its  
last view a  popup that contains a list of things (elsewhere in  
the window) that can be updated while the editor is being  
displayed.  I can get it so that I can add an instance of the  
template, update the list of items and add another instance which  
shows the updated list, but the original does not update.


For example, the original templates specifies A,B,C in the last  
popup.  I add a row with that template then I add a D to the list  
of items and then add another row to the Predicate Editor.  This  
new row will show me a list of A,B,C,D but the original row still  
just shows A,B,C.


Is there a way to resync that existing row with the new list of  
items in its source template?  Am I going to have to remove and re- 
add the row programmatically?


You should call -[NSPredicateEditor setRowTemplates:] with an array  
containing the new template (but not the old one).  If you want to  
preserve the predicate, you may have to save off the predicate via - 
objectValue, and then set it back; or alternatively calling  
reloadCriteria should work.


-Peter



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/pammon%40apple.com

This email sent to [EMAIL PROTECTED]


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Live updating NSPredicateEditorRowTemplate?

2008-12-10 Thread Guy Umbright
As I mentioned, I can get new rows to add with an updated list via the  
code attached to the OP.  The problem is that if I uncomment the  
[_editor reloadCriteria]; line the last popup of the initial row  
doesn't paint and I get the following message in the debug console:


2008-12-10 20:49:41.050 prededit[12581:813] In NSPredicateEditor:  
0x126340, different number of items (2) than values (3)


Guy

On Dec 8, 2008, at 8:58 PM, Peter Ammon wrote:



On Dec 8, 2008, at 6:37 PM, Guy Umbright wrote:

I am trying to create an NSPredicateEditorRowTemplate with its last  
view a  popup that contains a list of things (elsewhere in the  
window) that can be updated while the editor is being displayed.  I  
can get it so that I can add an instance of the template, update  
the list of items and add another instance which shows the updated  
list, but the original does not update.


For example, the original templates specifies A,B,C in the last  
popup.  I add a row with that template then I add a D to the list  
of items and then add another row to the Predicate Editor.  This  
new row will show me a list of A,B,C,D but the original row still  
just shows A,B,C.


Is there a way to resync that existing row with the new list of  
items in its source template?  Am I going to have to remove and re- 
add the row programmatically?


You should call -[NSPredicateEditor setRowTemplates:] with an array  
containing the new template (but not the old one).  If you want to  
preserve the predicate, you may have to save off the predicate via - 
objectValue, and then set it back; or alternatively calling  
reloadCriteria should work.


-Peter



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Live updating NSPredicateEditorRowTemplate?

2008-12-08 Thread Guy Umbright
I am trying to create an NSPredicateEditorRowTemplate with its last  
view a  popup that contains a list of things (elsewhere in the window)  
that can be updated while the editor is being displayed.  I can get it  
so that I can add an instance of the template, update the list of  
items and add another instance which shows the updated list, but the  
original does not update.


For example, the original templates specifies A,B,C in the last  
popup.  I add a row with that template then I add a D to the list of  
items and then add another row to the Predicate Editor.  This new row  
will show me a list of A,B,C,D but the original row still just shows  
A,B,C.


Is there a way to resync that existing row with the new list of items  
in its source template?  Am I going to have to remove and re-add the  
row programmatically?



Guy

Here is some code from my hack to try to figure this out:

- (void) awakeFromNib
{
	_lefts = [[NSArray arrayWithObject: [NSExpression  
expressionForKeyPath:@Filled]] retain];
	_rights = [[NSMutableArray arrayWithObjects:[NSExpression  
expressionForConstantValue:@Yabba],

[NSExpression 
expressionForConstantValue:@Dabba],
 [NSExpression 
expressionForConstantValue:@Doo],nil] retain];
	_ops = [[NSArray arrayWithObject: [NSNumber  
numberWithInt:NSEqualToPredicateOperatorType]] retain];;


_filledTemplate = [self generateFilledTemplate];

	[_editor setRowTemplates:[[_editor rowTemplates] arrayByAddingObject:  
_filledTemplate]];

[_editor addRow:self];
}

- (IBAction)alterFilled:(id)sender
{
	[_rights addObject:[NSExpression  
expressionForConstantValue:@Sandwich!]];

_filledTemplate = [self generateFilledTemplate];

NSArray* templates = [_editor rowTemplates];
NSMutableArray* newRowTemplates = [NSMutableArray array];
NSPredicateEditorRowTemplate* template;
NSEnumerator* enumerator = [templates objectEnumerator];

while (template = [enumerator nextObject])
{
NSArray* a = [template leftExpressions];
if (a != nil)
{
NSExpression* ex = [a objectAtIndex:0];

if (([ex expressionType] == NSKeyPathExpressionType))
{
if ([[ex keyPath] isEqual:@Filled])
{
continue;
}
}
}

[newRowTemplates addObject: template];
}

[newRowTemplates addObject:_filledTemplate];
[_editor setRowTemplates: newRowTemplates];
//	[_editor reloadCriteria];  //thing makes many bad things happen if  
I uncomment it

}

- (NSPredicateEditorRowTemplate*) generateFilledTemplate
{
	NSPredicateEditorRowTemplate* template =  
[FilledPredicateEditorRowTemplate alloc] ;

[template initWithLeftExpressions:_lefts

  rightExpressions:_rights

  modifier:NSDirectPredicateModifier

 operators:_ops

   options: 0];

return template;
}

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Live updating NSPredicateEditorRowTemplate?

2008-12-08 Thread Peter Ammon


On Dec 8, 2008, at 6:37 PM, Guy Umbright wrote:

I am trying to create an NSPredicateEditorRowTemplate with its last  
view a  popup that contains a list of things (elsewhere in the  
window) that can be updated while the editor is being displayed.  I  
can get it so that I can add an instance of the template, update the  
list of items and add another instance which shows the updated list,  
but the original does not update.


For example, the original templates specifies A,B,C in the last  
popup.  I add a row with that template then I add a D to the list of  
items and then add another row to the Predicate Editor.  This new  
row will show me a list of A,B,C,D but the original row still just  
shows A,B,C.


Is there a way to resync that existing row with the new list of  
items in its source template?  Am I going to have to remove and re- 
add the row programmatically?


You should call -[NSPredicateEditor setRowTemplates:] with an array  
containing the new template (but not the old one).  If you want to  
preserve the predicate, you may have to save off the predicate via - 
objectValue, and then set it back; or alternatively calling  
reloadCriteria should work.


-Peter

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


NSPredicateEditorRowTemplate and CoreData

2008-10-16 Thread Arved von Brasch

Hello Cocoa Dev List,

I'm loving NSPredicateEditor and what it lets you do.  I'm wondering  
about the best way to manage what I want to do:


I want a Pop-Up Pop-Up Pop-Up template row, where the last view is  
populated by every item of a particular CoreData Entity.  The entity  
has one attribute, 'name', that should be the display item, but the  
objects themselves (or at least their URL ID) should be part of the  
predicate, so that the predicate can follow the object should the name  
attribute change.  I'm expecting to parse the predicate tree when I  
want to use it to replace the object instance with its name attribute.


That part is relatively easy to set up in a  
NSPredicateEditorRowTemplate subclass.  I'm using an IBOutlet link to  
an NSArrayController which has all the items to populate the list  
with.  Overriding templateViews to populate the last view with the  
appropriate values.  This seems a little kludgy, but works well  
enough.  If there's a better solution, I'd love to hear it!


What's troubling me is the edge case where there are no objects of the  
particular entity in the database.  I think the best option would be  
to prevent the associated Row Template from being selectable from the  
left hand side Pop-Up, but I can't seem to find any way to do that.   
There is a potential problem I can see with removing the item from the  
left hand side Pop-Up anyway, namely, what happens if a previously  
saved predicate is given to the predicate editor.  Is there an elegant  
solution to this?


I appreciate any ideas,

Arved von Brasch
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: NSPredicateEditorRowTemplate and CoreData

2008-10-16 Thread Peter Ammon


On Oct 16, 2008, at 3:56 AM, Arved von Brasch wrote:


Hello Cocoa Dev List,

I'm loving NSPredicateEditor and what it lets you do.  I'm wondering  
about the best way to manage what I want to do:


I want a Pop-Up Pop-Up Pop-Up template row, where the last view is  
populated by every item of a particular CoreData Entity.  The entity  
has one attribute, 'name', that should be the display item, but the  
objects themselves (or at least their URL ID) should be part of the  
predicate, so that the predicate can follow the object should the  
name attribute change.  I'm expecting to parse the predicate tree  
when I want to use it to replace the object instance with its name  
attribute.


That part is relatively easy to set up in a  
NSPredicateEditorRowTemplate subclass.  I'm using an IBOutlet link  
to an NSArrayController which has all the items to populate the list  
with.  Overriding templateViews to populate the last view with the  
appropriate values.  This seems a little kludgy, but works well  
enough.  If there's a better solution, I'd love to hear it!


That's a fine approach.  You can also just create a new RowTemplate  
and set it on the NSPredicateEditor every time your list of items  
changes.


What's troubling me is the edge case where there are no objects of  
the particular entity in the database.  I think the best option  
would be to prevent the associated Row Template from being  
selectable from the left hand side Pop-Up, but I can't seem to find  
any way to do that.


There's no way to, say, disable the item, but you can remove it  
entirely by just removing that RowTemplate from the predicate editor's  
array of row templates.


 There is a potential problem I can see with removing the item from  
the left hand side Pop-Up anyway, namely, what happens if a  
previously saved predicate is given to the predicate editor.  Is  
there an elegant solution to this?


What you can do here is have a fallback template, that is, another  
template capable of showing the predicate.  If you load a predicate  
that references an item in the database that no longer exists, the  
fallback can display something generic instead.  You would implement  
this by having multiple templates nonzero for matchForPredicate:, with  
the fallback returning the smaller value.


You can also just preprocess the predicate to excise or replace  
predicates that no longer apply.


If no template claims the ability to show a particular predicate, then  
the predicate editor will complain (but does not raise an exception in  
Leopard), and then ignore the the predicate.


Hope this helps,
-Peter

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: NSPredicateEditorRowTemplate and ANY predicate

2008-07-23 Thread [EMAIL PROTECTED]

De: [EMAIL PROTECTED]

On Jul 22, 2008, at 12:05 PM, Frédéric Testuz wrote:

 Hello,

 Is it possible to prepare a row template for a NSPredicateEditor in  
 IB for a predicate like ANY keyPath == 'aValue' ?


I'm not sure I understand your question.  How is this different than  
just a normal OR type compound predicate?

My question was too general. My model have is like this :

Book --- Role --- Author

A book can have many authors, an author can be on many books. The reason of the 
Role is that for a book, an author 
can be a writer, a drawer, a colourist, etc.
So, to find the books with at least an author is John, I have this sort of 
predicate :

ANY roles.author.name CONTAINS 'John'

It works pretty well. But now I want a NSPredicateEditor to give me this sort 
of predicate. I don't find a way to do 
it in IB without subclassing NSPredicateEditorRowTemplate. Perhaps I have not 
see it.

For info, I tried the subclassing and it works.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: NSPredicateEditorRowTemplate and ANY predicate

2008-07-23 Thread Peter Ammon


On Jul 23, 2008, at 1:58 AM, [EMAIL PROTECTED] wrote:




De: [EMAIL PROTECTED]

On Jul 22, 2008, at 12:05 PM, Frédéric Testuz wrote:


Hello,

Is it possible to prepare a row template for a NSPredicateEditor in
IB for a predicate like ANY keyPath == 'aValue' ?



I'm not sure I understand your question.  How is this different than
just a normal OR type compound predicate?


My question was too general. My model have is like this :

Book --- Role --- Author

A book can have many authors, an author can be on many books. The  
reason of the Role is that for a book, an author

can be a writer, a drawer, a colourist, etc.
So, to find the books with at least an author is John, I have this  
sort of predicate :


ANY roles.author.name CONTAINS 'John'

It works pretty well. But now I want a NSPredicateEditor to give me  
this sort of predicate. I don't find a way to do
it in IB without subclassing NSPredicateEditorRowTemplate. Perhaps I  
have not see it.


For info, I tried the subclassing and it works.


Ok, thanks for clarifying your question.  As you guessed this isn't  
yet possible in IB.


-Peter


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


NSPredicateEditorRowTemplate and ANY predicate

2008-07-22 Thread Frédéric Testuz

Hello,

Is it possible to prepare a row template for a NSPredicateEditor in IB  
for a predicate like ANY keyPath == 'aValue' ?


Otherwise I found this : http://developer.apple.com/samplecode/PhotoSearch/listing2.html 


If I can't do it in IB, I think it will be the simplest solution :

- (NSPredicate *)predicateWithSubpredicates:(NSArray *)subpredicates
{ /* we only make NSComparisonPredicates */
	NSComparisonPredicate *predicate = (NSComparisonPredicate *)[super  
predicateWithSubpredicates:subpredicates];
 /* construct an identical predicate, but add the  
NSCaseInsensitivePredicateOption flag */
	return [NSComparisonPredicate predicateWithLeftExpression:[predicate  
leftExpression] rightExpression:[predicate rightExpression]  
modifier:NSAnyPredicateModifier type:[predicate predicateOperatorType]  
options:[predicate options]];

}

Thanks
Frédéric___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: NSPredicateEditorRowTemplate and ANY predicate

2008-07-22 Thread Peter Ammon


On Jul 22, 2008, at 12:05 PM, Frédéric Testuz wrote:


Hello,

Is it possible to prepare a row template for a NSPredicateEditor in  
IB for a predicate like ANY keyPath == 'aValue' ?




I'm not sure I understand your question.  How is this different than  
just a normal OR type compound predicate?


-Peter

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


NSPredicateEditorRowTemplate

2008-07-04 Thread Chris


I have a custom view in a NSPredicateEditorRowTemplate. It seems like  
the NSPredicateEditor isn't aware when I change the state of the  
custom view, because when I ask it for the predicate it just returns  
the old one without even calling predicateWithSubPredicates on my  
template. I'm guessing that NSPredicateEditor installs some kind of  
callback on the components and needs to know when they change, but  
being inexperienced with Cocoa, I'm not sure what it might be or how  
to implement it. I tried calling sendActionTo: with the action on the  
custom component when it changes, but that didn't seem to help.



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


NSPredicateEditorRowTemplate

2008-06-24 Thread Chris
I've got a NSPredicateEditor and I'm inheriting from
NSPredicateEditorRowTemplate to make a custom template. It implements
copyWithZone as the doco seems to imply I should. In Interface builder I
have a number of standard row templates, and I've added my custom one at the
end by setting the class in the identity pane.

When I load the nib containing the NSPredicateEditor, for some reason it
calls copyWithZone on my custom NSPredicateEditorRowTemplate during the nib
loading process. Let's call this object passed to copyWithZone as object
A, and I return from copyWithZone as instance B. So now there are two
instances created during the nib loading process. Nothing in the
documentation seems to explain why this would happen during nib
loading. From my reading of the doco, it should only get called when I do a
setObjectValue on the NSPredicateEditor.
Anyway, when I call setObjectValue, it does indeed call copyWithZone again
with object A and creates another object. Let's call this one C. It then
calls setPredicate on object C as you'd expect, whereupon I populate the
fields of MyCustomPredicateRowTemplate.

When the user clicks ok, then I call objectValue on the NSPredicateEditor
and it calls predicateWithSubpredicates not on object C, but on object
B, which is always going to be blank, because it is in fact object C
which is the one displayed. Thus I can never retrieve values from the row.
This phantom and unexplained object B that is created during NIB loading
suddenly seems to be the one it cares about.

I'm not sure where to go next. Has anyone got any advice?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: NSPredicateEditorRowTemplate

2008-06-24 Thread Jim Turner
On Tue, Jun 24, 2008 at 2:02 AM, Chris [EMAIL PROTECTED] wrote:
 When the user clicks ok, then I call objectValue on the NSPredicateEditor
 and it calls predicateWithSubpredicates not on object C, but on object
 B, which is always going to be blank, because it is in fact object C
 which is the one displayed. Thus I can never retrieve values from the row.
 This phantom and unexplained object B that is created during NIB loading
 suddenly seems to be the one it cares about.

 I'm not sure where to go next. Has anyone got any advice?

Hi Chris,

I saw this very same behavior and was fortunate enough to get the
following explanation from Peter Ammon:

A single row may be composed of views from multiple templates.  When
it's time to construct a predicate for that row, we pick one template,
and if its views are not actually in the row, we call objectValue on
the view in the row, and then setObjectValue: on the corresponding
view in your template.

Due to a bug, this happens more often than it should :(

What this means for your NSTextField subclass is that it should do the
right thing for objectValue and setObjectValue:.  The object value of
your view should encapsulate all the state your template needs to
compute that portion of the predicate.

The short answer, for me at least, was to make sure my custom
NSTextField in my template handled objectValue/setObjectValue:
properly.  That way, when predicateWithSubpredicates: is called, the
internals of the editor can pass around the values needed to properly
compute the predicate.

-- 
Jim
http://nukethemfromorbit.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: NSPredicateEditorRowTemplate

2008-06-24 Thread Chris


Hi!

This is very interesting information. Wish it was in the doco!

I have a custom view which wasn't responding to setObjectValue /  
objectValue.


When I add those methods I find that on startup it does indeed copy  
the values from object C to object B. This means that when I  
retrieve the values later on, instead of returning blank like before,  
it now returns the old value instead of blank. However I need the new  
value! If it were to copy the values across AFTER the user made  
changes or prior to me calling objectValue, then it would work. I  
thought maybe [rulePredicateEditor reloadPredicate] sounded like it  
might do it perhaps, but that doesn't help either. Once the user hits  
ok, we are still left with bogus values from object B, albeit now  
old values instead of nil values.





On 24/06/2008, at 11:02 PM, Jim Turner wrote:


On Tue, Jun 24, 2008 at 2:02 AM, Chris [EMAIL PROTECTED] wrote:
When the user clicks ok, then I call objectValue on the  
NSPredicateEditor
and it calls predicateWithSubpredicates not on object C, but on  
object
B, which is always going to be blank, because it is in fact  
object C
which is the one displayed. Thus I can never retrieve values from  
the row.
This phantom and unexplained object B that is created during NIB  
loading

suddenly seems to be the one it cares about.

I'm not sure where to go next. Has anyone got any advice?


Hi Chris,

I saw this very same behavior and was fortunate enough to get the
following explanation from Peter Ammon:

A single row may be composed of views from multiple templates.  When
it's time to construct a predicate for that row, we pick one template,
and if its views are not actually in the row, we call objectValue on
the view in the row, and then setObjectValue: on the corresponding
view in your template.

Due to a bug, this happens more often than it should :(

What this means for your NSTextField subclass is that it should do the
right thing for objectValue and setObjectValue:.  The object value of
your view should encapsulate all the state your template needs to
compute that portion of the predicate.

The short answer, for me at least, was to make sure my custom
NSTextField in my template handled objectValue/setObjectValue:
properly.  That way, when predicateWithSubpredicates: is called, the
internals of the editor can pass around the values needed to properly
compute the predicate.

--
Jim
http://nukethemfromorbit.com


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: NSPredicateEditorRowTemplate

2008-06-24 Thread Jim Turner
On Tue, Jun 24, 2008 at 8:46 AM, Chris [EMAIL PROTECTED] wrote:

 Hi!
 This is very interesting information. Wish it was in the doco!
 I have a custom view which wasn't responding to setObjectValue /
 objectValue.
 When I add those methods I find that on startup it does indeed copy the
 values from object C to object B. This means that when I retrieve the
 values later on, instead of returning blank like before, it now returns the
 old value instead of blank. However I need the new value! If it were to copy
 the values across AFTER the user made changes or prior to me calling
 objectValue, then it would work. I thought maybe [rulePredicateEditor
 reloadPredicate] sounded like it might do it perhaps, but that doesn't help
 either. Once the user hits ok, we are still left with bogus values from
 object B, albeit now old values instead of nil values.

How are you accessing your custom view's object value?  It almost
sounds like you're asking your original custom view for it's value
each time instead of the object currently being displayed.

When you create your template and insert your custom view, make sure
to keep a reference to that specific object so you can query it later
on.

@interface CustomPredicateEditorRowTemplate : NSPredicateEditorRowTemplate
{
CustomTextField *myTextField;
}
-(CustomTextField *) myTextField;
@end

@implementation CustomPredicateEditorRowTemplate
-(CustomTextField *) myTextField
{
if( !myTextField )
// init your view

return( myTextField );
}

- (NSArray *)templateViews
{
return( [[super templateViews] arrayByAddingObject:[self myTextField]] );
}

-(void) dealloc
{
[myTextField release];
[super dealloc];
}

- (NSPredicate *)predicateWithSubpredicates:(NSArray *)subpredicates
{
id objectValue = [[self myTextField] objectValue];
// Do magical things with objectValue
}
@end


-- 
Jim
http://nukethemfromorbit.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: NSPredicateEditorRowTemplate: Custom templateView state

2008-06-04 Thread Mario Fischer

Hi Peter,

yes of course, thanks!

Am 04.06.2008 um 22:27 schrieb Peter Ammon:


On Jun 3, 2008, at 12:05 PM, Mario Fischer wrote:


Hi -

- I use the NSPredicateEditor with a custom  
NSPredicateEditorRowTemplate

- This custom component should implement something like this:
[Filesize] - [is smaller/greater than] - [Textfield] - [KB/MB/GB]

By overriding templateViews I'm able to add an additional  
NSPopupButton to the existing ones:


- (NSArray *)templateViews
{
NSArray* myviews = [super templateViews];
NSPopUpButton* myButton = [[NSPopUpButton alloc] init];
	[myButton addItemsWithTitles:[NSArray arrayWithObjects:@KB,  
@MB, @GB, nil]];
	return [NSArray arrayWithObjects: [myviews objectAtIndex:0], 
[myviews objectAtIndex:1],[myviews objectAtIndex:2], myButton, nil];

}

But in predicateWithSubpredicates I can't find out, which of the  
entries the user selected:


- (NSPredicate *)predicateWithSubpredicates:(NSArray *)subpredicates
{
	[[[self templateViews] objectAtIndex:1] titleOfSelectedItem]; //  
works
	[[[self templateViews] objectAtIndex:3] titleOfSelectedItem]; //  
is always the first entry, regardless of the user selection..

...
}

What am I missing here / doing wrong?


Hi Mario,

Your code is creating a new instance of NSPopUpButton with every  
call to templateViews.   When you call templateViews again to check  
the value of the last popup, you get a different popup every time.


It looks like maybe you just accidentally declared myButton as a  
local variable instead of an instance variable.


-Peter


Mario Fischer | [EMAIL PROTECTED]


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


NSPredicateEditorRowTemplate: Custom templateView state

2008-06-03 Thread Mario Fischer

Hi -

- I use the NSPredicateEditor with a custom NSPredicateEditorRowTemplate
- This custom component should implement something like this:
[Filesize] - [is smaller/greater than] - [Textfield] - [KB/MB/GB]

By overriding templateViews I'm able to add an additional  
NSPopupButton to the existing ones:


- (NSArray *)templateViews
{
NSArray* myviews = [super templateViews];
NSPopUpButton* myButton = [[NSPopUpButton alloc] init];
	[myButton addItemsWithTitles:[NSArray arrayWithObjects:@KB, @MB,  
@GB, nil]];
	return [NSArray arrayWithObjects: [myviews objectAtIndex:0],[myviews  
objectAtIndex:1],[myviews objectAtIndex:2], myButton, nil];

}

But in predicateWithSubpredicates I can't find out, which of the  
entries the user selected:


- (NSPredicate *)predicateWithSubpredicates:(NSArray *)subpredicates
{
[[[self templateViews] objectAtIndex:1] titleOfSelectedItem]; // works
	[[[self templateViews] objectAtIndex:3] titleOfSelectedItem]; // is  
always the first entry, regardless of the user selection..

...
}

What am I missing here / doing wrong?

Thanks in advance,
Mario


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Custom NSPredicateEditorRowTemplate with Single Item

2008-05-20 Thread Steven Huey

Peter,

On May 19, 2008, at 6:58 PM, Peter Ammon wrote:

You're probably receiving this (admittedly opaque) error because  
you're not implementing the NSCopying protocol.  Since a predicate  
editor can have multiple, identical rows, your templates are copied  
before their views are added to the predicate editor.  If you  
subclass NSPredicateEditorRowTemplate and add a view to it, you must  
ensure that each copy has a new instance of the view.


I wasn't aware of that, but will keep that in mind since I have a few  
other custom templates to build.



However, there's an easier way to create a one-popup template:

- Select the row template in IB
- In the inspector, configure the row template to have whichever  
left expression type you want to have appear in your predicate (key  
paths or constant values).
- Double click on the popup in the template, and give it whatever  
title you want.
- Create a subclass of NSPredicateEditorRowTemplate, and override  
templateViews to only return the first view:


- (NSArray *)templateViews {
   return [NSArray arrayWithObject:[[super templateViews]  
objectAtIndex:0]];

}

- In IB again, change the row template's class to your subclass.


This works perfectly, thanks! It hadn't occurred to me to just  
override templateViews and return just the first item, but I really  
like the approach.


Best regards,
Steven Huey

--
Steven Huey Software - http://www.stevenhuey.com




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Custom NSPredicateEditorRowTemplate with Single Item

2008-05-19 Thread Steven Huey

Hello,

I'm trying to create a custom NSPredicateEditorRowTemplate subclass  
that has a single view, an NSPopUpButton with a single item and am  
having some trouble. Basically what I'm trying to do is create a  
predicate like the one in Apple Mail when creating a rule for handling  
e-mail in which you can select Any Message.


In my subclass I have:

- (id)initWithView:(NSView *)view
{
if (self = [super initWithLeftExpressions:[NSArray  
arrayWithObject:[NSExpression  
expressionForConstantValue:@kAnyCalendar]]

 rightExpressionAttributeType:NSBooleanAttributeType
 modifier:NSDirectPredicateModifier
operators:[NSArray  
arrayWithObject:[NSNumber  
numberWithInteger:NSEqualToPredicateOperatorType]]

  options:0]) {

self.parentView = view;
}
}

- (NSArray *)templateViews {
return [self.parentView subviews]; // This returns my single  
NSPopUpButton instance

}


In my controller I have an outlet variable named predicateView set to  
a NSView in my NIB that has a single NSPopUpButton instance, and I'm  
configuring the NSPredicateEditor as follows:


[predicateEditor setRowTemplates:[NSArray arrayWithObject: 
[[AnyCalendarTemplate alloc] initWithView:predicateView]]];


When I call [predicateEditor addRow:self] an exception is thrown and  
my application crashes:


2008-05-19 14:48:51.614 PredicateDebugger[15062:10b] *** Terminating  
app due to uncaught exception 'NSInternalInconsistencyException',  
reason: 'In NSPredicateEditor: 0x1023aa0, different number of items  
(1) than predicate template views (0) for template  
AnyCalendarTemplate 0x105a7c0: [kAnyCalendar] [4]  
NSBooleanAttributeType'


I've tried different settings for the NSPredicateEditor in IB, and  
also tried returning more than one view or type of view in my custom  
row template, all without luck.


Does anyone have any sample code or suggestions to help me get this  
working?


Thanks,
Steve

--
Steven Huey Software - http://www.stevenhuey.com




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Custom NSPredicateEditorRowTemplate with Single Item

2008-05-19 Thread Peter Ammon


On May 19, 2008, at 12:05 PM, Steven Huey wrote:


Hello,

I'm trying to create a custom NSPredicateEditorRowTemplate subclass  
that has a single view, an NSPopUpButton with a single item and am  
having some trouble. Basically what I'm trying to do is create a  
predicate like the one in Apple Mail when creating a rule for  
handling e-mail in which you can select Any Message.




When I call [predicateEditor addRow:self] an exception is thrown and  
my application crashes:


2008-05-19 14:48:51.614 PredicateDebugger[15062:10b] *** Terminating  
app due to uncaught exception 'NSInternalInconsistencyException',  
reason: 'In NSPredicateEditor: 0x1023aa0, different number of  
items (1) than predicate template views (0) for template  
AnyCalendarTemplate 0x105a7c0: [kAnyCalendar] [4]  
NSBooleanAttributeType'


Hi Steven,

You're probably receiving this (admittedly opaque) error because  
you're not implementing the NSCopying protocol.  Since a predicate  
editor can have multiple, identical rows, your templates are copied  
before their views are added to the predicate editor.  If you subclass  
NSPredicateEditorRowTemplate and add a view to it, you must ensure  
that each copy has a new instance of the view.


However, there's an easier way to create a one-popup template:

- Select the row template in IB
- In the inspector, configure the row template to have whichever left  
expression type you want to have appear in your predicate (key paths  
or constant values).
- Double click on the popup in the template, and give it whatever  
title you want.
- Create a subclass of NSPredicateEditorRowTemplate, and override  
templateViews to only return the first view:


- (NSArray *)templateViews {
return [NSArray arrayWithObject:[[super templateViews]  
objectAtIndex:0]];

}

- In IB again, change the row template's class to your subclass.

Hope that's clear.  Let me know if you have any questions.

-Peter

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: NSPredicateEditorRowTemplate and templateView delegates

2008-04-28 Thread Peter Ammon


On Apr 28, 2008, at 8:12 AM, Jim Turner wrote:


I've a NSPredicateEditor with some basic popup-popup-view style
templates (where the view is a NSTextField).  I am attempting to set
the text field's delegate to one of my objects so I can be notified
when the control text changes.  Everything appears to be setup
correctly except my controlTextDidChange: never gets called.  I'm
setting the delegate in my view controller's awakeFromNib: as such:


[snip code]



and 'self' does implement controlTextDidChange:  I realize the
template gets copied when it's used by the editor and I wonder if the
delegate isn't getting copied as well.  Is there a better way of
setting the delegate of a text field in a
NSPredicateEditorRowTemplate?


Hi Jim,

As you surmised, delegates are not propagated by copy.

NSPredicateEditor posts NSControlTextDidChangeNotification, with  
itself as the notification object, whenever any of its text fields  
changes.  If you ask for the predicate editor's object value at that  
point, it will reflect any edits in the text field.  That's the  
simplest way to get the filter-as-you-type behavior that I suspect you  
want.


Let me know if that doesn't answer your question,
-Peter

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]