Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to create submenu in a context menu
How to create submenu in a context menu [message #467709] Thu, 10 May 2007 08:02 Go to next message
Eclipse UserFriend
Originally posted by: johan_susai.yahoo.com

To create an context menu in Tree element i used the following code.
TreeViewer viewer=new TreeViewer();
final MenuManager mgr = new MenuManager();
mgr.setRemoveAllWhenShown(true);
Action action1=new Action();
Action action2=new Action();
mgr.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
IStructuredSelection selection = (IStructuredSelection) viewer
getSelection();
if (!selection.isEmpty()) {
action1.setText("Add");
action2.setText("Append");
manager.add(action1);
manager.add(Action2);

}
}
});

Now i am getting the context menu when i right click on the tree elements.
But i want to create submenu, so tell me how to create submenu while clicking on Add/Append action in context menu.

Thanks,
Joe
Re: How to create submenu in a context menu [message #467754 is a reply to message #467709] Thu, 10 May 2007 09:46 Go to previous message
Eclipse UserFriend
joesusai wrote:
> mgr.addMenuListener(new IMenuListener() {
> public void menuAboutToShow(IMenuManager manager) {
> IStructuredSelection selection = (IStructuredSelection) viewer
> getSelection();
> if (!selection.isEmpty()) {
> action1.setText("Add");
> action2.setText("Append");
> manager.add(action1);
> manager.add(Action2);

MenuManager subMenu = new MenuManager("Sub");
subMenu.add(new Action() { ... whatever ... });


In your about to show, create a MenuManager for your submenu and then
add other actions to it.

Later,
PW
Previous Topic:Problem opening editor in startup perspective
Next Topic:JFace dependencies for standalone application?
Goto Forum:
  


Current Time: Wed May 21 07:00:13 EDT 2025

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

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

Back to the top