I have integrated a propertytester for my eclipse plugin.
Everytime i am selecting an item from the context menu the property tester will be activated and checks, what datatype the selected element is, e.g. IProject or IFolder.
The recognition worked perfectly, until i did install the CDT plugin to eclipse.
Now the folders seem to be represented as type org.eclipse.cdt.internal.core.model.CContainer, which seems to be a CDT representation of the folder.
Is there a way to avoid this conversion mechanism or to convert the CDT foldertype org.eclipse.cdt.internal.core.model.CContainer programmatically to the known IFolder?
User interface objects normally are 'adaptable' to resource objects.
So try
IFolder folder = (IFolder)Platform.getAdapterManager().getAdapter(object, IFolder.class);
where object
is the selected object.
It is possible that an adapter directly to IFolder
is not provided so also try adapting to IResource
.
In newer versions of Eclipse the adapter manager is generic so you don't need the cast.
In Eclipse 4.6 (Neon) you can use:
IFolder folder = Adapters.adapt(object, IFolder.class);
which will also check if the class implements IAdaptable
or is an instance of IFolder
. Only use this if you only want your code to run in Eclipse 4.6 (and later).