Example usage for org.eclipse.jdt.core.search SearchEngine createWorkspaceScope

List of usage examples for org.eclipse.jdt.core.search SearchEngine createWorkspaceScope

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.search SearchEngine createWorkspaceScope.

Prototype

public static IJavaSearchScope createWorkspaceScope() 

Source Link

Document

Returns a Java search scope with the workspace as the only limit.

Usage

From source file:at.spardat.xma.gui.mapper.BDInstanceSelectionDialog.java

License:Open Source License

private void browseButtonSelected() {
    ProgressMonitorDialog pmd = new ProgressMonitorDialog(getShell());
    SelectionDialog selDialog = null;/*from  w w  w  .  j  av a  2  s .  c o  m*/
    try {
        selDialog = JavaUI.createTypeDialog(getShell(), pmd, SearchEngine.createWorkspaceScope(),
                IJavaElementSearchConstants.CONSIDER_CLASSES, false);
        selDialog.setTitle("Select BusinessData");
    } catch (Exception ex) {
        setErrorMessage(ex.toString());
    }
    if (selDialog != null) {
        if (selDialog.open() == IDialogConstants.CANCEL_ID)
            return;
        Object[] types = selDialog.getResult();
        if (types == null || types.length == 0)
            return;
        IType selectedType = (IType) types[0];
        className_.setText(selectedType.getFullyQualifiedName());
    }
}

From source file:ca.mt.wb.devtools.tx.InheritanceView.java

License:unlicense.org

/**
 * Creates the menu and toolbar actions.
 *///from  ww  w.  j a  v  a 2s .  com
private void makeActions() {

    addNodeAction = new Action() {
        public void run() {
            try {
                SelectionDialog dialog = JavaUI.createTypeDialog(getSite().getShell(),
                        new ProgressMonitorDialog(getSite().getShell()), SearchEngine.createWorkspaceScope(),
                        IJavaElementSearchConstants.CONSIDER_ALL_TYPES, true);
                dialog.setTitle("Add type(s)...");
                dialog.setMessage("Type(s) to add?");
                if (dialog.open() == IDialogConstants.CANCEL_ID) {
                    return;
                }
                Object[] types = dialog.getResult();
                if (types == null || types.length == 0) {
                    return;
                }
                for (int i = 0; i < types.length; i++) {
                    addType((IType) types[i]);
                }
            } catch (JavaModelException e) {
                /* do nothing */
            }
        }
    };

    addNodeAction.setText("Add Type");
    addNodeAction.setToolTipText("Add a new class or interface");
    addNodeAction.setImageDescriptor(getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_ADD));

    expandElementAction = new Action() {
        public void run() {
            for (IType t : getSelectedTypes()) {
                addSubTypes(t);
            }
        }
    };
    expandElementAction.setText("Add Subtypes");
    expandElementAction.setToolTipText("Add subtypes of selected element");
    expandElementAction.setImageDescriptor(getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_ADD));

    // create the action that deletes the selected node
    deleteNodeAction = new Action() {
        public void run() {
            // ISelection = viewer.getSelection();
            ComparisonModel model = ((ComparisonModel) viewer.getInput()).copy();
            boolean modified = false;
            for (IType t : getSelectedTypes()) {
                if (model.remove(t)) {
                    modified = true;
                }
            }
            if (modified) {
                viewer.setInput(model);
            }
            setEnabled(false);
        }
    };
    deleteNodeAction.setEnabled(false);
    deleteNodeAction.setText("Delete Node");
    deleteNodeAction.setToolTipText("Delete the selected node");
    deleteNodeAction.setImageDescriptor(getSharedImages().getImageDescriptor(ISharedImages.IMG_ETOOL_DELETE));
    deleteNodeAction.setDisabledImageDescriptor(
            getSharedImages().getImageDescriptor(ISharedImages.IMG_ETOOL_DELETE_DISABLED));

    clearAction = new Action() {
        public void run() {
            viewer.setInput(new ComparisonModel());
            // viewer.refresh();
        }
    };
    clearAction.setText("Clear");
    clearAction.setToolTipText("Remove all elements");
    clearAction.setImageDescriptor(getSharedImages().getImageDescriptor(ISharedImages.IMG_ETOOL_CLEAR));
    clearAction.setDisabledImageDescriptor(
            getSharedImages().getImageDescriptor(ISharedImages.IMG_ETOOL_CLEAR_DISABLED));

    openInEditorAction = new Action() {
        public void run() {
            openInEditor(getSelectedTypes().get(0));
        }
    };

    layoutActions = new ArrayList<IAction>();
    layoutActions
            .add(createLayoutAction("Spring", new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING)));
    layoutActions
            .add(createLayoutAction("Radial", new RadialLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING)));
    layoutActions.add(createLayoutAction("Directed",
            new DirectedGraphLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING)));
    layoutActions
            .add(createLayoutAction("Tree", new TreeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING)));
    layoutActions.add(createLayoutAction("Horizontal Tree",
            new HorizontalTreeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING)));

}

From source file:com.android.ide.eclipse.adt.internal.editors.Hyperlinks.java

License:Open Source License

/**
 * Opens a Java method referenced by the given on click attribute method name
 *
 * @param project the project containing the click handler
 * @param method the method name of the on click handler
 * @return true if the method was opened, false otherwise
 *//*  ww  w .j  av  a  2s.c  o  m*/
public static boolean openOnClickMethod(IProject project, String method) {
    // Search for the method in the Java index, filtering by the required click handler
    // method signature (public and has a single View parameter), and narrowing the scope
    // first to Activity classes, then to the whole workspace.
    final AtomicBoolean success = new AtomicBoolean(false);
    SearchRequestor requestor = new SearchRequestor() {
        @Override
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
            Object element = match.getElement();
            if (element instanceof IMethod) {
                IMethod methodElement = (IMethod) element;
                String[] parameterTypes = methodElement.getParameterTypes();
                if (parameterTypes != null && parameterTypes.length == 1
                        && ("Qandroid.view.View;".equals(parameterTypes[0]) //$NON-NLS-1$
                                || "QView;".equals(parameterTypes[0]))) { //$NON-NLS-1$
                    // Check that it's public
                    if (Flags.isPublic(methodElement.getFlags())) {
                        JavaUI.openInEditor(methodElement);
                        success.getAndSet(true);
                    }
                }
            }
        }
    };
    try {
        IJavaSearchScope scope = null;
        IType activityType = null;
        IJavaProject javaProject = BaseProjectHelper.getJavaProject(project);
        if (javaProject != null) {
            activityType = javaProject.findType(CLASS_ACTIVITY);
            if (activityType != null) {
                scope = SearchEngine.createHierarchyScope(activityType);
            }
        }
        if (scope == null) {
            scope = SearchEngine.createWorkspaceScope();
        }

        SearchParticipant[] participants = new SearchParticipant[] {
                SearchEngine.getDefaultSearchParticipant() };
        int matchRule = SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE;
        SearchPattern pattern = SearchPattern.createPattern("*." + method, IJavaSearchConstants.METHOD,
                IJavaSearchConstants.DECLARATIONS, matchRule);
        SearchEngine engine = new SearchEngine();
        engine.search(pattern, participants, scope, requestor, new NullProgressMonitor());

        boolean ok = success.get();
        if (!ok && activityType != null) {
            // TODO: Create a project+dependencies scope and search only that scope

            // Try searching again with a complete workspace scope this time
            scope = SearchEngine.createWorkspaceScope();
            engine.search(pattern, participants, scope, requestor, new NullProgressMonitor());

            // TODO: There could be more than one match; add code to consider them all
            // and pick the most likely candidate and open only that one.

            ok = success.get();
        }
        return ok;
    } catch (CoreException e) {
        AdtPlugin.log(e, null);
    }
    return false;
}

From source file:com.android.ide.eclipse.adt.internal.editors.layout.gre.ClientRulesEngine.java

License:Open Source License

@Override
public String displayFragmentSourceInput() {
    try {//from w  ww.  j  a  v a  2s . c  om
        // Compute a search scope: We need to merge all the subclasses
        // android.app.Fragment and android.support.v4.app.Fragment
        IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
        IProject project = mRulesEngine.getProject();
        final IJavaProject javaProject = BaseProjectHelper.getJavaProject(project);
        if (javaProject != null) {
            IType oldFragmentType = javaProject.findType(CLASS_V4_FRAGMENT);

            // First check to make sure fragments are available, and if not,
            // warn the user.
            IAndroidTarget target = Sdk.getCurrent().getTarget(project);
            // No, this should be using the min SDK instead!
            if (target.getVersion().getApiLevel() < 11 && oldFragmentType == null) {
                // Compatibility library must be present
                MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(),
                        "Fragment Warning", null,
                        "Fragments require API level 11 or higher, or a compatibility "
                                + "library for older versions.\n\n"
                                + " Do you want to install the compatibility library?",
                        MessageDialog.QUESTION, new String[] { "Install", "Cancel" },
                        1 /* default button: Cancel */);
                int answer = dialog.open();
                if (answer == 0) {
                    if (!AddSupportJarAction.install(project)) {
                        return null;
                    }
                } else {
                    return null;
                }
            }

            // Look up sub-types of each (new fragment class and compatibility fragment
            // class, if any) and merge the two arrays - then create a scope from these
            // elements.
            IType[] fragmentTypes = new IType[0];
            IType[] oldFragmentTypes = new IType[0];
            if (oldFragmentType != null) {
                ITypeHierarchy hierarchy = oldFragmentType.newTypeHierarchy(new NullProgressMonitor());
                oldFragmentTypes = hierarchy.getAllSubtypes(oldFragmentType);
            }
            IType fragmentType = javaProject.findType(CLASS_FRAGMENT);
            if (fragmentType != null) {
                ITypeHierarchy hierarchy = fragmentType.newTypeHierarchy(new NullProgressMonitor());
                fragmentTypes = hierarchy.getAllSubtypes(fragmentType);
            }
            IType[] subTypes = new IType[fragmentTypes.length + oldFragmentTypes.length];
            System.arraycopy(fragmentTypes, 0, subTypes, 0, fragmentTypes.length);
            System.arraycopy(oldFragmentTypes, 0, subTypes, fragmentTypes.length, oldFragmentTypes.length);
            scope = SearchEngine.createJavaSearchScope(subTypes, IJavaSearchScope.SOURCES);
        }

        Shell parent = AdtPlugin.getShell();
        final AtomicReference<String> returnValue = new AtomicReference<String>();
        final AtomicReference<SelectionDialog> dialogHolder = new AtomicReference<SelectionDialog>();
        final SelectionDialog dialog = JavaUI.createTypeDialog(parent, new ProgressMonitorDialog(parent), scope,
                IJavaElementSearchConstants.CONSIDER_CLASSES, false,
                // Use ? as a default filter to fill dialog with matches
                "?", //$NON-NLS-1$
                new TypeSelectionExtension() {
                    @Override
                    public Control createContentArea(Composite parentComposite) {
                        Composite composite = new Composite(parentComposite, SWT.NONE);
                        composite.setLayout(new GridLayout(1, false));
                        Button button = new Button(composite, SWT.PUSH);
                        button.setText("Create New...");
                        button.addSelectionListener(new SelectionAdapter() {
                            @Override
                            public void widgetSelected(SelectionEvent e) {
                                String fqcn = createNewFragmentClass(javaProject);
                                if (fqcn != null) {
                                    returnValue.set(fqcn);
                                    dialogHolder.get().close();
                                }
                            }
                        });
                        return composite;
                    }

                    @Override
                    public ITypeInfoFilterExtension getFilterExtension() {
                        return new ITypeInfoFilterExtension() {
                            @Override
                            public boolean select(ITypeInfoRequestor typeInfoRequestor) {
                                int modifiers = typeInfoRequestor.getModifiers();
                                if (!Flags.isPublic(modifiers) || Flags.isInterface(modifiers)
                                        || Flags.isEnum(modifiers) || Flags.isAbstract(modifiers)) {
                                    return false;
                                }
                                return true;
                            }
                        };
                    }
                });
        dialogHolder.set(dialog);

        dialog.setTitle("Choose Fragment Class");
        dialog.setMessage("Select a Fragment class (? = any character, * = any string):");
        if (dialog.open() == IDialogConstants.CANCEL_ID) {
            return null;
        }
        if (returnValue.get() != null) {
            return returnValue.get();
        }

        Object[] types = dialog.getResult();
        if (types != null && types.length > 0) {
            return ((IType) types[0]).getFullyQualifiedName();
        }
    } catch (JavaModelException e) {
        AdtPlugin.log(e, null);
    } catch (CoreException e) {
        AdtPlugin.log(e, null);
    }
    return null;
}

From source file:com.android.ide.eclipse.adt.internal.editors.layout.gre.ClientRulesEngine.java

License:Open Source License

@Override
public String displayCustomViewClassInput() {
    try {//ww w  .  j ava 2s .  co m
        IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
        IProject project = mRulesEngine.getProject();
        final IJavaProject javaProject = BaseProjectHelper.getJavaProject(project);
        if (javaProject != null) {
            // Look up sub-types of each (new fragment class and compatibility fragment
            // class, if any) and merge the two arrays - then create a scope from these
            // elements.
            IType[] viewTypes = new IType[0];
            IType fragmentType = javaProject.findType(CLASS_VIEW);
            if (fragmentType != null) {
                ITypeHierarchy hierarchy = fragmentType.newTypeHierarchy(new NullProgressMonitor());
                viewTypes = hierarchy.getAllSubtypes(fragmentType);
            }
            scope = SearchEngine.createJavaSearchScope(viewTypes, IJavaSearchScope.SOURCES);
        }

        Shell parent = AdtPlugin.getShell();
        final AtomicReference<String> returnValue = new AtomicReference<String>();
        final AtomicReference<SelectionDialog> dialogHolder = new AtomicReference<SelectionDialog>();
        final SelectionDialog dialog = JavaUI.createTypeDialog(parent, new ProgressMonitorDialog(parent), scope,
                IJavaElementSearchConstants.CONSIDER_CLASSES, false,
                // Use ? as a default filter to fill dialog with matches
                "?", //$NON-NLS-1$
                new TypeSelectionExtension() {
                    @Override
                    public Control createContentArea(Composite parentComposite) {
                        Composite composite = new Composite(parentComposite, SWT.NONE);
                        composite.setLayout(new GridLayout(1, false));
                        Button button = new Button(composite, SWT.PUSH);
                        button.setText("Create New...");
                        button.addSelectionListener(new SelectionAdapter() {
                            @Override
                            public void widgetSelected(SelectionEvent e) {
                                String fqcn = createNewCustomViewClass(javaProject);
                                if (fqcn != null) {
                                    returnValue.set(fqcn);
                                    dialogHolder.get().close();
                                }
                            }
                        });
                        return composite;
                    }

                    @Override
                    public ITypeInfoFilterExtension getFilterExtension() {
                        return new ITypeInfoFilterExtension() {
                            @Override
                            public boolean select(ITypeInfoRequestor typeInfoRequestor) {
                                int modifiers = typeInfoRequestor.getModifiers();
                                if (!Flags.isPublic(modifiers) || Flags.isInterface(modifiers)
                                        || Flags.isEnum(modifiers) || Flags.isAbstract(modifiers)) {
                                    return false;
                                }
                                return true;
                            }
                        };
                    }
                });
        dialogHolder.set(dialog);

        dialog.setTitle("Choose Custom View Class");
        dialog.setMessage("Select a Custom View class (? = any character, * = any string):");
        if (dialog.open() == IDialogConstants.CANCEL_ID) {
            return null;
        }
        if (returnValue.get() != null) {
            return returnValue.get();
        }

        Object[] types = dialog.getResult();
        if (types != null && types.length > 0) {
            return ((IType) types[0]).getFullyQualifiedName();
        }
    } catch (JavaModelException e) {
        AdtPlugin.log(e, null);
    } catch (CoreException e) {
        AdtPlugin.log(e, null);
    }
    return null;
}

From source file:com.android.ide.eclipse.adt.internal.editors.manifest.ManifestInfo.java

License:Open Source License

/** Creates a package search scope for the first package root in the given java project */
private static IJavaSearchScope createPackageScope(IJavaProject javaProject) {
    IPackageFragmentRoot packageRoot = getSourcePackageRoot(javaProject);

    IJavaSearchScope scope;//from  w w  w . ja v  a  2s . co  m
    if (packageRoot != null) {
        IJavaElement[] scopeElements = new IJavaElement[] { packageRoot };
        scope = SearchEngine.createJavaSearchScope(scopeElements);
    } else {
        scope = SearchEngine.createWorkspaceScope();
    }
    return scope;
}

From source file:com.android.ide.eclipse.adt.internal.editors.xml.Hyperlinks.java

License:Open Source License

/**
 * Opens a Java method referenced by the given on click attribute method name
 *
 * @param project the project containing the click handler
 * @param method the method name of the on click handler
 * @return true if the method was opened, false otherwise
 *//*from ww  w  .  j  a  va 2s. c  o  m*/
public static boolean openOnClickMethod(IProject project, String method) {
    // Search for the method in the Java index, filtering by the required click handler
    // method signature (public and has a single View parameter), and narrowing the scope
    // first to Activity classes, then to the whole workspace.
    final AtomicBoolean success = new AtomicBoolean(false);
    SearchRequestor requestor = new SearchRequestor() {
        @Override
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
            Object element = match.getElement();
            if (element instanceof IMethod) {
                IMethod methodElement = (IMethod) element;
                String[] parameterTypes = methodElement.getParameterTypes();
                if (parameterTypes != null && parameterTypes.length == 1
                        && ("Qandroid.view.View;".equals(parameterTypes[0]) //$NON-NLS-1$
                                || "QView;".equals(parameterTypes[0]))) { //$NON-NLS-1$
                    // Check that it's public
                    if (Flags.isPublic(methodElement.getFlags())) {
                        JavaUI.openInEditor(methodElement);
                        success.getAndSet(true);
                    }
                }
            }
        }
    };
    try {
        IJavaSearchScope scope = null;
        IType activityType = null;
        IJavaProject javaProject = BaseProjectHelper.getJavaProject(project);
        if (javaProject != null) {
            activityType = javaProject.findType(SdkConstants.CLASS_ACTIVITY);
            if (activityType != null) {
                scope = SearchEngine.createHierarchyScope(activityType);
            }
        }
        if (scope == null) {
            scope = SearchEngine.createWorkspaceScope();
        }

        SearchParticipant[] participants = new SearchParticipant[] {
                SearchEngine.getDefaultSearchParticipant() };
        int matchRule = SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE;
        SearchPattern pattern = SearchPattern.createPattern("*." + method, IJavaSearchConstants.METHOD,
                IJavaSearchConstants.DECLARATIONS, matchRule);
        SearchEngine engine = new SearchEngine();
        engine.search(pattern, participants, scope, requestor, new NullProgressMonitor());

        boolean ok = success.get();
        if (!ok && activityType != null) {
            // TODO: Create a project+dependencies scope and search only that scope

            // Try searching again with a complete workspace scope this time
            scope = SearchEngine.createWorkspaceScope();
            engine.search(pattern, participants, scope, requestor, new NullProgressMonitor());

            // TODO: There could be more than one match; add code to consider them all
            // and pick the most likely candidate and open only that one.

            ok = success.get();
        }
        return ok;
    } catch (CoreException e) {
        AdtPlugin.log(e, null);
    }
    return false;
}

From source file:com.android.ide.eclipse.adt.internal.wizards.templates.NewTemplatePage.java

License:Open Source License

private String chooseActivity() {
    try {//from   w  w  w . j  a  va2 s  .  c  o m
        // Compute a search scope: We need to merge all the subclasses
        // android.app.Fragment and android.support.v4.app.Fragment
        IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
        IProject project = mValues.project;
        IJavaProject javaProject = BaseProjectHelper.getJavaProject(project);
        IType activityType = null;

        if (javaProject != null) {
            activityType = javaProject.findType(CLASS_ACTIVITY);
        }
        if (activityType == null) {
            IJavaProject[] projects = BaseProjectHelper.getAndroidProjects(null);
            for (IJavaProject p : projects) {
                activityType = p.findType(CLASS_ACTIVITY);
                if (activityType != null) {
                    break;
                }
            }
        }
        if (activityType != null) {
            NullProgressMonitor monitor = new NullProgressMonitor();
            ITypeHierarchy hierarchy = activityType.newTypeHierarchy(monitor);
            IType[] classes = hierarchy.getAllSubtypes(activityType);
            scope = SearchEngine.createJavaSearchScope(classes, IJavaSearchScope.SOURCES);
        }

        Shell parent = AdtPlugin.getShell();
        final SelectionDialog dialog = JavaUI.createTypeDialog(parent, new ProgressMonitorDialog(parent), scope,
                IJavaElementSearchConstants.CONSIDER_CLASSES, false,
                // Use ? as a default filter to fill dialog with matches
                "?", //$NON-NLS-1$
                new TypeSelectionExtension() {
                    @Override
                    public ITypeInfoFilterExtension getFilterExtension() {
                        return new ITypeInfoFilterExtension() {
                            @Override
                            public boolean select(ITypeInfoRequestor typeInfoRequestor) {
                                int modifiers = typeInfoRequestor.getModifiers();
                                if (!Flags.isPublic(modifiers) || Flags.isInterface(modifiers)
                                        || Flags.isEnum(modifiers)) {
                                    return false;
                                }
                                return true;
                            }
                        };
                    }
                });

        dialog.setTitle("Choose Activity Class");
        dialog.setMessage("Select an Activity class (? = any character, * = any string):");
        if (dialog.open() == IDialogConstants.CANCEL_ID) {
            return null;
        }

        Object[] types = dialog.getResult();
        if (types != null && types.length > 0) {
            return ((IType) types[0]).getFullyQualifiedName();
        }
    } catch (JavaModelException e) {
        AdtPlugin.log(e, null);
    } catch (CoreException e) {
        AdtPlugin.log(e, null);
    }
    return null;
}

From source file:com.android.ide.eclipse.adt.SourceRevealer.java

License:Open Source License

private List<SearchMatch> searchForPattern(String pattern, int searchFor,
        Predicate<SearchMatch> filterPredicate) {
    SearchEngine se = new SearchEngine();
    SearchPattern searchPattern = SearchPattern.createPattern(pattern, searchFor,
            IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);
    SearchResultAccumulator requestor = new SearchResultAccumulator(filterPredicate);
    try {/*from  w  w  w.j av a2  s  . c o  m*/
        se.search(searchPattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
                SearchEngine.createWorkspaceScope(), requestor, new NullProgressMonitor());
    } catch (CoreException e) {
        AdtPlugin.printErrorToConsole(e.getMessage());
        return Collections.emptyList();
    }

    return requestor.getMatches();
}

From source file:com.android.ide.eclipse.auidt.internal.editors.layout.gre.ClientRulesEngine.java

License:Open Source License

@Override
public String displayFragmentSourceInput() {
    try {//  w  w  w  .  ja  v a 2  s .  c om
        // Compute a search scope: We need to merge all the subclasses
        // android.app.Fragment and android.support.v4.app.Fragment
        IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
        IProject project = mRulesEngine.getProject();
        final IJavaProject javaProject = BaseProjectHelper.getJavaProject(project);
        if (javaProject != null) {
            IType oldFragmentType = javaProject.findType(CLASS_V4_FRAGMENT);

            // First check to make sure fragments are available, and if not,
            // warn the user.
            IAndroidTarget target = Sdk.getCurrent().getTarget(project);
            // No, this should be using the min SDK instead!
            if (target.getVersion().getApiLevel() < 11 && oldFragmentType == null) {
                // Compatibility library must be present
                MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(),
                        "Fragment Warning", null,
                        "Fragments require API level 11 or higher, or a compatibility "
                                + "library for older versions.\n\n"
                                + " Do you want to install the compatibility library?",
                        MessageDialog.QUESTION, new String[] { "Install", "Cancel" },
                        1 /* default button: Cancel */);
                int answer = dialog.open();
                if (answer == 0) {
                    if (!AddSupportJarAction.install(project)) {
                        return null;
                    }
                } else {
                    return null;
                }
            }

            // Look up sub-types of each (new fragment class and compatibility fragment
            // class, if any) and merge the two arrays - then create a scope from these
            // elements.
            IType[] fragmentTypes = new IType[0];
            IType[] oldFragmentTypes = new IType[0];
            if (oldFragmentType != null) {
                ITypeHierarchy hierarchy = oldFragmentType.newTypeHierarchy(new NullProgressMonitor());
                oldFragmentTypes = hierarchy.getAllSubtypes(oldFragmentType);
            }
            IType fragmentType = javaProject.findType(CLASS_FRAGMENT);
            if (fragmentType != null) {
                ITypeHierarchy hierarchy = fragmentType.newTypeHierarchy(new NullProgressMonitor());
                fragmentTypes = hierarchy.getAllSubtypes(fragmentType);
            }
            IType[] subTypes = new IType[fragmentTypes.length + oldFragmentTypes.length];
            System.arraycopy(fragmentTypes, 0, subTypes, 0, fragmentTypes.length);
            System.arraycopy(oldFragmentTypes, 0, subTypes, fragmentTypes.length, oldFragmentTypes.length);
            scope = SearchEngine.createJavaSearchScope(subTypes, IJavaSearchScope.SOURCES);
        }

        Shell parent = AdtPlugin.getDisplay().getActiveShell();
        final AtomicReference<String> returnValue = new AtomicReference<String>();
        final AtomicReference<SelectionDialog> dialogHolder = new AtomicReference<SelectionDialog>();
        final SelectionDialog dialog = JavaUI.createTypeDialog(parent, new ProgressMonitorDialog(parent), scope,
                IJavaElementSearchConstants.CONSIDER_CLASSES, false,
                // Use ? as a default filter to fill dialog with matches
                "?", //$NON-NLS-1$
                new TypeSelectionExtension() {
                    @Override
                    public Control createContentArea(Composite parentComposite) {
                        Composite composite = new Composite(parentComposite, SWT.NONE);
                        composite.setLayout(new GridLayout(1, false));
                        Button button = new Button(composite, SWT.PUSH);
                        button.setText("Create New...");
                        button.addSelectionListener(new SelectionAdapter() {
                            @Override
                            public void widgetSelected(SelectionEvent e) {
                                String fqcn = createNewFragmentClass(javaProject);
                                if (fqcn != null) {
                                    returnValue.set(fqcn);
                                    dialogHolder.get().close();
                                }
                            }
                        });
                        return composite;
                    }

                    @Override
                    public ITypeInfoFilterExtension getFilterExtension() {
                        return new ITypeInfoFilterExtension() {
                            @Override
                            public boolean select(ITypeInfoRequestor typeInfoRequestor) {
                                int modifiers = typeInfoRequestor.getModifiers();
                                if (!Flags.isPublic(modifiers) || Flags.isInterface(modifiers)
                                        || Flags.isEnum(modifiers)) {
                                    return false;
                                }
                                return true;
                            }
                        };
                    }
                });
        dialogHolder.set(dialog);

        dialog.setTitle("Choose Fragment Class");
        dialog.setMessage("Select a Fragment class (? = any character, * = any string):");
        if (dialog.open() == IDialogConstants.CANCEL_ID) {
            return null;
        }
        if (returnValue.get() != null) {
            return returnValue.get();
        }

        Object[] types = dialog.getResult();
        if (types != null && types.length > 0) {
            return ((IType) types[0]).getFullyQualifiedName();
        }
    } catch (JavaModelException e) {
        AdtPlugin.log(e, null);
    } catch (CoreException e) {
        AdtPlugin.log(e, null);
    }
    return null;
}