Drag and drop question - re-using a view.

Jos Yule's Avatar

Jos Yule

07 Dec, 2009 02:07 AM

Hello all.

How, using MVC, do we implement Drag and Drop of items, from one component to another, while re-using a view from one component?

For example: Lets say we have some kind of app, with a palette of items on the left, and a workspace on the right. Items can be dragged from the palette to the workspace, and then dropped into the workspace.

When moving an item from the palette to the workspace, i need to re-parent the view, from the palette view to the workspace view.

I'm triggering a command when an item is dropped on the workspace. This command removes the item's Model from the paletteModel, and adds it to the Workspace's model. What i'd like to do, is to reuse the existing view, but i don't know how to do that in a non-hacky way (the respective Models send up update events, and the mediators then add/remove the model item as needed, and currently, create a new view - this is what i'd like to avoid).

You can see an example sequence diagram here:
http://tiny.cc/rGv2l

This is an example - its not exactly how i'd do it, or even how i am doing it right now, but it is something to start from. I'd rather talk at a higher level then actual code, if that's possible. I don't need a specific implementation, but an architectural approach for solving this class of problems... You dig? Although i wouldn't say no to chatting about code either, just don't get hung-up on this example.

I was thinking that the ItemView might just be dumb, and not have a mediator itself (the PaletteMediator/WorkspaceMediator) would take care of it)...

Really, i just need a way of letting the WorkspaceMediator know that there is a pre-existing view for a certain ItemModel, and to use it rather then create a new one...

Whew, that was way over complicated. When i simplify it down to that, maybe i should be using a "view" model, which contains info about views... Naa, that sounds crazy...

Anyway, any suggestions, help, links, jeers, etc are appreciated!

Thanks a lot,
jos

  1. 1 Posted by Jos Yule on 09 Dec, 2009 04:56 PM

    Jos Yule's Avatar

    I've done some more simplification of this - here is the new sequence diagram.

    http://tiny.cc/MNYwF

    It is better, but i feel like i shouldn't be passing the displayObject around.. But it works, and follows most of the guidelines in the best practices doc..

  2. Support Staff 2 Posted by Shaun Smith on 11 Dec, 2009 02:42 PM

    Shaun Smith's Avatar

    Hi Jos,

    I feel terrible that I haven't had a chance to look at this at all. Hopefully someone else will get a chance to dig into it with you, or I'll manage to free up some time soon.

    I'm not sure if this is even remotely related, but don't forget that mediators can be mapped in such a way as to be auto-created, but to require manual removal - this might help with re-parenting issues. Or it might have nothing to do with anything!

  3. Support Staff 3 Posted by Shaun Smith on 11 Dec, 2009 02:46 PM

    Shaun Smith's Avatar

    Looking very briefly at your latest sequence diagram, and thinking about your statement "i feel like i shouldn't be passing the displayObject", perhaps you don't need to.

    Maybe you could have a model that maps DOs to VOs. Then all you'd need to do is pass the VOs around - if anything needs the DO associated with a VO it can just look it up in the model. Again, I haven't looked into your specific needs yet, it was just a thought.

  4. 4 Posted by Jos Yule on 11 Dec, 2009 03:17 PM

    Jos Yule's Avatar

    That was the direction i was going - i just wasn't sure if a Model could/should store that info... But that's what a Model does, right?

    Anyway, thanks for even looking at this - i know its of questionable relevancy to RL... but it does relate to MVC, although in a more general, non-rl way...

    I went ahead with the system I worked out in the previous email - its working fine. But i think for next time i'll go with your suggestion - a DO to VO Model. At the least, i'll try it out.

    Thanks for spending some of your valuable time with this - i really appreciate it.

    jos

  5. Support Staff 5 Posted by Shaun Smith on 11 Dec, 2009 03:36 PM

    Shaun Smith's Avatar

    Hey, no problem =)

    It depends on how you define what a Model is. I tend to view Models in my Flex/Flash apps as Models of front-end application state. I avoid having too much view specific state information, but I do have some models that exist purely to manage view related stuff.

    PureMVC tends to promote the idea of models (proxies) as gatekeepers of server-side state. I leave most of that kind of state to my server, and talk to it via Services. My models are for my app - and sometimes that includes view state.

    Cheers,
    shaun

  6. Shaun Smith closed this discussion on 11 Dec, 2009 03:36 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac