Action problem




What's the best solution for this?

I have a bunch of components each in a tab of a JTabbedPane, it is desirable
for each pane to have its own 'Submit' button - yes an alternative is to
have the button outside the tabbed pane and let it do the right thing
depending on which tab is showing, visually I find it better to duplicate
the buttons for each tab.
I also want a menu item to be able to do the submit, in the same way I just
dismissed, depending on which tab is showing.
The buttons on each tab are in different states enabled/disabled, I think
this should be a property of the Action rather than the button - so I should
have many Actions...

My solution at present, is to have the Action as an attribute of the tabbed
component class, this keeps the action logic simple as it knows exactly what
it has to deal with (directly related, as it is, to the tabbed component).

The tricky bit is the Action for the menuItem - to achieve this I have a
changeListener on the JTabbedPane, this gets the Action from the just shown
tabbed component and installs it on the MenuItem.

It works fine, but is it the best way? It feels a bit convoluted.

Actions usually solve the many controls for 1 Action problem, here I want to
choose from many Actions for 1 control.

TIA
--
Mike W


.


Quantcast