Getting nullpointerexception while fetching current runtime project [message #655876] |
Tue, 22 February 2011 19:21  |
Eclipse User |
|
|
|
hi,
I've a plugin which is running on the workspace. in the runtime
environment, i created a project "test" and a file inside this
project. I need to get this project path and name to create some files inside it at runtime.
If i try ResourcesPlugin.getWorkspace().getRoot().getProjects()[0]
it returns me path to the test folder.
But here i dont know which index of the projects to take.
so now when i try to get the project with
ResourcesPlugin.getWorkspace().getRoot().getProject()
it returns me null.
if i select the project, then i'm able to get the project from the
selectionservice and iresource like below.
IResource extractSelection(ISelection sel) {
if (!(sel instanceof IStructuredSelection))
return null;
IStructuredSelection ss = (IStructuredSelection) sel;
Object element = ss.getFirstElement();
if (element instanceof IResource)
return (IResource) element;
if (!(element instanceof IAdaptable))
return null;
IAdaptable adaptable = (IAdaptable)element;
Object adapter = adaptable.getAdapter(IResource.class);
return (IResource) adapter;
}
System.out.println(resource.getProject());
But i will not have the selection available always.
Can anyone kindly tell me how to get the current project from the runtime environment !
Thanks,
|
|
|
|
Re: Getting nullpointerexception while fetching current runtime project [message #656068 is a reply to message #655891] |
Wed, 23 February 2011 20:40  |
Eclipse User |
|
|
|
Hi, Thanks for the response.
But there i don't have the name of the project.
as a work around, i tried the below approach to get the container of the active editor and then from there navigating to a relative path.
(EditorPart)getActiveWorkbench().getActivePage().getActiveEd itor().getEditorInput()).getFile().getParent()
i think this is not an optimum approach, please let me know if there are alternates.
Thanks,
|
|
|
Powered by
FUDForum. Page generated in 0.03458 seconds