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:org.jboss.tools.fuse.transformation.editor.internal.wizards.OtherPage.java

License:Open Source License

/**
 * @param shell Shell for the window//  w  ww  .  ja v  a 2s. com
 * @param superTypeName supertype to search for
 * @param project project to look in
 * @return IType the type created
 * @throws JavaModelException exception thrown
 */
public IType selectType(Shell shell, String superTypeName, IProject project) throws JavaModelException {
    IJavaSearchScope searchScope = null;
    if (project == null) {
        ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService()
                .getSelection();
        if (selection instanceof IStructuredSelection) {
            IStructuredSelection selectionToPass = (IStructuredSelection) selection;
            if (selectionToPass.getFirstElement() instanceof IFile) {
                project = ((IFile) selectionToPass.getFirstElement()).getProject();
            }
        }
    }
    if (superTypeName == null) {
        superTypeName = "java.lang.Object"; //$NONNLS-1$ //$NON-NLS-1$
    }
    if (CamelUtils.project() != null) {
        if (project == null) {
            project = CamelUtils.project();
        }
        IJavaProject javaProject = JavaCore.create(project);
        IType superType = javaProject.findType(superTypeName);
        if (superType != null) {
            searchScope = SearchEngine.createStrictHierarchyScope(javaProject, superType, true, false, null);
        }
    } else {
        searchScope = SearchEngine.createWorkspaceScope();
    }
    SelectionDialog dialog = JavaUI.createTypeDialog(shell, new ProgressMonitorDialog(shell), searchScope,
            IJavaElementSearchConstants.CONSIDER_CLASSES_AND_INTERFACES, false, "**"); //$NON-NLS-1$
    dialog.setTitle(Messages.OtherPage_selectClassDialogTitle);
    dialog.setMessage(Messages.OtherPage_matchingitemsMessageSelectClassDialog);
    if (dialog instanceof ITypeSelectionComponent) {
        ((ITypeSelectionComponent) dialog).triggerSearch();
    }
    if (dialog.open() == IDialogConstants.CANCEL_ID) {
        return null;
    }
    Object[] types = dialog.getResult();
    if (types == null || types.length == 0) {
        return null;
    }
    return (IType) types[0];
}

From source file:org.nuxeo.ide.sdk.server.ui.OpenClassAction.java

License:Open Source License

public void run() {
    Job job = new Job("Open class") {
        @Override/*from  ww w.  j  a v a 2s  .c  om*/
        protected IStatus run(IProgressMonitor monitor) {
            monitor.beginTask("Finding type", 1);
            SearchEngine engine = new SearchEngine();
            IStatus status = Status.OK_STATUS;
            try {
                engine.searchAllTypeNames(packageName.toCharArray(), SearchPattern.R_EXACT_MATCH,
                        className.toCharArray(), SearchPattern.R_EXACT_MATCH,
                        IJavaSearchConstants.CLASS_AND_INTERFACE, SearchEngine.createWorkspaceScope(),
                        OpenClassAction.this, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, monitor);
                monitor.worked(1);
            } catch (Throwable t) {
                status = new Status(IStatus.ERROR, SDKPlugin.PLUGIN_ID,
                        "failed to seach for type: " + packageName + "." + className, t);
            }
            monitor.done();
            return status;
        }
    };
    job.schedule();
    try {
        job.join();
        if (match != null) {
            JavaUI.openInEditor(match.getType());
        } else {
            UI.showWarning("No class matching '" + packageName + "." + className + "' was found");
        }
    } catch (Exception e) {
        // do nothing
    }
}

From source file:org.oobium.build.console.Eclipse.java

License:Open Source License

public static void openType(String type, final int line) {
    if (type.contains("$")) {
        // handles inner classes
        type = type.substring(0, type.indexOf('$'));
    }//from www  . j  a v  a  2 s  .co  m

    SearchPattern pattern = SearchPattern.createPattern(type, IJavaSearchConstants.TYPE,
            IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);
    IJavaSearchScope scope = SearchEngine.createWorkspaceScope();

    SearchRequestor sr = new SearchRequestor() {
        @Override
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
            IResource resource = match.getResource();
            if (resource instanceof IFile) {
                final IFile file = (IFile) match.getResource();
                logger.debug(String.valueOf(match));
                Display.getDefault().asyncExec(new Runnable() {
                    @Override
                    public void run() {
                        open(file, null, line);
                    }
                });
            } else {
                Object element = match.getElement();
                if (element instanceof IType) {
                    final IType itype = (IType) element;
                    Display.getDefault().asyncExec(new Runnable() {
                        @Override
                        public void run() {
                            Object parent = itype.getParent();
                            if (parent instanceof IFile) {
                                open(parent, null, line);
                            }
                            if (parent instanceof IClassFile) {
                                // TODO is there a better way to do this?
                                IEditorInput input = EditorUtility.getEditorInput(itype.getParent());
                                open(input, "org.eclipse.jdt.ui.ClassFileEditor", line);
                            }
                        }
                    });
                }
            }
        }
    };

    SearchEngine engine = new SearchEngine();
    try {
        engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
                sr, null);
    } catch (CoreException e) {
        e.printStackTrace();
    }
}

From source file:org.openlegacy.ide.eclipse.actions.CustomizeScreenEntityDialog.java

License:Open Source License

private static SelectionListener getBrowseButtonSelectionListener(final CCombo combo) {
    return new SelectionAdapter() {

        @Override// www  .  j a v  a  2 s  .c  om
        public void widgetSelected(SelectionEvent e) {
            IRunnableContext context = new BusyIndicatorRunnableContext();
            IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
            TypesSelectionDialog dialog = new TypesSelectionDialog(e.widget.getDisplay().getActiveShell(),
                    false, context, scope, IJavaSearchConstants.CLASS);
            ScreenTypeViewerFilter filter = new ScreenTypeViewerFilter();
            dialog.addListFilter(filter);
            dialog.setTitle(Messages.getString("title_select_class_dialog"));//$NON-NLS-1$
            if (dialog.open() == Window.OK) {
                IType res = (IType) dialog.getResult()[0];
                combo.setData(ID_FULLY_QUALIFIED_NAME, res.getFullyQualifiedName());
                combo.setText(res.getElementName());
            }
        }

    };
}

From source file:org.polarsys.reqcycle.jdt.traceability.preferences.NewAnnotDialog.java

License:Open Source License

/**
 * Create contents of the dialog./*  w  w w  .ja  v a 2s  . c  om*/
 * 
 * @param parent
 */
@Override
protected Control createDialogArea(Composite parent) {
    setTitleImage(ResourceManager.getPluginImage("org.polarsys.reqcycle.jdt.traceability", "icons/annot.gif"));
    setTitle("Register new Annotation");
    Composite area = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(area, SWT.NONE);
    container.setLayout(new GridLayout(3, false));
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    Label lblAnnotationName = new Label(container, SWT.NONE);
    lblAnnotationName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblAnnotationName.setText("Annotation Name : ");

    text = new Text(container, SWT.BORDER);
    text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    text.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            annotName = text.getText();
        }
    });

    Button button = new Button(container, SWT.NONE);
    button.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            OpenTypeSelectionDialog d = new OpenTypeSelectionDialog(getShell(), false,
                    PlatformUI.getWorkbench().getProgressService(), SearchEngine.createWorkspaceScope(),
                    IJavaSearchConstants.ANNOTATION_TYPE);
            if (d.open() == OpenTypeSelectionDialog.OK) {
                SourceType type = (SourceType) d.getFirstResult();
                text.setText(type.getElementName());
            }
        }
    });
    button.setText("...");

    Label lblKind = new Label(container, SWT.NONE);
    lblKind.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblKind.setText("Kind : ");

    comboViewer = new ComboViewer(container, SWT.None);
    Combo combo = comboViewer.getCombo();
    combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
    comboViewer.setContentProvider(new ArrayContentProvider());
    comboViewer.setLabelProvider(new LabelProvider());
    input.addAll(JDTPreferences.getPreferences().keySet());
    comboViewer.setInput(input);
    comboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            link = new JDTType(comboViewer.getCCombo().getText());
        }
    });
    return area;
}

From source file:org.springframework.ide.eclipse.quickfix.proposals.CreateNewClassQuickFixProposal.java

License:Open Source License

private IPackageFragment findPackageFragment(String packageName) {
    final List<IPackageFragment> results = new ArrayList<IPackageFragment>();

    SearchRequestor collector = new SearchRequestor() {

        @Override/*from  ww w .j  a v  a2s .c  o  m*/
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
            Object element = match.getElement();
            if (element instanceof IPackageFragment) {
                IPackageFragment packageFragment = (IPackageFragment) element;
                if (!packageFragment.isReadOnly()) {
                    results.add(packageFragment);
                }
            }
        }
    };

    SearchEngine engine = new SearchEngine();
    SearchPattern pattern = SearchPattern.createPattern(packageName, IJavaSearchConstants.PACKAGE,
            IJavaSearchConstants.ALL_OCCURRENCES, SearchPattern.R_EXACT_MATCH);
    try {
        engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
                SearchEngine.createWorkspaceScope(), collector, new NullProgressMonitor());
    } catch (CoreException e) {
    }

    if (results.size() > 0) {
        return results.get(0);
    }
    return null;
}

From source file:org.springframework.ide.eclipse.webflow.ui.graph.dialogs.MappingEditorDialog.java

License:Open Source License

/**
 * One of the buttons has been pressed, act accordingly.
 * //from   w  w w.j a  va2s.  co m
 * @param button 
 */
private void handleButtonPressed(Button button) {

    IJavaSearchScope searchScope = SearchEngine.createWorkspaceScope();
    FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(getShell(), false,
            new ProgressMonitorDialog(getShell()), searchScope, IJavaSearchConstants.CLASS);

    dialog.setMessage("Select an type"); //$NON-NLS-1$
    dialog.setBlockOnOpen(true);
    dialog.setTitle("Type Selection");
    // dialog.setFilter("*");
    if (Dialog.OK == dialog.open()) {
        IType obj = (IType) dialog.getFirstResult();
        this.requiredText.setText(obj.getFullyQualifiedName());
    }

    this.validateInput();

}

From source file:org.springframework.ide.eclipse.webflow.ui.graph.dialogs.MethodArgumentEditorDialog.java

License:Open Source License

/**
 * One of the buttons has been pressed, act accordingly.
 * /*from  w w w.  j a v  a 2  s  .c om*/
 * @param button 
 */
private void handleButtonPressed(Button button) {

    IJavaSearchScope searchScope = SearchEngine.createWorkspaceScope();
    FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(getShell(), false,
            new ProgressMonitorDialog(getShell()), searchScope, IJavaSearchConstants.CLASS);

    dialog.setMessage("Select an type"); //$NON-NLS-1$
    dialog.setBlockOnOpen(true);
    dialog.setTitle("Type Selection");
    // dialog.setFilter("*");
    if (Dialog.OK == dialog.open()) {
        IType obj = (IType) dialog.getFirstResult();
        this.parameterTypeText.setText(obj.getFullyQualifiedName());
    }

    this.validateInput();

}

From source file:org.springframework.ide.eclipse.webflow.ui.graph.dialogs.PropertyEditorDialog.java

License:Open Source License

/**
 * One of the buttons has been pressed, act accordingly.
 * /*from  w w  w .java 2 s.co  m*/
 * @param button 
 */
private void handleButtonPressed(Button button) {

    IJavaSearchScope searchScope = SearchEngine.createWorkspaceScope();
    FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(getShell(), false,
            new ProgressMonitorDialog(getShell()), searchScope, IJavaSearchConstants.CLASS);

    dialog.setMessage("Select an type"); //$NON-NLS-1$
    dialog.setBlockOnOpen(true);
    dialog.setTitle("Type Selection");
    // dialog.setFilter("*");
    if (Dialog.OK == dialog.open()) {
        IType obj = (IType) dialog.getFirstResult();
        this.typeText.setText(obj.getFullyQualifiedName());
    }

    this.validateInput();

}

From source file:org.springframework.ide.eclipse.webflow.ui.graph.dialogs.VarEditorDialog.java

License:Open Source License

/**
 * One of the buttons has been pressed, act accordingly.
 * @param button/*from  ww  w .ja v  a  2  s  .  co  m*/
 */
private void handleButtonPressed(Button button) {

    if (button.equals(this.browseTypeButton)) {

        IJavaSearchScope searchScope = SearchEngine.createWorkspaceScope();
        FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(getShell(), false,
                new ProgressMonitorDialog(getShell()), searchScope, IJavaSearchConstants.CLASS);

        dialog.setMessage("Select an type"); //$NON-NLS-1$
        dialog.setBlockOnOpen(true);
        dialog.setTitle("Type Selection");
        if (Dialog.OK == dialog.open()) {
            IType obj = (IType) dialog.getFirstResult();
            this.classText.setText(obj.getFullyQualifiedName());
        }
    } else if (button.equals(this.browseBeanButton)) {
        ElementListSelectionDialog dialog = DialogUtils.openBeanReferenceDialog(this.beanText.getText(), false);
        if (Dialog.OK == dialog.open()) {
            this.beanText.setText(((IBean) dialog.getFirstResult()).getElementName());
        }
    }
    this.validateInput();

}