Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » How to find out, for which item to build a context menu in a tree viewer?
How to find out, for which item to build a context menu in a tree viewer? [message #206355] Thu, 09 June 2005 07:26 Go to next message
Eclipse UserFriend
If one defined a context menu for items displayed in a TreeViewer - how
can one figure out, for which item the context menu should be built?

Or, paraphrasing from the example plugin generated using eclipse's
Plugin-Wizard:

views.SampleView:
....
public void createPartControl(Composite parent) {
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL |
SWT.V_SCROLL);
...
hookContextMenu();
...
}

void hookContextMenu() {
MenuManager menuMgr = new MenuManager("#PopupMenu");
...
menuMgr.addMenuListener(new IMenuListener()
{
public void menuAboutToShow(IMenuManager manager) {
fillContextMenu(manager);
}
});
Menu menu = menuMgr.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(menu);
getSite().registerContextMenu(menuMgr, viewer);
}

void fillContextMenu(IMenuManager manager) {
manager.add(action1);
manager.add(action2);
...
/* If the actions to be added here are supposed to depend on
the object(-type) being clicked on, how can one figure out
here, for which item this context menu(builder) is called???
The passed IMenuManager does not seem to offer any method
that allows to figure out, which item the user clicked on..
Neither does the View in which this whole stuff is defined...
*/
...
}
....

Michael
Re: How to find out, for which item to build a context menu in a tree viewer? [message #206363 is a reply to message #206355] Thu, 09 June 2005 07:50 Go to previous message
Eclipse UserFriend
Never mind - I found the answer: viewer.getSelection()

I had been thinking about the fact, that (right-)clicking on some item
in order to bring up its context menu of course also automatically
selects it and thus one can easily find out...

Sorry for the bandwidth,
Michael
Previous Topic:How to trigger UI refreshes from a "job"
Next Topic:Breakpoints not installed
Goto Forum:
  


Current Time: Thu Jul 17 20:26:23 EDT 2025

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

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

Back to the top