nautilusvn
nautilusvn

Reputation: 665

How to get resource object in RCP App

I use CNF to make a view like Project Explorer in my RCP app. I'm done showing new menu and its submenu when user right clicks on a project in the view. enter image description here

But when user click on a submenu (for this case, a method library going to be created), I need to know which project object that user has right-clicked on.

My question is how can I do that? Please help me.

Thank you all, Nautilus

Upvotes: 1

Views: 539

Answers (2)

nautilusvn
nautilusvn

Reputation: 665

Thank VonC,

Now I got the resource object that user has right-clicked on by doing this:

IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IWorkbenchPage page = window.getActivePage();
    CommonNavigator view = (CommonNavigator)page.findView("spe.ui.navigator.view");
    selection = (IStructuredSelection) view.getSite().getSelectionProvider().getSelection();

But I'm really not happy completely with the solution. Note that I open a INewWizard after the action. In the INewWizard we have public void init(IWorkbench workbench, IStructuredSelection selection). I really want to use this method but I don't how to make it work.

Please, someone help me. Thanks

Upvotes: 0

VonC
VonC

Reputation: 1324278

I think the wiki page E4/EAS/Selection should provide a way to query the right selection.

In Eclipse 3.x, the org.eclipse.ui.ISelectionService allows workbench parts to query the active selection in addition to attaching listeners for monitoring selection changes.

(see this example)

In the e4 world, selection is propagated with the ESelectionService.

Upvotes: 0

Related Questions