Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Get selected project name when action is executed
Get selected project name when action is executed [message #900757] Wed, 08 August 2012 08:14 Go to next message
Eclipse UserFriend
I created a custom wizard which creates a new folder with some files insides
when it successfully finishes.

But I want this folder to be created inside a project which the user doesn't explicitly specify but is implicitly specified depending where the user right click and fired the wizard.

I made a menu contribution for the popup menu of the navigator
that shows my action and I need to obtain information about what project is selected
when the user right click and selected the action to start the wizard in order to
create the folder in that project.

After that i will use the project name to create the folder as follows.
 
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IWorkspaceRoot root = workspace.getRoot();
        IProject project  = root.getProject("myProject"); //WHICH ONE...?


Any idea how to get this information?

Edit: I tried creating a class that extends SelectionListenerAction but getSelectedResources is empty whatever is selected when the users fires the wizard.

[Updated on: Wed, 08 August 2012 08:45] by Moderator

Re: Get selected project name when action is executed [message #900797 is a reply to message #900757] Wed, 08 August 2012 09:56 Go to previous messageGo to next message
Eclipse UserFriend
Hi Mat,

Take a look at this article:

techjava.de/topics/2009/08/eclipse-common-navigator-framework-2/

It sounds like you just need to get the package explorer's currently selected project, which you can get multiple ways, including the selection service:
IStructuredSelection selection = (IStructuredSelection) service
                        .getSelection("org.eclipse.jdt.ui.PackageExplorer");

((IFile)selection.getFirstElement()).getLocation()
...


Additionally, take a look at this example:

csourcesearch.net/java/fidBC292163B64B401EE9693615B9C861B5230107C2.aspx?s=org.eclipse.jdt.ui.PackageExplorer%2BgetSelected#L45

Hope it helps!
Re: Get selected project name when action is executed [message #900810 is a reply to message #900797] Wed, 08 August 2012 10:43 Go to previous message
Eclipse UserFriend
Thank you very much that solve my problem!
Previous Topic:Perspective initial layout for views with allow multiple = true (compound ids)
Next Topic:How to dynamically set the View Part Name and Content
Goto Forum:
  


Current Time: Thu Jul 17 16:08:56 EDT 2025

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

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

Back to the top