Removing certain menu options from framework menu

Oxygen general issues.
cnevins
Posts: 5
Joined: Tue Mar 29, 2011 8:16 pm

Removing certain menu options from framework menu

Post by cnevins »

Hi,

It looks like the Refresh, Tags Display Mode, and Profiling/Conditional Text menu options are added to the end of every Associated Document Type Framework menu - both my custom document types and the ones that come with Oxygen. How can I suppress or hide these menu options? I'm not seeing anything in the Document Type author menu customization options. Can I use a plugin that extends the ComponentsValidatorPlugin to remove these on startup? Is there a better method?

Thanks!

-Cole
Radu
Posts: 9055
Joined: Fri Jul 09, 2004 5:18 pm

Re: Removing certain menu options from framework menu

Post by Radu »

Hi Cole,

You have basically two ways to approach this:

1) Using a components validator plugin implementation you can remove the actions (but the main menu entries in the framework menu will remain). So you can remove the Refresh references and Refresh actions but the menu Refresh will remain with no child menu items to display.

Example:

Code: Select all

public boolean validateAccelAction(String category, String tag) {
if("Author".equals(category) && "Refresh_references".equals(tag)) {
return false;
}
if("Author".equals(category) && "Reload".equals(tag)) {
return false;
}
System.err.println("cate " + category + " tag:" + tag) ;
return true;
}
2) You can use a WorkspaceAccess plugin implementation which has methods to add a MenuBarCustomizer like:

Code: Select all

 pluginWorkspaceAccess.addMenuBarCustomizer(new MenuBarCustomizer() {
/**
* @see ro.sync.exml.workspace.api.standalone.MenuBarCustomizer#customizeMainMenu(javax.swing.JMenuBar)
*/
public void customizeMainMenu(JMenuBar mainMenuBar) {
..................
The problem is that the framework specific menu is created automatically only when an editor gets selected.
So you must keep a reference to the main JMenuBar received from the customizer.

Then you can add a WSEditorChangeListener like:

Code: Select all

    pluginWorkspaceAccess.addEditorChangeListener(
new WSEditorChangeListener() {
@Override
public void editorSelected(URL editorLocation) {
//Here you can recurse the main JMenuBar and remove the items if they exist in the framework menu
};
......................
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
yann1806
Posts: 22
Joined: Fri Aug 09, 2013 11:03 am

Re: Removing certain menu options from framework menu

Post by yann1806 »

Hi guys,

following to this question - how can I implement hiding or showing menu options when the user takes an arbitrary action? In my case, when my user logs in to a remote repository (via my plugin), I want to show extra menus.

But of course the listeners has methods for editor opened, editor closed, etc, not for my own plugin actions. What's the best way to implement something like that?

Thanks

Yann
Radu
Posts: 9055
Joined: Fri Jul 09, 2004 5:18 pm

Re: Removing certain menu options from framework menu

Post by Radu »

Hi Yann,

If you add a MenuBarCustomizer as in my example above, you will be able to store in a field the main JMenuBar (or your own menu added to the main JMenuBar).
When your action gets called you could update the menu which you have contributed.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply