RE: NSOutlineView from Java solved?
RE: NSOutlineView from Java solved?
- Subject: RE: NSOutlineView from Java solved?
- From: "Kent Smotherman" <email@hidden>
- Date: Thu, 12 Jul 2001 09:57:29 -0500
Thanks for the update! I had tried something along these lines with a Vector
holding the Strings or other Java objects but it didn't work, it seems the
difference is that NSOutlineView needs to have NSObjects of some sort
instead of java Objects. Weird.
On another note, one concern I had (although I gave up on NSOutlineView
before I answered this particular concern) is when methods like
outlineViewChildOfItem get called. I know from working with NSTableView that
it's data access methods get called a TON so I was concerned that a work
around of this type for NSOutlineView would be problematic since there would
be no good way to know when to allocate these objects and when not to. If,
as I hope and suspect, NSOutlineView only calls things like
outlineViewChildOfItem once (until you tell it the data has changed anyway)
then it would be a suitable work around.
Kent =)
-----Original Message-----
From: Doug Knowles (PB) [
mailto:email@hidden]
Sent: Thursday, July 12, 2001 9:44 AM
To: CocoaDev
Cc: Kent Smotherman
Subject: NSOutlineView from Java solved?
I may have overcome the previously discussed problem of NSOutlineView
losing track of Java objects.
Briefly, instead of passing Java objects (such as String's, which I had
been using) out of my DataSource's outlineViewChildOfItem() method (for
example), I instantiate Objective-C objects as proxies of the Java objects I
would otherwise pass to NSOutlineView. The rationale is that the Obj-C
runtime will retain objects created from Java code, satisfying the dictum
that the DataSource is obliged to retain the objects.
I'm still refining my solution, but here are some of the details:
- It seems to be acceptable to simply construct a unique NSObject() for
each item to be represented in the NSOutlineView. I originally used an
NSMutableString to contain an identification string for the "real" object,
but it proved easier to use content-free NSObjects and maintain a Hashtable
to associate them with the original Java objects on subsequent calls into my
DataSource.
- The Java Hashtable seems to be sufficient to maintain references to the
NSObjects (and thus "retain" them). Initially I was adding them to an
Objective-C container (NSMutableArray), but I backed out the use of this
container and everything still appears to work.
That's the gist of it. I'm not ready to share source yet, because my
implementation has become badly butchered by trial-and-error programming.
Doug K;