99miles
|
|
« on: March 18, 2008, 02:23:15 » |
|
Project Overview: I have a project with a TileList containing images.
I also have a List of tag names and each tag name has a checkbox next to it.
When one or more images are selected, then a tag checkbox is clicked, I need to apply the tag to the selected image(s) if the checkbox is checked (or remove the tag from the image if the checkbox is now unchecked.)
On to the implementation: There are a couple things I need to do this. I need to grab the selectedIndices of the TileList (so I know which ArrayCollection items to add the tag to), and I need the tag name. I then push the selected tag name into the ArrayCollection of the selectedIndices for the collection of images. I also have a ‘state’ property on each tagVO which I set to ‘STATE_CHECKED’ for any tag that is checked. Obviously to remove a tag this would all be reversed.
I started out with an ApplyTagCommand, a RemoveTagCommand, etc to handle these actions. But I also do a similar thing for ‘Sets’, and ‘Groups’ which behave very similar to the Tags list. So I combined the ApplyTagCommand and RemoveTagCommand into one TagCommand to keep down the number of commands and to consolidate related code. It seemed like the right thing to do.
The question: My question is this: What would your approach be for accessing the particular behavior you want from a command that can perform several actions? I currently have static vars in the TagCommand, ADD_TAG and REMOVE_TAG, and I’m passing either one of those in the body of the notification – the command then calls the appropriate method depending on the which static is in the notification body. Like this: sendNotification( ApplicationFacade.TAG_HANDLER, TagCommand.ADD_TAG );
Does that seem okay? Would it be preferable to set the value of a public variable ‘mode’ on the Command first, then leave the notification body empty? Is there an altogether different preferred approach?
Thanks in advance, and awesome job Cliff! -Mac
|