Search code examples
eclipseeclipse-jdt

Filter classes which implements certain interface using FilteredTypesSelectionDialog


I want to filter all the classes from the workspace which implements certain interface using eclipse jdt FilteredTypesSelectionDialog. Is there any way to achieve this?

IJavaElement[] elements = new IJavaElement[] { javaproject };
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(elements);
FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(root.getShell(), false, null, scope, IJavaSearchConstants.CLASS);
//filter classes which implements an interface

Solution

  • For subtypes of a given type use

    org.eclipse.jdt.core.search.SearchEngine.createStrictHierarchyScope(IJavaProject, IType, boolean, boolean, WorkingCopyOwner)
    

    To use this in a type selection dialog refer to

    org.eclipse.jdt.ui.JavaUI.createTypeDialog(Shell, IRunnableContext, IJavaSearchScope, int, boolean, String, TypeSelectionExtension)