cathalmchale
asked on
Enabling / disabling of menu items
This is a rather poxy and general question, but perhaps someone can give me a few ideas.
Menu items (and toolbar buttons) may change a little to have extra options / enable or disable certain items etc. depending on what perspective / window is "on" at that moment in time.
Without getting to bogged down with the precise nature and structure of my project:
* where should the menus be created? (and if a general menu is shared by 2 windows is there a good way of getting the action command so things dont get hard-coded in several classes)
* and what about the methods which decide what menu items are enabled / disabled depending on certain local criteria? (is an interface a good idea here?
* and for toolbar buttons.
I guess my question is how do YOU solve these issues. Any good ideas and direction much appreciated!
Regards,
Cathal.
Menu items (and toolbar buttons) may change a little to have extra options / enable or disable certain items etc. depending on what perspective / window is "on" at that moment in time.
Without getting to bogged down with the precise nature and structure of my project:
* where should the menus be created? (and if a general menu is shared by 2 windows is there a good way of getting the action command so things dont get hard-coded in several classes)
* and what about the methods which decide what menu items are enabled / disabled depending on certain local criteria? (is an interface a good idea here?
* and for toolbar buttons.
I guess my question is how do YOU solve these issues. Any good ideas and direction much appreciated!
Regards,
Cathal.
The same actions can also be used for buttons, and toolbars
ASKER
so a package called .Actions could be a good idea - with lots of different action sub-classes?
But I still don't fully understand. In the Sun example there are 2 ways of performing a general action. What would it look like if I wanted to implement a save or save as action -> we have to decide if there is something saveable in the workspace, if so then perform this guys save routine (so does this action class not need to know a little more - eg a way of getting a reference to the active "workspace document") - and then in this case who is telling the action whether to have save enabled / disabled depending on whether there is a saveable entity in the workspace at the current time.
Hope this doesnt read to gibberish-ly!! but another similar response would send me on my way nicely, thanks!
But I still don't fully understand. In the Sun example there are 2 ways of performing a general action. What would it look like if I wanted to implement a save or save as action -> we have to decide if there is something saveable in the workspace, if so then perform this guys save routine (so does this action class not need to know a little more - eg a way of getting a reference to the active "workspace document") - and then in this case who is telling the action whether to have save enabled / disabled depending on whether there is a saveable entity in the workspace at the current time.
Hope this doesnt read to gibberish-ly!! but another similar response would send me on my way nicely, thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
and when the active document in the workspace changes is this when to call the appropriate setEnabled(..) methods in the actions??
yes it could be handled that way, another way would be to use listeners so the action is informed when the active doc changews allowing it to enable/disable itself as appropriate.
ASKER
Hi again!
for the action we have:
putValue(SHORT_DESCRIPTION , desc);
putValue(MNEMONIC_KEY, mnemonic);
can i do the same for an accelerator key? and an mnemonic displayed index?
for the action we have:
putValue(SHORT_DESCRIPTION
putValue(MNEMONIC_KEY, mnemonic);
can i do the same for an accelerator key? and an mnemonic displayed index?
ASKER
OK I see how this can be done, although there is no fileld in AbstractAction for a "mnemonic displayed index"?? so will I just have to set this on my menu item / button myself?
Yes I think you'll need to set the index yourself.
ASKER
This all seems to be working quite nicely now, but what about the following:
I have a popup menu with options such as New, open, delete etc. These pop-ups appear when the user right clicks in a certain window. This window has a tree and a table, and the action is slightly different depending on the origin of the right click (eg, a delete on the tree deletes the entire selected directory, where as a delete on the table just deletes the selected file!!)
can i still solve this problem using the action idea -> is the solution simply - if the actions are different then make 2 actions (TableDeleteAction, TreeDeleteAction)
Thanks.
I have a popup menu with options such as New, open, delete etc. These pop-ups appear when the user right clicks in a certain window. This window has a tree and a table, and the action is slightly different depending on the origin of the right click (eg, a delete on the tree deletes the entire selected directory, where as a delete on the table just deletes the selected file!!)
can i still solve this problem using the action idea -> is the solution simply - if the actions are different then make 2 actions (TableDeleteAction, TreeDeleteAction)
Thanks.
>> is the solution simply - if the actions are different then make 2 actions (TableDeleteAction, TreeDeleteAction)
I tend to answer: yes, indeed.
You could do it with one but I think that would make your action code more (/too?) complex.
I tend to answer: yes, indeed.
You could do it with one but I think that would make your action code more (/too?) complex.
The two actions could inherit from the say a DeleteAction which contained the non-component specific functionality.
Or you use a single action that works regardless of the componwent.
Or you use a single action that works regardless of the componwent.
You can then share these actions between different windows.
And to enable/disable the menu item, you enable/disable the action.