Multiple CommandHandlers

Topics: CAB & Smart Client Software Factory
Jan 24, 2007 at 12:16 PM
Here is the scenario, I have a general tool bar with a "New" button. I have added the invoker to handle the "Click" event. I am also developing a TabMdi user interface similar to Visual Studio, so each tab shows the smart parts. Each smart part is configured to handle the "New" command (i.e. they each have the CommandHandler attribute on a given method.) The issue is I want the smartpart that is visible or active to handle the command and the other one(s) to ignore the command. The solution I came up with, was to have each smart manage some sort of state indicator (IsActive) and use that variable in the command handler (i.e. If IsActive Then ...) Is there a better way or different way to attack the problem?

Thanks
Phil James
www.skylinetechnologies.com
Jan 24, 2007 at 8:13 PM
Not that I can think of.

This is a pretty common issue, and it's not easily solvable any other way. The bottom line is, if you are going to have multiple "subscribers" to one "publisher", but you only want a single, specific "subscriber" to actually do anything, then in some way you have to determine who the "single, specific" subscriber is going to be. Having the subscribers manage themselves and determine who is "active" is about the only way I think think of to handle this.

It's a unique constraint to put on a publish/subscriber pattern, but it happens all the time. Maybe someday someone will find a better way :)