Should I be trying to use bindings for this?

  • I'm about to give up on bindings for a part of my user interface.
    This is a non-document-based application.

    I have a array in my appController called operationTypes which
    contains objects of class OperationType. These are all the operations
    that can be performed in a production facility.

    I have an array in my appController called workCenters which contains
    objects of class WorkCenter. These are the divisions within the
    facility that do the work (like departments).

    A workCenter can perform one or many operationTypes, so each
    workCenter has an instance variable array called operationTypes.

    I want an interface that will allow the user to specify the
    operationTypes that a workCenter can do. I have successfully bound
    the workCenters array to a table on the top half of the window. The
    user clicks on the workCenter to see the operationTypes that it can
    do. This part works great.

    I am trying to successfully bind (in Master-Detail fashion) another
    table, on the bottom of the window, containing the instance variable
    array of operationTypes for the workCenter selected in the top table.

    I put an NSPopupButton into the column so that I can choose from the
    total list of operationTypes.

    With mmalc's help some time ago I thought I was able to get this to
    work. Visually, it works fine and error free. The key was to set up
    an NSArrayController which has for content the selection of the
    WorkCenters array controller.

    But now I have found that the objects in the operationTypes instance
    variable array are not the same objects that are in my "global"
    operationTypes array as I expected them to be. They are some kind of
    copy, or created objects that must be being created by my binding.
    This is a problem for me.

    Is it advisable to use bindings for this? From my readings it seems
    so, but I have spent days and days and my stomach hurts :(
  • On 10/3/07, Paul Bruneau <paul_bruneau...> wrote:
    > I'm about to give up on bindings for a part of my user interface.
    > This is a non-document-based application.

      It's not a perfect fit for everything.

    > But now I have found that the objects in the operationTypes instance
    > variable array are not the same objects that are in my "global"
    > operationTypes array as I expected them to be. They are some kind of
    > copy, or created objects that must be being created by my binding.
    > This is a problem for me.

      Why is this a problem? Are you aware that NSArrayController passes
    you a *proxy* object that represents your actual object? What are you
    trying to do that requires them to be the exact same object (maybe we
    can suggest a better way of getting at it)?

    > Is it advisable to use bindings for this? From my readings it seems
    > so, but I have spent days and days and my stomach hurts :(

      I don't see what you've described as being too difficult a problem
    but the part you left out is what you're doing that you need the
    objects to be exactly the same (why the proxy won't do and how you're
    trying to access the objects).

    --
    I.S.
  • On Oct 3, 2007, at 11:27 AM, I. Savant wrote:

    > On 10/3/07, Paul Bruneau <paul_bruneau...> wrote:
    >> I'm about to give up on bindings for a part of my user interface.
    >> This is a non-document-based application.
    >
    > It's not a perfect fit for everything.
    >
    >> But now I have found that the objects in the operationTypes instance
    >> variable array are not the same objects that are in my "global"
    >> operationTypes array as I expected them to be. They are some kind of
    >> copy, or created objects that must be being created by my binding.
    >> This is a problem for me.
    >
    > Why is this a problem? Are you aware that NSArrayController passes
    > you a *proxy* object that represents your actual object?

    Shamefully, no. I'll go re-re-read about NSArrayControllers.

    > What are you
    > trying to do that requires them to be the exact same object (maybe we
    > can suggest a better way of getting at it)?

    Because later, when I want to schedule a workOrder, my app has to
    step through all the orderSteps of that order to see what
    operationType they are, and I have to check to see what workCenters
    are available to take on each of those steps. In order to see if a
    workCenter is able to do that kind of work, I look to see if the
    workCenter's operationTypes array contains the same operationType as
    is required by the orderStep.

    >> Is it advisable to use bindings for this? From my readings it seems
    >> so, but I have spent days and days and my stomach hurts :(
    >
    > I don't see what you've described as being too difficult a problem
    > but the part you left out is what you're doing that you need the
    > objects to be exactly the same (why the proxy won't do and how you're
    > trying to access the objects).

    It could very well be that I am Doing It Wrong™. I am very open to
    hearing how I might do it better.
  • >> Why is this a problem? Are you aware that NSArrayController passes
    >> you a *proxy* object that represents your actual object?
    >
    > Shamefully, no. I'll go re-re-read about NSArrayControllers.

      I can't recall, but I *believe* this is mentioned in the
    documentation. You can find undocumented (private API) ways of getting
    at the object directly via the proxy, but ... yuck.

    > Because later, when I want to schedule a workOrder, my app has to
    > step through all the orderSteps of that order to see what
    > operationType they are, and I have to check to see what workCenters
    > are available to take on each of those steps. In order to see if a
    > workCenter is able to do that kind of work, I look to see if the
    > workCenter's operationTypes array contains the same operationType as
    > is required by the orderStep.

      Okay, so if you ask for its orderSteps using -valueForKey: or
    -valueForKeyPath: you should get what you're looking for (ie, no
    proxy). You can ask the proxy for any KVC-compliant property and
    you'll get real objects in response. I'm not sure based on your
    description if this is sufficient for your purposes, but it's worth
    mentioning.

      Caveat: I may totally be misunderstanding your description. Take the
    above with a grain of salt.

    > It could very well be that I am Doing It Wrong™. I am very open to
    > hearing how I might do it better.

      Almost certainly. :-)

    --
    I.S.
  • On Oct 3, 2007, at 1:19 PM, I. Savant wrote:

    > Okay, so if you ask for its orderSteps using -valueForKey: or
    > -valueForKeyPath: you should get what you're looking for (ie, no
    > proxy). You can ask the proxy for any KVC-compliant property and
    > you'll get real objects in response. I'm not sure based on your
    > description if this is sufficient for your purposes, but it's worth
    > mentioning.
    >
    > Caveat: I may totally be misunderstanding your description. Take the
    > above with a grain of salt.

    I think you lost me there. I don't care if the array controller is a
    proxy, but I want the objects in it to be the real ones.

    Let me reference something all of us can look at. If you can, run
    mmalc's combatants example. See how you can choose the weapon for an
    attacker? Now pretend that each attacker can have an array of weapons
    instead of just one, chosen from a list of weapons he can buy.

    How, using bindings, might I set up the interface to let the user
    edit the list of weapons in an attacker's possession?

    I want the attacker to have an instance variable array containing the
    weapons, and I want the array to contain pointers to the actual
    weapon objects.

    I hope that clarifies what I am looking to do.
  • I am in the middle of my own journey to using Bindings, but I have some questions for you.  Your answers might solve your problem.

      1) Why do you insist on pointer comparison for OperationTypes instances.  Why not inplement -compare: and test for equality of two OperationTypes instances with compare:?  Then it doesn't matter if theye are different instances or not if the compare as NSOrderedSame.

      2) Why don't you just write [workCentersArrayController valueForKeyPath: @"selection.operationTypes"].  Assuming that the selected WorkCenter instance actually has an array instance variable called "operationTypes", the above code should retrun that array as an NSArray.  Whatever is in the returned NSArray is what is in the instance variable, so if the OperationTypes instances have unexpected pointer values, the problem occured when the array was filled and not when it was returned.
  • You could create a 2nd array controller and have its arranged objects
    attached to your 1st array controller's selected item at a key path of
    "weapons". This allows you too dynamically associate a 2nd controller
    for a another list box based on the selection of another. This should
    work well really well. Then its all dynamic and you have very little
    code except for basic accessors. Doing an addObject on the 2nd
    controller will add your new weapons to the backing NSMutableArray.

    Scott

    On Oct 3, 2007, at 11:18 AM, Paul Bruneau wrote:

    > On Oct 3, 2007, at 1:19 PM, I. Savant wrote:
    >
    >> Okay, so if you ask for its orderSteps using -valueForKey: or
    >> -valueForKeyPath: you should get what you're looking for (ie, no
    >> proxy). You can ask the proxy for any KVC-compliant property and
    >> you'll get real objects in response. I'm not sure based on your
    >> description if this is sufficient for your purposes, but it's worth
    >> mentioning.
    >>
    >> Caveat: I may totally be misunderstanding your description. Take the
    >> above with a grain of salt.
    >
    > I think you lost me there. I don't care if the array controller is a
    > proxy, but I want the objects in it to be the real ones.
    >
    > Let me reference something all of us can look at. If you can, run
    > mmalc's combatants example. See how you can choose the weapon for an
    > attacker? Now pretend that each attacker can have an array of
    > weapons instead of just one, chosen from a list of weapons he can buy.
    >
    > How, using bindings, might I set up the interface to let the user
    > edit the list of weapons in an attacker's possession?
    >
    > I want the attacker to have an instance variable array containing
    > the weapons, and I want the array to contain pointers to the actual
    > weapon objects.
    >
    > I hope that clarifies what I am looking to do.
  • On Oct 3, 2007, at 4:01 PM, Scott Andrew wrote:

    > You could create a 2nd array controller and have its arranged
    > objects attached to your 1st array controller's selected item at a
    > key path of "weapons". This allows you too dynamically associate a
    > 2nd controller for a another list box based on the selection of
    > another. This should work well really well. Then its all dynamic
    > and you have very little code except for basic accessors. Doing an
    > addObject on the 2nd controller will add your new weapons to the
    > backing NSMutableArray.

    Yes in fact that is what mmalc taught me to do earlier and it does
    work well. I think my problem was that I was trying to do it with an
    NSPopupButton imbedded into my table's column. So I think my
    interface idea was my main fault.

    Thank you!
  • On Oct 3, 2007, at 3:36 PM, Erik Buck wrote:

    > I am in the middle of my own journey to using Bindings, but I have
    > some questions for you.  Your answers might solve your problem.
    >
    > 1) Why do you insist on pointer comparison for OperationTypes
    > instances.  Why not inplement -compare: and test for equality of
    > two OperationTypes instances with compare:?  Then it doesn't matter
    > if theye are different instances or not if the compare as
    > NSOrderedSame.

    That approach seems reasonable to me, I considered something similar
    but was lured in by the simplicity of the NSArray containsObject:
    method and it just seemed clean and nice. It is probably better for
    me to use something like an INT operation code in the operationType
    object and compare that so that I'm not so reliant on the exact
    operationType object always being in existence for things to work.

    > 2) Why don't you just write [workCentersArrayController
    > valueForKeyPath: @"selection.operationTypes"].  Assuming that the
    > selected WorkCenter instance actually has an array instance
    > variable called "operationTypes", the above code should retrun that
    > array as an NSArray.  Whatever is in the returned NSArray is what
    > is in the instance variable, so if the OperationTypes instances
    > have unexpected pointer values, the problem occured when the array
    > was filled and not when it was returned.

    My problem wasn't with accessing the information from code, I was OK
    in that respect. My problem was with the interface and the binding.

    Thanks for writing!
previous month october 2007 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