Debajit
Debajit

Reputation: 47101

Eclipse "Open Type" dialog restricted to a particular interface

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?

Upvotes: 1

Views: 654

Answers (1)

Rich Seller
Rich Seller

Reputation: 84028

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
...

Upvotes: 2

Related Questions