where to put "selected" property

where to put "selected" property

Old forum URL: forums.lhotka.net/forums/t/4485.aspx


mtagliaf posted on Monday, March 10, 2008

I'm having trouble separating "model" from "view" in my current project.  First, some background, my app duplicates a "wall of magnets" in real life.  People move the magnets around in various orders, and my application mirrors that functionality by allowing drag/drop operations on the "magnet" elements.  Only one user (the 'admin' user) is allowed to move the magnets in the application - all other users of the app see the board in a readonly view, and it refreshes every x seconds via a timer. The CSLA classes that represent the magnets are readonly.

The admin user might selected 5 magnets (either by ctrl-clicking on them or rubber-band selecting them) and then move them around.  Once he moves them (say 10 units in both x and y direction), I update the database to say these 5 magnets have been moved by an offset of (10,10) using a CSLA CommandBase and then I reload the readonly CSLA object from the DB. I also update a time stamp so that the readonly users know to reload the object as well.

Here's the dilemma - I need a place to store which 5 magnets are selected and which are not, and that information has to survive the CSLA reload from the database.  In my first crack, I just put a selected property on the CSLA magnet class, but this of course did not survive the refresh from the DB.

In my next attempt, I created a SortedDictionary class that stored the magnet objects, and I add and remove the objects as they are selected.  This survives the CSLA refresh really well, but the problem is that too much information survives - specifically the OLD x and y coordinates of the 5 magnets, before they were moved. For example, say one of the readonly users has the magnet in the upper left corner (0,0) selected, but then the admin moves it to (10,10).  I refresh the CSLA object, but the magnet in the "selected" collection still says (0,0).

I think maybe I need to keep some kind of "pointer list" of the selected magnets, but when its time to go get any specific information from the selected list (like the current coordinates), it would go back to the current CSLA class to get this info.  This also has to be pretty fast since the lookups need to happen as the user drags multiple magnets across the board.

Does anyone have any more specific ideas?


JonnyBee replied on Wednesday, March 12, 2008

I assume each "magnet" has a unique id and since you will get new objects from the database when you do a refresh of data I would recommend you keep a separate list (such as HashTable) of "selected IDs". That should assist you in retrieving the actual "magnets" from any instance of the list.

/jonny

mtagliaf replied on Wednesday, March 12, 2008

thanks, this is the solution I ended up implementing.  I wrote a wrapper around a Hashtable so I could "toggle" items in the list (if it's in there, take it out, if it's not in there, add it), which lends itself well to CTRL-clicking on the magnets.




Copyright (c) Marimer LLC