views:

450

answers:

1

Hello! :-)

In my current RCP-project i use a MultipageEditorPart. It has various pages, with simple SWT composites on it. The composites contain some Text and Combo elements. When the user right clicks onto the editor page, I want a context menu to open. This menu holds a command for creating a new editor page, with a composite on it.

The command is already working, but I'm quite clueless about how to implement the context menu for the editor. Can someone help with this?

A: 

This should be based on Action contributions: see Contributing Actions to the Eclipse Workbench

As an RCP-based example, You could check out "Designing a Workflow Editor Eclipse XML", where a contextual menu is added to an EditorPart, included in a MultipageEditorPart.

protected void createContextMenuFor(StructuredViewer viewer) { 
   MenuManager contextMenu = new MenuManager("#PopUp"); 
   contextMenu.add(new Separator("additions")); 
   contextMenu.setRemoveAllWhenShown(true); 
   contextMenu.addMenuListener(this); 
   Menu menu= contextMenu.createContextMenu(viewer.getControl()); 
   viewer.getControl().setMenu(menu); 
   getSite().registerContextMenu(contextMenu, new UnwrappingSelectionProvider(viewer)); 

   } 

alt text

See also Step 18 for extending that context menu (section "Delete - Contextual Menu, requiring using GEF).

VonC
Thanks for your effort, but I'm trying not to use any actions. As far as i understand this, the extension point "org.eclipse.ui.popupMenus" was replaced in eclipse 3.3 by "org.eclipse.ui.menues". And in your example you are using a structured viewer, while i'm not using any. Do i have to use viewers or is there some other way to get the commands on the context menu? But anyway thanks for helping me. :-)
Patrick
@Patrick: this is right, the example is a bit old. I will look a bit more into this.
VonC