我正在尝试创建一个JavaUI.createTypeDialog(),它限制用户只选择属于特定接口的类型。我怎么能这样做?
答案 0 :(得分:2)
This answer显示了如何获取特定类型的类型层次结构。您可以使用类似的处理来获取接口的TypeHierarchy,然后使用结果类型填充列表。
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
...