Remove NSTableView Default Selection

2009-09-24 Thread John McIntosh
Hello all. I am working on an application that contains a NSTableView.
The table view has a single column which display several options.
Based on the row that the user selects, something is displayed. When
the application is first launched, the first row in the table is
selected by default (but not processed as a selection because it was
not actually clicked). I want no rows to be selected when it is first
launched. So, the functionality is correct now, but I need the first
(or any other) row not to be preselected.

I have a button to clear the selection. In its code, I send a
deselectAll message to the table which correctly clears the selection.
I assumed that I could send the same deselectAll message in either an
awakeFromNib function or applicationDidFinishLaunching. However,
neither of these clears the selection.

I would greatly appreciate any advice. Thank you.

John
___

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: Remove NSTableView Default Selection

2009-09-25 Thread John McIntosh
Perfect, thank you! I have the table bound to a core data source and
did not know about the "avoid empty selection" option in the
controller. Unckecking that box took care of it.

John

On Thu, Sep 24, 2009 at 10:12 PM, Jens Alfke  wrote:
>
> On Sep 24, 2009, at 5:07 PM, John McIntosh wrote:
>
>> I assumed that I could send the same deselectAll message in either an
>> awakeFromNib function or applicationDidFinishLaunching. However,
>> neither of these clears the selection.
>
> Make sure you've checked the table's "Empty" checkbox (allow empty
> selection) in the nib.
> Also, if there's a controller bound to the table, uncheck its "Avoid empty
> selection" checkbox.
>
> —Jens
___

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: Core Data Calculated Properties [solved]

2009-09-29 Thread John McIntosh
After more research, I found my solution in the NSPersistentDocument
Tutorial. If anyone else has this problem, I needed to implement the
following method in the subclass for my entity:

+ (NSSet *)keyPathsForValuesAffectingProperty3{
return [NSSet setWithObjects:@"property1", @"property2", nil];
}

Also, declare the property in the entity's subclass header like this:

@property (nonatomic, readonly) NSString * property3;




On Tue, Sep 29, 2009 at 1:32 PM, John McIntosh
 wrote:
> Hi all. I am working on a core data application and am having some
> difficulty understanding how to configure a particular aspect of it.
>
> I am using an nstable to display a selection of properties from my
> core data managed object. I have the properties bound to the columns
> in the table and set to Continuously Updates Value. For most
> properties this works as expected.
>
> For example, I have a button that loads a value into property1. When
> pressed, the value is automatically updated in the table. I have
> another button that loads a different value into property2. Again,
> this is automatically updated. Lastly, the value of property3 should
> be the result of a function based on properties1 and 2. I have
> declared property3 as a transient value and have subclassed my entity.
> In the .m file for my subclass I have the following function:
>
> -(NSString *)property3{
>        NSString *p1 = [self valueForKey:@"property1"];
>        NSString *p2 = [self valueForKey:@"property2"];
>
>        NSMutableString *result = "";
>        [result stringByAppendingString[p1]];
>        [result stringByAppendingString[p2]];
>
>        return result;
> }
>
> In the GUI, when I press the buttons, the columns for property1 and
> property2 update immediately. However, the column with property3 only
> updates when something else changes in the table. For example,
> clicking a row or making another entry.
>
> Is this the correct setup for having a calculated value? If so, is
> there a way I can force the table to retrieve the new calculated value
> any time another property changes?
>
___

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


Core Data Calculated Properties

2009-09-29 Thread John McIntosh
Hi all. I am working on a core data application and am having some
difficulty understanding how to configure a particular aspect of it.

I am using an nstable to display a selection of properties from my
core data managed object. I have the properties bound to the columns
in the table and set to Continuously Updates Value. For most
properties this works as expected.

For example, I have a button that loads a value into property1. When
pressed, the value is automatically updated in the table. I have
another button that loads a different value into property2. Again,
this is automatically updated. Lastly, the value of property3 should
be the result of a function based on properties1 and 2. I have
declared property3 as a transient value and have subclassed my entity.
In the .m file for my subclass I have the following function:

-(NSString *)property3{
NSString *p1 = [self valueForKey:@"property1"];
NSString *p2 = [self valueForKey:@"property2"];

NSMutableString *result = "";
[result stringByAppendingString[p1]];
[result stringByAppendingString[p2]];

return result;
}

In the GUI, when I press the buttons, the columns for property1 and
property2 update immediately. However, the column with property3 only
updates when something else changes in the table. For example,
clicking a row or making another entry.

Is this the correct setup for having a calculated value? If so, is
there a way I can force the table to retrieve the new calculated value
any time another property changes?
___

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


Core Data KVO with To-Many Relationships

2009-10-07 Thread John McIntosh
Hi all.
I am working on a Core Data application which contains an entity that
needs to be notified of changes in entities that it has a relationship
to. Let's talk about this in terms of Apple's example with Departments
and Employees. As described here
(http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/KeyValueObserving/Concepts/DependentKeys.html)
they talk about the example where each Department has a "totalSalary"
attribute and each Employee has a "salary" attribute.

In regards to Core Data, the documentation linked above says this:
"If you're using Core Data, you can register the parent with the
application's notification center as an observer of its managed object
context. The parent should respond to relevant change notifications
posted by the children in a manner similar to that for key-value
observing."

I assume this means that something similar to the code posted
previously in the article should be done. I understand the statement
conceptually, but do not know how to go about implementing it. Here is
my start in the Department entity.

- (void) awakeFromInsert{
 [[NSNotificationCenter defaultCenter]addObserver:self
selector:@selector(methodToCallOnNotification:)   name:???
object:managedObjectContext];
}

If this is the correct start, what should happen in methodToCallOnNotification?
Do I need to remove each Department entity from being an observer when
it is deleted?
What else do I need to be sure to do upon Department or Employee
creation or deletion?

Thank you,

John
___

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: Core Data KVO with To-Many Relationships

2009-10-07 Thread John McIntosh
Since my previous post, I have been able to get the functionality I
was hoping for with the following code in my "Department" subclass. I
would greatly appreciate some feedback as to whether this is an
appropriate way to implement the functionality or if there is a more
efficient or cleaner way.


- (void)awakeFromFetch {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(managedObjectContextDidChange:) name:
NSManagedObjectContextObjectsDidChangeNotification object:[self
managedObjectContext]];
}

- (void)awakeFromInsert {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(managedObjectContextDidChange:) name:
NSManagedObjectContextObjectsDidChangeNotification object:[self
managedObjectContext]];
}

- (void)managedObjectContextDidChange:(NSNotification *)notification {
// Get a set containing ALL objects which have been changed
NSSet *insertedObjects = [[notification userInfo]
objectForKey:NSInsertedObjectsKey];
NSSet *updatedObjects = [[notification userInfo]
objectForKey:NSUpdatedObjectsKey];
NSSet *deletedObjects = [[notification userInfo]
objectForKey:NSDeletedObjectsKey];

//this method of gathering changed objects is because the final set
was always null if the first set was null
NSSet *changedObjects;
if([insertedObjects count] > 0){
changedObjects = [insertedObjects 
setByAddingObjectsFromSet:updatedObjects];
changedObjects = [changedObjects 
setByAddingObjectsFromSet:deletedObjects];
}else{
if([updatedObjects count] > 0){
changedObjects = [updatedObjects 
setByAddingObjectsFromSet:deletedObjects];
}else{
changedObjects = [NSSet setWithSet:deletedObjects];
}
}

if([changedObjects intersectsSet:[self employees]]){
//if an employee in this department changed, indicate
that the totalSalary attribute should be refreshed
[self willChangeValueForKey:@"totalSalary"];
[self didChangeValueForKey:@"totalSalary"];
}   
}



Thank you,

John    

On Mon, Oct 5, 2009 at 1:18 PM, John McIntosh
 wrote:
> Hi all.
> I am working on a Core Data application which contains an entity that
> needs to be notified of changes in entities that it has a relationship
> to. Let's talk about this in terms of Apple's example with Departments
> and Employees. As described here
> (http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/KeyValueObserving/Concepts/DependentKeys.html)
> they talk about the example where each Department has a "totalSalary"
> attribute and each Employee has a "salary" attribute.
>
> In regards to Core Data, the documentation linked above says this:
> "If you're using Core Data, you can register the parent with the
> application's notification center as an observer of its managed object
> context. The parent should respond to relevant change notifications
> posted by the children in a manner similar to that for key-value
> observing."
>
> I assume this means that something similar to the code posted
> previously in the article should be done. I understand the statement
> conceptually, but do not know how to go about implementing it. Here is
> my start in the Department entity.
>
> - (void) awakeFromInsert{
>     [[NSNotificationCenter defaultCenter]    addObserver:self
> selector:@selector(methodToCallOnNotification:)   name:???
> object:managedObjectContext];
> }
>
> If this is the correct start, what should happen in 
> methodToCallOnNotification?
> Do I need to remove each Department entity from being an observer when
> it is deleted?
> What else do I need to be sure to do upon Department or Employee
> creation or deletion?
>
> Thank you,
>
> John
>
___

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