Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 12:14 Go to next message
Mat Mathiew is currently offline Mat MathiewFriend
Messages: 29
Registered: July 2012
Junior Member
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 12:45]

Report message to a moderator

Re: Get selected project name when action is executed [message #900797 is a reply to message #900757] Wed, 08 August 2012 13:56 Go to previous messageGo to next message
John Steele is currently offline John SteeleFriend
Messages: 50
Registered: January 2010
Member
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 14:43 Go to previous message
Mat Mathiew is currently offline Mat MathiewFriend
Messages: 29
Registered: July 2012
Junior Member
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: Fri Oct 04 09:45:25 GMT 2024

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

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

Back to the top