问题
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:
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
...
来源:https://stackoverflow.com/questions/1463114/eclipse-open-type-dialog-restricted-to-a-particular-interface