Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Context Menu on my TreeViewer
Context Menu on my TreeViewer [message #668049] Tue, 03 May 2011 10:15 Go to next message
Eclipse UserFriend
Hello dear Eclipse Community

Im working with a TreeViewer which holds several Files in it.
Now im wondering if i could get the Eclipse standart Context Menu on my TreeElement?

For a Example:

I got a .java File in my Tree and would like to see on a Right Click the Context Menu for Java Files provided by eclipse.

Is there any way to do this?

Thanks!
Re: Context Menu on my TreeViewer [message #671236 is a reply to message #668049] Tue, 17 May 2011 04:41 Go to previous messageGo to next message
Eclipse UserFriend
	// creating the Menu and registering it
		MenuManager menuMgr = new MenuManager("#PopupMenu");
		menuMgr.setRemoveAllWhenShown(false);
		Menu menu = menuMgr.createContextMenu(treeViewer.getControl());
		viewer.getControl().setMenu(menu);
		getSite().registerContextMenu(menuMgr, treeViewer);

		Action action1 = new Action() { 
			public void run() {
			// Code for handling action goes here. 
			}
		} ; 
		action1.setText("Action 1");



Try out this code.. Let me know if it works.

[Updated on: Tue, 17 May 2011 04:42] by Moderator

Re: Context Menu on my TreeViewer [message #671420 is a reply to message #671236] Tue, 17 May 2011 15:46 Go to previous message
Eclipse UserFriend
Using the Plug-in Spy (ALT+SHIFT+F1) on the PackageExplorer I could see that the class where the menu is shown is PackageExplorerPart --> menuAboutToShow() method. After that you can check if that implementation could be used by you easily or not.
That class is from JDT internal package so probably asking on the JDT forum will give you back more answers.
Previous Topic:How to open correct XML editor for different XML documents
Next Topic:Simple Question: Making a button open a tab
Goto Forum:
  


Current Time: Sun Aug 31 08:50:51 EDT 2025

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

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

Back to the top