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:com.hudson.hibernatesynchronizer.wizard.NewMappingWizardPage.java

License:GNU General Public License

public Composite addConfiguration(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);//from  w  w w . ja  v  a  2 s. c o m
    layout.numColumns = 3;
    layout.verticalSpacing = 9;

    Label label = new Label(container, SWT.NULL);
    label.setText("&Container:");

    containerText = new Text(container, SWT.BORDER | SWT.SINGLE);
    containerText.setEnabled(false);
    containerText.setBackground(new Color(null, 255, 255, 255));
    GridData gd = new GridData();
    gd.widthHint = 250;
    containerText.setLayoutData(gd);
    containerText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    Button containerButton = new Button(container, SWT.NATIVE);
    containerButton.setText("Browse");
    containerButton.addMouseListener(new ContainerMouseListener(this));

    label = new Label(container, SWT.NULL);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalSpan = 3;
    label.setLayoutData(gd);

    label = new Label(container, SWT.NULL);
    label.setText("&Driver:");
    driverText = new Text(container, SWT.BORDER | SWT.SINGLE);
    driverText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    driverText.setEnabled(false);
    driverText.setBackground(new Color(null, 255, 255, 255));
    gd = new GridData();
    gd.widthHint = 250;
    driverText.setLayoutData(gd);
    Button driverButton = new Button(container, SWT.NATIVE);
    driverButton.setText("Browse");
    driverButton.addMouseListener(new DriverMouseListener(this));

    label = new Label(container, SWT.NULL);
    label.setText("&Database URL:");
    databaseUrlText = new Text(container, SWT.BORDER | SWT.SINGLE);
    databaseUrlText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    gd = new GridData();
    gd.horizontalSpan = 2;
    gd.widthHint = 250;
    databaseUrlText.setLayoutData(gd);

    label = new Label(container, SWT.NULL);
    label.setText("&Username:");
    usernameText = new Text(container, SWT.BORDER | SWT.SINGLE);
    usernameText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    gd = new GridData();
    gd.horizontalSpan = 2;
    gd.widthHint = 150;
    usernameText.setLayoutData(gd);

    label = new Label(container, SWT.NULL);
    label.setText("&Password:");
    passwordText = new Text(container, SWT.BORDER | SWT.SINGLE);
    passwordText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    passwordText.setEchoChar('*');
    gd = new GridData();
    gd.horizontalSpan = 2;
    gd.widthHint = 150;
    passwordText.setLayoutData(gd);

    label = new Label(container, SWT.NULL);
    label.setText("Table pattern:");
    tablePattern = new Text(container, SWT.BORDER | SWT.SINGLE);
    tablePattern.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    tablePattern.setEnabled(true);
    tablePattern.setBackground(new Color(null, 255, 255, 255));
    gd = new GridData();
    gd.horizontalSpan = 2;
    gd.widthHint = 250;
    tablePattern.setLayoutData(gd);

    label = new Label(container, SWT.NULL);
    label.setText("Schema pattern:");
    schemaPattern = new Text(container, SWT.BORDER | SWT.SINGLE);
    schemaPattern.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    schemaPattern.setEnabled(true);
    schemaPattern.setBackground(new Color(null, 255, 255, 255));
    gd = new GridData();
    gd.horizontalSpan = 2;
    gd.widthHint = 250;
    schemaPattern.setLayoutData(gd);

    label = new Label(container, SWT.NULL);
    label.setText("Tables");
    table = new Table(container, SWT.BORDER | SWT.H_SCROLL | SWT.FULL_SELECTION | SWT.CHECK);
    table.setVisible(true);
    table.setLinesVisible(false);
    table.setHeaderVisible(false);
    table.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            dialogChanged();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    GridData data = new GridData();
    data.heightHint = 150;
    data.widthHint = 250;
    table.setLayoutData(data);

    // create the columns
    TableColumn nameColumn = new TableColumn(table, SWT.LEFT);
    ColumnLayoutData nameColumnLayout = new ColumnWeightData(100, false);

    // set columns in Table layout
    TableLayout tableLayout = new TableLayout();
    tableLayout.addColumnData(nameColumnLayout);
    table.setLayout(tableLayout);

    Composite buttonContainer = new Composite(container, SWT.NULL);
    buttonContainer.setLayout(new GridLayout(1, true));
    gd = new GridData();
    gd.verticalAlignment = GridData.BEGINNING;
    gd.horizontalAlignment = GridData.BEGINNING;
    buttonContainer.setLayoutData(gd);
    tableRefreshButton = new Button(buttonContainer, SWT.PUSH);
    tableRefreshButton.setText("Refresh");
    tableRefreshButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    tableRefreshButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
            try {
                dialog.run(false, true, new IRunnableWithProgress() {
                    public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {
                        try {
                            monitor.beginTask("Refreshing tables...", 21);
                            refreshTables(monitor);
                        } catch (Exception e) {
                            throw new InvocationTargetException(e);
                        } finally {
                            monitor.done();
                        }
                    }
                });
            } catch (Exception exc) {
            }
        }
    });
    selectAllButton = new Button(buttonContainer, SWT.PUSH);
    selectAllButton.setText("Select All");
    selectAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    selectAllButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            try {
                for (int i = 0; i < table.getItemCount(); i++) {
                    table.getItem(i).setChecked(true);
                }
                dialogChanged();
            } catch (Exception exc) {
            }
        }
    });
    selectNoneButton = new Button(buttonContainer, SWT.PUSH);
    selectNoneButton.setText("Select None");
    selectNoneButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    selectNoneButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            try {
                for (int i = 0; i < table.getItemCount(); i++) {
                    table.getItem(i).setChecked(false);
                }
                dialogChanged();
            } catch (Exception exc) {
            }
        }
    });

    label = new Label(container, SWT.NULL);
    label.setText("&Package:");
    packageText = new Text(container, SWT.BORDER | SWT.SINGLE);
    packageText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    gd = new GridData();
    gd.widthHint = 250;
    packageText.setLayoutData(gd);

    packageButton = new Button(container, SWT.NATIVE);
    packageButton.setText("Browse");
    packageButton.addMouseListener(new MouseListener() {
        public void mouseDown(MouseEvent e) {
            if (null != project) {
                try {
                    IJavaSearchScope searchScope = SearchEngine.createWorkspaceScope();
                    SelectionDialog sd = JavaUI.createPackageDialog(getShell(), project,
                            IJavaElementSearchConstants.CONSIDER_REQUIRED_PROJECTS);
                    sd.open();
                    Object[] objects = sd.getResult();
                    if (null != objects && objects.length > 0) {
                        IPackageFragment pf = (IPackageFragment) objects[0];
                        packageText.setText(pf.getElementName());
                    }
                } catch (JavaModelException jme) {
                    jme.printStackTrace();
                }
            }
        }

        public void mouseDoubleClick(MouseEvent e) {
        }

        public void mouseUp(MouseEvent e) {
        }

    });

    if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) {
        IStructuredSelection ssel = (IStructuredSelection) selection;
        if (ssel.size() == 1) {
            Object obj = ssel.getFirstElement();
            if (obj instanceof IResource) {
                IContainer cont;
                if (obj instanceof IContainer)
                    cont = (IContainer) obj;
                else
                    cont = ((IResource) obj).getParent();
                containerText.setText(cont.getFullPath().toString());
                projectChanged(cont.getProject());
            } else if (obj instanceof IPackageFragment) {
                IPackageFragment frag = (IPackageFragment) obj;
                containerText.setText(frag.getPath().toString());
                projectChanged(frag.getJavaProject().getProject());
            } else if (obj instanceof IPackageFragmentRoot) {
                IPackageFragmentRoot root = (IPackageFragmentRoot) obj;
                containerText.setText(root.getPath().toString());
                projectChanged(root.getJavaProject().getProject());
            } else if (obj instanceof IJavaProject) {
                IJavaProject proj = (IJavaProject) obj;
                containerText.setText("/" + proj.getProject().getName());
                projectChanged(proj.getProject());
            } else if (obj instanceof IProject) {
                IProject proj = (IProject) obj;
                containerText.setText("/" + proj.getName());
                projectChanged(proj);
            }
        }
    }

    containerText.forceFocus();
    initialize();
    dialogChanged();
    return container;
}

From source file:com.ibm.wala.ide.util.JdtUtil.java

License:Open Source License

/**
 * Find the IMethod in the workspace corresponding to a method signature.
 * //from   w  w w  .  java 2 s .co  m
 * This doesn't work for elements declared in inner classes. It's possible this is a 3.2 bug fixed in 3.3
 * 
 * @return null if not found
 */
@Deprecated
public static IMethod findJavaMethodInWorkspaceBrokenForInnerClasses(String methodSig) {
    // dammit ... this doesn't work for inner classes.

    System.err.println("Search for " + methodSig);
    SearchPattern p = SearchPattern.createPattern(methodSig, IJavaSearchConstants.METHOD,
            IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);
    IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
    SearchEngine engine = new SearchEngine();
    final Collection<IJavaElement> kludge = HashSetFactory.make();
    SearchRequestor requestor = new SearchRequestor() {

        @Override
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
            kludge.add((IJavaElement) match.getElement());
        }

    };
    try {
        engine.search(p, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
                requestor, null);
    } catch (CoreException e) {
        e.printStackTrace();
    }
    if (kludge.size() == 1) {
        return (IMethod) kludge.iterator().next();
    } else {
        System.err.println("RETURNED " + kludge.size() + " " + kludge);
        return null;
    }
}

From source file:com.iw.plugins.spindle.util.FieldBindingsPreferencePage.java

License:Mozilla Public License

public static IJavaElement[] unfold(String folded) {
    if (folded != null && !"".equals(folded.trim())) {
        ISearchPattern searchPattern = null;
        StringTokenizer tok = new StringTokenizer(folded, ",");
        while (tok.hasMoreTokens()) {
            String fragment = tok.nextToken();

            if (searchPattern == null) {

                searchPattern = SearchEngine.createSearchPattern(fragment, IJavaSearchConstants.PACKAGE,
                        IJavaSearchConstants.DECLARATIONS, false);
            } else {

                searchPattern = SearchEngine.createOrSearchPattern(searchPattern,
                        SearchEngine.createSearchPattern(fragment, IJavaSearchConstants.PACKAGE,
                                IJavaSearchConstants.DECLARATIONS, false));
            }//from  ww w  . ja  v a 2 s.c om
        }
        try {
            UnfoldSearchCollector collector = new UnfoldSearchCollector();
            long start = new Date().getTime();
            new SearchEngine().search(TapestryPlugin.getDefault().getWorkspace(), searchPattern,
                    SearchEngine.createWorkspaceScope(), collector);
            return collector.getFoundElements();
        } catch (JavaModelException jmex) {
            jmex.printStackTrace();
        }
    }
    return new IJavaElement[0];
}

From source file:com.legstar.eclipse.plugin.cixscom.wizards.CixsProxyPojoTargetGroup.java

License:Open Source License

/**
 * {@inheritDoc}//from w  ww. j a v a2 s.  com
 */
public void createControls(final Composite composite) {
    super.createControls(composite, Messages.target_pojo_group_label, 3);

    AbstractWizardPage.createLabel(getGroup(), Messages.target_pojo_class_name_label + ':');
    _classNameText = AbstractWizardPage.createText(getGroup());

    Button browseButton = AbstractWizardPage.createButton(getGroup(),
            com.legstar.eclipse.plugin.common.Messages.browse_button_label);
    browseButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            try {
                SelectionDialog dialog = JavaUI.createTypeDialog(getShell(),
                        PlatformUI.getWorkbench().getProgressService(), SearchEngine.createWorkspaceScope(),
                        IJavaElementSearchConstants.CONSIDER_CLASSES, false);
                if (Window.OK == dialog.open()) {
                    Object[] results = dialog.getResult();
                    if (results != null && results.length > 0) {
                        setClassName(((IType) results[0]).getFullyQualifiedName());
                    }
                }
            } catch (JavaModelException e1) {
                AbstractWizard.errorDialog(getShell(), Messages.class_selection_error_dialog_title,
                        Activator.PLUGIN_ID, Messages.class_selection_error_short_msg,
                        NLS.bind(Messages.class_selection_error_long_msg, e1.getMessage()));
                AbstractWizard.logCoreException(e1, Activator.PLUGIN_ID);
            }
        }
    });

    AbstractWizardPage.createLabel(getGroup(), Messages.target_pojo_method_name_label + ':');
    _methodNameText = AbstractWizardPage.createText(getGroup());
}

From source file:com.legstar.eclipse.plugin.mulegen.wizards.CixsProxyUmoComponentTargetGroup.java

License:Open Source License

/**
 * {@inheritDoc} //  w w  w.j  av a2 s .  c o  m
 */
public void createControls(final Composite composite) {
    super.createControls(composite, Messages.target_umo_component_group_label, 3);

    AbstractWizardPage.createLabel(getGroup(), Messages.target_umo_component_implementation_name_label + ':');
    _targetUmoComponentImplementationNameText = AbstractWizardPage.createText(getGroup());

    Button browseButton = AbstractWizardPage.createButton(getGroup(),
            com.legstar.eclipse.plugin.common.Messages.browse_button_label);
    browseButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            try {
                SelectionDialog dialog = JavaUI.createTypeDialog(getShell(),
                        PlatformUI.getWorkbench().getProgressService(), SearchEngine.createWorkspaceScope(),
                        IJavaElementSearchConstants.CONSIDER_CLASSES, false);
                if (Window.OK == dialog.open()) {
                    Object[] results = dialog.getResult();
                    if (results != null && results.length > 0) {
                        setImplementationName(((IType) results[0]).getFullyQualifiedName());
                    }
                }
            } catch (JavaModelException e1) {
                AbstractWizard.errorDialog(getShell(), Messages.class_selection_error_dialog_title,
                        Activator.PLUGIN_ID, Messages.class_selection_error_short_msg,
                        NLS.bind(Messages.class_selection_error_long_msg, e1.getMessage()));
                AbstractWizard.logCoreException(e1, Activator.PLUGIN_ID);
            }
        }
    });
}

From source file:com.legstar.eclipse.plugin.schemagen.wizards.JavaToXsdWizardPage.java

License:Open Source License

/**
 * Present a type selection dialog starting from the workspace root.
 * This will allow user to select java classes from more than one project.
 *//*  w ww.jav  a  2s. c  o m*/
private void addJavaClasses() {
    try {
        SelectionDialog dialog = JavaUI.createTypeDialog(getShell(),
                PlatformUI.getWorkbench().getProgressService(), SearchEngine.createWorkspaceScope(),
                IJavaElementSearchConstants.CONSIDER_CLASSES, true);
        if (Window.OK == dialog.open()) {
            Object[] results = dialog.getResult();
            if (results != null && results.length > 0) {
                for (Object obj : results) {
                    if (obj instanceof IType) {
                        if (!addJavaClass((IType) obj)) {
                            break;
                        }
                    }
                }
            }
            dialogChanged();
        }
    } catch (JavaModelException e1) {
        errorDialog(getShell(), Messages.selection_error_dialog_title, Activator.PLUGIN_ID,
                Messages.selection_dialog_init_failure_short_msg,
                NLS.bind(Messages.selection_dialog_init_failure_long_msg, e1.getMessage()));
        logCoreException(e1, Activator.PLUGIN_ID);
    }
}

From source file:com.mg.merp.wb.bai.BAiPlugin.java

License:Open Source License

private static IType getBAiAsType() {
    SearchPattern pattern = SearchPattern.createPattern(BAI_TYPE_NAME, IJavaSearchConstants.TYPE,
            IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EQUIVALENT_MATCH);
    IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
    class BAiTypeSearchRequestor extends SearchRequestor {

        private IType baiType = null;

        @Override//from  w ww . j a v  a  2 s  . c o m
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
            baiType = (IType) match.getElement();
        }

        /**
         *
         * @return ?  (AbstractBusinessAddin 
         *         ??  ,  ,    ..)
         */
        public IType getBaiType() {
            return baiType;
        }

    }
    BAiTypeSearchRequestor requestor = new BAiTypeSearchRequestor();

    SearchEngine searchEngine = new SearchEngine();
    try {
        searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
                scope, requestor, null);

    } catch (CoreException e) {
        return null;
    }

    return requestor.getBaiType();
}

From source file:com.mg.merp.wb.bai.ui.editor.BAiEditorPage.java

License:Open Source License

private String selectBAiImpl() {
    IJavaSearchScope scope = null;// www . ja v  a2 s.c om
    IType type = BAiPlugin.getBusinessAddinType();
    try {
        if (type == null)
            scope = SearchEngine.createWorkspaceScope();
        else
            scope = SearchEngine.createHierarchyScope(type);

        Shell sh = CoreUtils.getMainShell();
        SelectionDialog dialog = JavaUI.createTypeDialog(sh, new ProgressMonitorDialog(sh), scope,
                IJavaElementSearchConstants.CONSIDER_CLASSES, false);

        dialog.setTitle(BAiPlugin.getDefault().getString(BROWSE_DIALOG_TITLE));
        if (dialog.open() == Window.OK)
            return ((IType) dialog.getResult()[0]).getFullyQualifiedName();
        else
            return "";
    } catch (JavaModelException e1) {
        return "";
    }
}

From source file:com.mg.merp.wb.entitymapper.ui.editor.EntityMapperEditorPage.java

License:Open Source License

private String selectAvailableClasses() {
    try {//from ww  w . jav  a 2 s .c  o  m
        IJavaSearchScope scope = SearchEngine.createWorkspaceScope();

        Shell sh = CoreUtils.getMainShell();
        SelectionDialog dialog = JavaUI.createTypeDialog(sh, new ProgressMonitorDialog(sh), scope,
                IJavaElementSearchConstants.CONSIDER_CLASSES, false);

        dialog.setTitle(Activator.getDefault().getString(BROWSE_DIALOG_TITLE));
        if (dialog.open() == Window.OK)
            return ((IType) dialog.getResult()[0]).getFullyQualifiedName();
        else
            return "";
    } catch (JavaModelException e1) {
        return "";
    }
}

From source file:com.siteview.mde.internal.ui.editor.schema.SchemaJavaAttributeDetails.java

License:Open Source License

private void doOpenSelectionDialog(int scopeType, FormEntry entry) {
    try {//from w w  w .  j a v  a  2s .co m
        String filter = entry.getValue();
        filter = filter.substring(filter.lastIndexOf(".") + 1); //$NON-NLS-1$
        SelectionDialog dialog = JavaUI.createTypeDialog(MDEPlugin.getActiveWorkbenchShell(),
                PlatformUI.getWorkbench().getProgressService(), SearchEngine.createWorkspaceScope(), scopeType,
                false, filter);
        dialog.setTitle(MDEUIMessages.GeneralInfoSection_selectionTitle);
        if (dialog.open() == Window.OK) {
            IType type = (IType) dialog.getResult()[0];
            entry.setValue(type.getFullyQualifiedName('$'));
            entry.commit();
        }
    } catch (CoreException e) {
    }
}