Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Problem of Context Menu
Problem of Context Menu [message #453010] Thu, 20 July 2006 07:42 Go to next message
Hailong Zhang is currently offline Hailong ZhangFriend
Messages: 19
Registered: July 2009
Junior Member
How to hide some menu items of the Context Menu?
For example: My application's context menu always has "Run as...", "Debug
as..." menu items. They are contributed by other plugins which my plugin
depends. However, I don't want these menu items to be displayed.

Any solutions?

Thanks in advance.

Regards
zhlmmc
Re: Problem of Context Menu [message #453024 is a reply to message #453010] Thu, 20 July 2006 08:12 Go to previous messageGo to next message
Ilya Shinkarenko is currently offline Ilya ShinkarenkoFriend
Messages: 56
Registered: July 2009
Member
hi,

here is a small example

MenuManager menuMgr = new MenuManager();
menuMgr.setOverrides(new ContributionManagerOverridesAdapter()
{
public Boolean getEnabled(IContributionItem aItem)
{
final String ACTION_ID = "..you have to know the id.."";
if (FOLLOW_UP_ACTION.equals(aItem.getId()))
{
return Boolean.FALSE;
}
else
return null;
}
});


Ilya Shinkarenko
--
www.imedic.de
www.rcp-training.com



zhlmmc wrote:
> How to hide some menu items of the Context Menu?
> For example: My application's context menu always has "Run as...",
> "Debug as..." menu items. They are contributed by other plugins which my
> plugin depends. However, I don't want these menu items to be displayed.
>
> Any solutions?
>
> Thanks in advance.
>
> Regards
> zhlmmc
>
Re: Problem of Context Menu [message #453026 is a reply to message #453024] Thu, 20 July 2006 08:14 Go to previous messageGo to next message
Ilya Shinkarenko is currently offline Ilya ShinkarenkoFriend
Messages: 56
Registered: July 2009
Member
uppps... now it's correct

MenuManager menuMgr = new MenuManager();
menuMgr.setOverrides(new ContributionManagerOverridesAdapter()
{
public Boolean getEnabled(IContributionItem aItem)
{
final String ACTION_ID = "..you have to know the id.."";
if (ACTION_ID.equals(aItem.getId()))
return Boolean.FALSE;
else
return null;
}
});



Ilya Shinkarenko wrote:
> hi,
>
> here is a small example
>
> MenuManager menuMgr = new MenuManager();
> menuMgr.setOverrides(new ContributionManagerOverridesAdapter()
> {
> public Boolean getEnabled(IContributionItem aItem)
> {
> final String ACTION_ID = "..you have to know the id.."";
> if (FOLLOW_UP_ACTION.equals(aItem.getId()))
> {
> return Boolean.FALSE;
> }
> else
> return null;
> }
> });
>
>
> Ilya Shinkarenko


Ilya Shinkarenko
--
www.imedic.de
www.rcp-training.com
Re: Problem of Context Menu [message #453065 is a reply to message #453026] Fri, 21 July 2006 03:03 Go to previous messageGo to next message
Hailong Zhang is currently offline Hailong ZhangFriend
Messages: 19
Registered: July 2009
Junior Member
Hi Shinkarenko,
I have tried your code, it just disables the menus but not hide the
menus. How to hide the menus? Thank you!

Regards
zhlmmc
Re: Problem of Context Menu [message #453069 is a reply to message #453065] Fri, 21 July 2006 08:01 Go to previous messageGo to next message
Ilya Shinkarenko is currently offline Ilya ShinkarenkoFriend
Messages: 56
Registered: July 2009
Member
try another approach:

private void createContextMenu()
{
MenuManager menuMgr = new MenuManager();
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener()
{
public void menuAboutToShow(IMenuManager mgr)
{
//we fill the menu every time from scratch
//when user tries to open it
fillContextMenu(mgr);
}
});
Menu menu = menuMgr.createContextMenu(m_TreeViewer.getControl());
m_TreeViewer.getControl().setMenu(menu);
getSite().registerContextMenu(menuMgr, m_TreeViewer);
}

private void fillContextMenu(IMenuManager mgr)
{
//here you decide what to show in your menu
//
//...
//

mgr.add(new GroupMarker(
IWorkbenchActionConstants.MB_ADDITIONS));
}



zhlmmc wrote:
> Hi Shinkarenko,
> I have tried your code, it just disables the menus but not hide the
> menus. How to hide the menus? Thank you!
>
> Regards
> zhlmmc
>


Ilya Shinkarenko
--
www.imedic.de
www.rcp-training.com
Re: Problem of Context Menu [message #453074 is a reply to message #453069] Fri, 21 July 2006 09:56 Go to previous message
Hailong Zhang is currently offline Hailong ZhangFriend
Messages: 19
Registered: July 2009
Junior Member
Thanks for your response.
I have solved this problme in another way.
Menu menu = menuMgr.createContextMenu(m_TreeViewer.getControl());
menu.addMenuListener(new MenuListener(){
//....
public void menuShown(MenuEvent event){
//destroy any menu to be hidden
}
});

"Debug As...", "Run As..." are contributed by org.eclipse.debug.ui. It
will always add these items to context menu at runtime if you
"getSite().registerContextMenu()". So, I have to delete these items in
Menu component. My solution is ugly, but I can not find other ways to do
this. If someone has better solution, please tell me.

Regards
zhlmmc
Previous Topic:Define a global enablement actionset's element
Next Topic:checkbox
Goto Forum:
  


Current Time: Fri Oct 04 21:34:26 GMT 2024

Powered by FUDForum. Page generated in 3.32932 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top