DZone Forums
Go Back   DZone Forums > Community > Tools & IDEs > Eclipse
Reload this Page code to get the location of file in package explorer
Notices
Reply
 
LinkBack Thread Tools Display Modes
  (#1 (permalink)) Old
Member
 
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Feb 2008
Default code to get the location of file in package explorer - 03-04-2008, 06:50 AM

Hi all,
I want to get the location of FILE selected in package explorer through code, i m not able to get it..

i hv tried to access its location thru:-

ResourcesPlugin.getWorkspace().getRoot().members() ;
.
.

which will give the list of proj. added in workspace and then iterating thru all those projects for that particular file... but here the problem is like if the same file exists in more than 1 proj. my code will fail,

i want the location of that very specific file without iterating thru all the proj., its like if we select that file in package explorer and right click on that file clicking on 'properties' option and in that we can get the path in 'resource' section..thats the way i want it but through code.

plz help..thanks for ur reply in advance.
Reply With Quote
  (#2 (permalink)) Old
Member
 
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Mar 2008
Default 03-18-2008, 03:04 AM

Hi,

When i want to right click on a file in package explorer and get its location, i will implement a popupmenu (who's action class will implement the IObjectActionDelegate).
In the selectionChanged(IAction, ISelection) method of this interface, i will get the selection object which is selected in the PkgExplorer.

From this selection obj i can use below code, try this:

TreeSelection treeSel = (TreeSelection) selection;
((IFile)treeSel.getFirstElement()).getLocation();

Did it help u?
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add item to right click in package explorer legolaus Eclipse 2 10-07-2009 08:49 AM
How can my view in Eclipse listen to the selection made in the package explorer. poonam12jul Eclipse 0 11-15-2008 02:27 PM
Get the Location of Active View jayjamba Eclipse 0 08-25-2008 03:09 AM
[Eclipse PDE] Accessing Package Explorer mazeli Eclipse 1 08-10-2008 03:21 PM
code to monitor new files in folder with file name in the arraylist: sahuabinash Java 0 04-04-2008 08:26 AM


Copyright 1997-2009, DZone, Inc.
vBulletin Skin developed by: vBStyles.com