views:

207

answers:

1

I'm trying to create a JavaUI.createTypeDialog() which restricts the user to selecting only types belonging to a particular interface. How could I do this?

+1  A: 

This answer shows how to obtain the type hierarchy for a particular type. You could use similar processing to obtain the TypeHierarchy for the interface, then populate the list with the resultant types.

IProject project; //currently selected project

//get the java project and locate the interface type
JavaProject javaProject = JavaCore.create(project);
IType myInterface = 
    javaProject.findType("MyInterface","name.seller.rich");

//get the sub types from the interface's type hierarchy
ITypeHierarchy hierarchy =
    myInterface .newTypeHierarchy(new NullProgressMonitor());

IType[] subTypes = hierarchy.getAllSubtypes(myInterface );

//do something with the sub types
...
Rich Seller