Get TreeSelection path [message #900102] |
Sat, 04 August 2012 01:50 |
rohit chawla Messages: 19 Registered: June 2012 |
Junior Member |
|
|
Hi, What is a good way to get the location of current selection in packageExplorer? The selection instance returned is always TreeSelection. But how to get path from the TreeSelection. I am using the following ugly way, which sometimes work & sometimes does not?
I researched a lot on net, but didn't find any good solution.
IPath path = null;
try{
Object element = ((TreeSelection) selection). getFirstElement();
if (element instanceof JavaProject) {
path = ((JavaProject) element).getPath();
} else if (element instanceof PackageFragmentRoot) {
path = ((PackageFragmentRoot) element).getPath();
} else if (element instanceof PackageFragment) {
path = ((PackageFragment) element).getPath();
}
return path.toString();
}
|
|
|
Powered by
FUDForum. Page generated in 0.02699 seconds