How to find out, for which item to build a context menu in a tree viewer? [message #206355] |
Thu, 09 June 2005 07:26  |
Eclipse User |
|
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03195 seconds