views:

148

answers:

2

Hi,
I'm writing an eclipse plugin, and I want to get all the types that are available in my workspace,
like when pressing Ctrl+Shift+T,
but in a list or array.

How can I do it?

+1  A: 

The relevant code is referenced from the org.eclipse.jdt.internal.ui.dialogs.FilteredTypesSelectionDialog (which the OpenTypeSelectionDialog triggered by ctrl-shift-T inherits from).

If you inspect the fillContentProvider() method you'll see it the org.eclipse.jdt.core.search.SearchEngine, which is passed a TypeSearchRequestor and TypeItemsFilter to match the required types.

If you look at the Javadoc for SearchEngine.searchAllTypeNames() and/or debug its execution, you should have a pretty clear idea how to obtain the workspace types into a requestor, and process them accordingly.

Rich Seller
I was searching the same thing;) PluginSpy helps :) +1
VonC
A: 

I search the source code and create FilteredTypesSelectionDialog directly to open the OpenTypeSelectionDialog.

But I do not understand what is the mean of fillContentProvider() and SearchEngine.searchAllTypeNames()?

btnBrowser button listen:

btnBrowser.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
                            // give the project
            IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(
            "demo1");
            IJavaProject javaProject = JavaCore.create(project);
            System.out.println("javaProject:" + javaProject.getProject().getName());
            IJavaElement[] elements= new IJavaElement[] {javaProject };
            // generate the search scope
                            IJavaSearchScope scope= SearchEngine.createJavaSearchScope(elements);
                            // generate the dialog
            FilteredTypesSelectionDialog dialog= new FilteredTypesSelectionDialog(getShell(), false, 
                    getWizard().getContainer(), scope, IJavaSearchConstants.CLASS_AND_INTERFACE, null);
            dialog.setInitialPattern("java");

            if (dialog.open() == Window.OK) {
                text_1.setText( ((IType)dialog.getFirstResult()).getFullyQualifiedName());
            }else{
                System.out.println("Not ok");
            }

        }
    });
Li Jia Jia