Skip to content
Advertisement

Eclispe API – How to get parent project location

How to get the parent module of project. Here is my code works fine in Eclipse PDE. But when I test the plugin(installing in eclipse) using test application by selecting the child module this condition (if (projectRoot == selectedResource)) is coming true and it return src and target as child modules which is incorrect. Any suggestion on how to get the parent module of project.

JavaScript

Resource.Class

JavaScript

Advertisement

Answer

An Eclipse workspace is organised like this:

JavaScript

IFolder in turn can contain a mixture of more IFolder and IFile resources.

IWorkspaceRoot, IProject, and IFolder all extend IContainer. IContainer and IFile extend IResource.

The IResource.getProject method always returns the top IProject resource (except for IWorkspaceRoot).

IResource.getParent returns the immediate IContainer parent (null for IWorkspaceRoot)

So if you want the parent container of a resource call IResource.getParent, if you want the top level containing project call IResource.getProject.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement