Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Enabling / disabling of menu items

Posted on 2004-10-31
14
Medium Priority
?
228 Views
Last Modified: 2010-05-18
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.
0
Comment
Question by:cathalmchale
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
14 Comments
 
LVL 92

Expert Comment

by:objects
ID: 12461080
Define the actions performed by your menu items as Action subclasses.
You can then share these actions between different windows.
And to enable/disable the menu item, you enable/disable the action.
0
 
LVL 92

Expert Comment

by:objects
ID: 12461081
The same actions can also be used for buttons, and toolbars
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:cathalmchale
ID: 12461256
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!
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 12461262
yes the action class will need access to all the objects required to perform the action.
0
 

Author Comment

by:cathalmchale
ID: 12461272
and when the active document in the workspace changes is this when to call the appropriate setEnabled(..) methods in the actions??
0
 
LVL 92

Expert Comment

by:objects
ID: 12461293
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.
0
 

Author Comment

by:cathalmchale
ID: 12461867
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?
0
 

Author Comment

by:cathalmchale
ID: 12462144
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?
0
 
LVL 92

Expert Comment

by:objects
ID: 12467877
Yes I think you'll need to set the index yourself.
0
 

Author Comment

by:cathalmchale
ID: 12470542
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.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12470806
>> 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.
0
 
LVL 92

Expert Comment

by:objects
ID: 12470945
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.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question