Two TreeControllers, one ArrayController and the ContentSet binding...

  • Hello all,

    I have a CoreData application that has two NSOutlineViews and one
    NSTableView.  Each OutlineView has a TreeController to manage the
    specific data for that OutlineView and the TableView has an
    NSArrayController to manage it's data.

    I have a Node entity that knows about subnodes (or children if you
    prefer) and their related contents.  The two different OutlineView's
    TreeControllers are managing subclasses of this Node entity.  The
    NSArrayController is managing another entity that represents the To-
    Many relationship for a given Node's contents.

    What I am trying to do is have the content of the ArrayController
    change based on the selected node in the TreeControllers.  This isn't
    a problem with one TreeController, but since I have two, I am running
    into trouble and I was hoping someone could help me out.

    My initial idea was to use an NSMutableSet in my main controller
    class and then have the selection of the node load the data I need
    into the MutableSet.  I could then have the NSArrayControllers
    "contentSet" binding set to manage the data in the MutableSet.  I
    have done something similar to this in a different non-CoreData
    project but was wondering if any of you had a better way to handle this?

    Since I am using CoreData, I figure there must be a way to ask the
    ManagedObjectContext for the information I need when the selection
    changes, but I am not sure how to do this and what the bindings setup
    would be.  If someone could point me in the right direction, or
    verify that the idea for using the MuableSet in my main controller
    class is a good one, I would really appreciate it.  I am still
    learning CoreData, and so I am sure there are tricks I just don't
    know about yet.

    Regards,

    k
  • On Oct 16, 2006, at 4:34 PM, Kam Dahin wrote:

    > What I am trying to do is have the content of the ArrayController
    > change based on the selected node in the TreeControllers.  This
    > isn't a problem with one TreeController, but since I have two, I am
    > running into trouble and I was hoping someone could help me out.
    >
    > My initial idea was to use an NSMutableSet in my main controller
    > class and then have the selection of the node load the data I need
    > into the MutableSet.

    That might work. Another option is to have two table views and two
    array controllers, and only one table view is visible to the user at
    any one time.

    Without knowing the whole app design, it's hard to say which approach
    is cleaner.

    > Since I am using CoreData, I figure there must be a way to ask the
    > ManagedObjectContext for the information I need when the selection
    > changes

    What information do you want to ask for?

        - Scott
  • Thanks for the reply Scott --

    Here is a more detailed breakdown of what I am doing.

    The Node entities have a to-many relationship called "mediaFiles" -
    which map to my MediaFile entity.

    I use two different types of Nodes (subclasses of the Node entity)
    "Source" and "Target".  The "Source" type is a read-only
    representation of a folder structure that contains different types of
    media files.  These media files show up in the TableView where the
    user can tag them with meta data.

    The target type of Node stores the media files that the user has
    tagged.  The user can create various numbers of these nodes and each
    of these nodes can contain mediaFile entities.  Basically this type
    of Node creates a new structure of folders with the newly tagged
    media files organized into the locations that the user has created.

    MediaFile entities are displayed in the TableView hold information
    about a particular "real" file.

    So the flow of the app is like this:

    User selects the location of the media files he/she wants to tag.
    User tags these files with the approperiate meta data in the Table view.
    User adds these media files to the target nodes and sub nodes.
    User can select the target nodes to see the files they have tagged
    and continue to edit them.
    or the user can select the various source nodes and edit any
    associated files there.

    I want the user to be able to click on the target nodes and see the
    files they have added to the selected node in the TableView.  This
    way, they can change any of the metadata they need to.  They also can
    always go back up to the source tree and view the media files there,
    so they need to be able to select the source nodes and see the
    original files there.

    To your last question:

    I was wondering if could create a fetch request that would get all of
    the MediaFile entities for the selected node and then set the content
    of the ArrayController with that information?  Basically I am trying
    to do this with the tools that CoreData provides instead of having to
    resort to a more manual approach (the NSMutableSet idea from the
    first email) --

      Hopefully this makes more sense.

    Thanks again for your quick response -- I read your blog all the time
    and Cocoa Dev Central has been a huge part of my Cocoa learning
    experience... So thank you for that also.

    Regards,

    K

    On Oct 16, 2006, at 5:10 PM, Scott Stevenson wrote:

    >
    > On Oct 16, 2006, at 4:34 PM, Kam Dahin wrote:
    >
    >> What I am trying to do is have the content of the ArrayController
    >> change based on the selected node in the TreeControllers.  This
    >> isn't a problem with one TreeController, but since I have two, I am
    >> running into trouble and I was hoping someone could help me out.
    >>
    >> My initial idea was to use an NSMutableSet in my main controller
    >> class and then have the selection of the node load the data I need
    >> into the MutableSet.
    >
    > That might work. Another option is to have two table views and two
    > array controllers, and only one table view is visible to the user at
    > any one time.
    >
    > Without knowing the whole app design, it's hard to say which approach
    > is cleaner.
    >
    >> Since I am using CoreData, I figure there must be a way to ask the
    >> ManagedObjectContext for the information I need when the selection
    >> changes
    >
    > What information do you want to ask for?
    >
    > - Scott
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/<kamd...>
    >
    > This email sent to <kamd...>
    >
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today