tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/17-drag-and-drop-question-re-using-a-viewRobotlegs: Discussion 2013-04-28T10:30:50Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/6848712009-12-07T02:07:50Z2009-12-07T02:07:50ZDrag and drop question - re-using a view. <div><p>Hello all.</p>
<p>How, using MVC, do we implement Drag and Drop of items, from one
component to another, while re-using a view from one component?</p>
<p>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.</p>
<p>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.</p>
<p>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).</p>
<p>You can see an example sequence diagram here:<br>
<a href="http://tiny.cc/rGv2l">http://tiny.cc/rGv2l</a></p>
<p>This is an <em>example</em> - 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.</p>
<p>I was thinking that the ItemView might just be dumb, and not
have a mediator itself (the PaletteMediator/WorkspaceMediator)
would take care of it)...</p>
<p>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...</p>
<p>Whew, that was <em>way</em> 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...</p>
<p>Anyway, any suggestions, help, links, jeers, etc are
appreciated!</p>
<p>Thanks a lot,<br>
jos<br></p></div>Jos Yuletag:robotlegs.tenderapp.com,2009-10-18:Comment/6848712009-12-09T16:56:54Z2009-12-09T16:56:54ZDrag and drop question - re-using a view. <div><p>I've done some more simplification of this - here is the new
sequence diagram.</p>
<p><a href="http://tiny.cc/MNYwF">http://tiny.cc/MNYwF</a></p>
<p>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..</p></div>Jos Yuletag:robotlegs.tenderapp.com,2009-10-18:Comment/6848712009-12-11T14:42:12Z2009-12-11T14:42:12ZDrag and drop question - re-using a view. <div><p>Hi Jos,</p>
<p>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.</p>
<p>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!</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/6848712009-12-11T14:46:18Z2009-12-11T14:46:18ZDrag and drop question - re-using a view. <div><p>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.</p>
<p>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.</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/6848712009-12-11T15:17:22Z2009-12-11T15:17:22ZDrag and drop question - re-using a view. <div><p>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?</p>
<p>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...</p>
<p>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.</p>
<p>Thanks for spending some of your valuable time with this - i
really appreciate it.</p>
<p>jos</p></div>Jos Yuletag:robotlegs.tenderapp.com,2009-10-18:Comment/6848712009-12-11T15:36:20Z2009-12-11T15:36:20ZDrag and drop question - re-using a view. <div><p>Hey, no problem =)</p>
<p>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.</p>
<p>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.</p>
<p>Cheers,<br>
shaun</p></div>Shaun Smith