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.eclipse.pde.internal.ds.ui.wizards.DSFileWizardPage.java

License:Open Source License

protected void createAdvancedControls(Composite parent) {
    IDialogSettings settings = getDialogSettings();
    if (settings != null) {
        String component = settings.get(S_COMPONENT_NAME);
        if (component != null && !component.equals("")) { //$NON-NLS-1$
            setFileName(component);/*  ww w  .  ja v  a  2  s  . c  o  m*/
        } else {
            setFileName(F_DEFAULT_COMPONENT_NAME);
        }
    } else {
        setFileName(F_DEFAULT_COMPONENT_NAME);
    }

    // Controls Group
    fGroup = new Group(parent, SWT.NONE);
    fGroup.setText(Messages.DSFileWizardPage_group);
    fGroup.setLayout(new GridLayout(3, false));
    fGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    GridData nameTextGridData = new GridData(GridData.FILL_HORIZONTAL);
    nameTextGridData.horizontalSpan = 2;
    nameTextGridData.horizontalIndent = 3;

    fDSComponentNameLabel = new Label(fGroup, SWT.None);
    fDSComponentNameLabel.setText(Messages.DSFileWizardPage_component_name);

    fDSComponentNameText = new Text(fGroup, SWT.SINGLE | SWT.BORDER);
    fDSComponentNameText.setLayoutData(nameTextGridData);
    fDSComponentNameText.setText(""); //$NON-NLS-1$
    fDSComponentNameText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            setPageComplete(isPageComplete());
        }
    });
    setComponentName();

    fDSImplementationClassHyperlink = new Link(fGroup, SWT.NONE);
    fDSImplementationClassHyperlink.setText("<a>" //$NON-NLS-1$
            + Messages.DSFileWizardPage_implementation_class + "</a>"); //$NON-NLS-1$
    fDSImplementationClassHyperlink.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLUE));
    fDSImplementationClassHyperlink.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            String value = fDSImplementationClassText.getText();
            value = handleLinkActivated(value, false);
            if (value != null)
                fDSImplementationClassText.setText(value);

        }

        private String handleLinkActivated(String value, boolean isInter) {
            Object object = fSelection.getFirstElement();
            if (object != null) {
                IProject project = getProject(object);
                try {
                    if (project != null && project.hasNature(JavaCore.NATURE_ID)) {
                        IJavaProject javaProject = JavaCore.create(project);
                        IJavaElement element = javaProject.findType(value.replace('$', '.'));
                        if (element != null)
                            JavaUI.openInEditor(element);
                        else {
                            // TODO create our own wizard for reuse
                            // here
                            DSNewClassCreationWizard wizard = new DSNewClassCreationWizard(project, isInter,
                                    value);
                            WizardDialog dialog = new WizardDialog(Activator.getActiveWorkbenchShell(), wizard);
                            dialog.create();
                            SWTUtil.setDialogSize(dialog, 400, 500);
                            if (dialog.open() == Window.OK) {
                                return wizard.getQualifiedName();
                            }
                        }
                    }
                } catch (PartInitException e1) {
                } catch (CoreException e1) {
                }
            }
            return null;
        }

    });

    // Implementation Class Text
    fDSImplementationClassText = new Text(fGroup, SWT.SINGLE | SWT.BORDER);
    GridData classTextGridData = new GridData(GridData.FILL_HORIZONTAL);
    classTextGridData.horizontalSpan = 1;
    classTextGridData.horizontalIndent = 3;
    fDSImplementationClassText.setLayoutData(classTextGridData);
    fDSImplementationClassText.setText("Component"); //$NON-NLS-1$
    fDSImplementationClassText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            setPageComplete(isPageComplete());
        }
    });

    // Implementation Class Browse Button
    fDSImplementationClassButton = new Button(fGroup, SWT.NONE);
    fDSImplementationClassButton.setText(Messages.DSFileWizardPage_browse);
    fDSImplementationClassButton.addMouseListener(new MouseListener() {

        public void mouseDoubleClick(MouseEvent e) {
            // do nothing
        }

        public void mouseDown(MouseEvent e) {
            // do nothing
        }

        public void mouseUp(MouseEvent e) {
            doOpenSelectionDialog(IJavaElementSearchConstants.CONSIDER_CLASSES, fDSImplementationClassText);
        }

        private void doOpenSelectionDialog(int scopeType, Text entry) {
            try {
                String filter = entry.getText();
                filter = filter.substring(filter.lastIndexOf(".") + 1); //$NON-NLS-1$
                SelectionDialog dialog = JavaUI.createTypeDialog(Activator.getActiveWorkbenchShell(),
                        PlatformUI.getWorkbench().getProgressService(), SearchEngine.createWorkspaceScope(),
                        scopeType, false, filter);
                dialog.setTitle(Messages.DSFileWizardPage_selectType);
                if (dialog.open() == Window.OK) {
                    IType type = (IType) dialog.getResult()[0];
                    entry.setText(type.getFullyQualifiedName('$'));
                }
            } catch (CoreException e) {
                Activator.logException(e);
            }
        }
    });
}

From source file:org.eclipse.pde.internal.ui.editor.schema.SchemaJavaAttributeDetails.java

License:Open Source License

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

From source file:org.eclipse.rap.ui.internal.launch.rwt.tab.EntryPointTypeSelectionDialog.java

License:Open Source License

private SelectionDialog createDialog() {
    IRunnableContext context = PlatformUI.getWorkbench().getProgressService();
    IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
    int style = IJavaElementSearchConstants.CONSIDER_CLASSES;
    String filter = "";
    try {/*  ww  w. ja  va 2 s.  co m*/
        return JavaUI.createTypeDialog(parent, context, scope, style, false, filter, null);
    } catch (JavaModelException jme) {
        throw new RuntimeException("Failed to open JavaElement selection dialog.", jme);
    }
}

From source file:org.eclipse.recommenders.rcp.JavaElementResolver.java

License:Open Source License

private Optional<IType> resolveType(final ITypeName recType) {
    // TODO woah, what a hack just to find a nested/anonymous type... this
    // definitely needs refactoring!
    ensureIsNotNull(recType);/*ww w . j a va  2  s.c  o m*/
    if (recType.isArrayType()) {
        // TODO see https://bugs.eclipse.org/bugs/show_bug.cgi?id=339806
        // should throw an exception? or return an Array type?
        log(ERROR_ARRAY_TYPE_IN_JAVA_ELEMENT_RESOLVER, recType);
        return absent();
    }

    if (recType.isNestedType()) {
        final ITypeName declaringType = recType.getDeclaringType();
        final String simpleName = StringUtils.substringAfterLast(recType.getIdentifier(), "$"); //$NON-NLS-1$

        final IType parent = resolveType(declaringType).orNull();
        if (parent != null) {
            try {
                for (final IType nested : parent.getTypes()) {
                    final String key = nested.getKey();
                    if (key.equals(recType.getIdentifier() + ';')) {
                        return fromNullable(nested);
                    }
                }

                for (final IMethod m : parent.getMethods()) {
                    for (final IJavaElement children : m.getChildren()) {
                        if (children instanceof IType) {
                            final IType nested = (IType) children;
                            if (nested.getKey().endsWith(simpleName + ';')) {
                                return of(nested);
                            }

                            final String key = nested.getKey();
                            if (key.equals(recType.getIdentifier() + ';')) {
                                return fromNullable(nested);
                            }
                        }
                    }
                }
            } catch (final Exception x) {
                return absent();
            }
        }
        return absent();
    }
    final IType[] res = new IType[1];
    final IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
    final SearchEngine search = new SearchEngine();
    final String srcTypeName = Names.vm2srcTypeName(recType.getIdentifier());
    final SearchPattern pattern = SearchPattern.createPattern(srcTypeName, IJavaSearchConstants.TYPE,
            IJavaSearchConstants.DECLARATIONS, SearchPattern.R_FULL_MATCH);
    try {
        search.search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, new SearchRequestor() {

            @Override
            public void acceptSearchMatch(final SearchMatch match) throws CoreException {
                IType element = (IType) match.getElement();
                // with the current settings the engine matches 'Lnull' with 'Ljava/lang/ref/ReferenceQueue$Null'
                if (toRecType(element).equals(recType)) {
                    res[0] = element;
                }
            }
        }, null);
    } catch (final CoreException e) {
        throwUnhandledException(e);
    }
    return fromNullable(res[0]);
}

From source file:org.eclipse.recommenders.utils.rcp.JavaElementResolver.java

License:Open Source License

private Optional<IType> resolveType(final ITypeName recType) {
    // TODO woah, what a hack just to find a nested/anonymous type... this
    // definitely needs refactoring!
    ensureIsNotNull(recType);//from ww  w.  java  2  s. c om
    if (recType.isArrayType()) {
        // TODO see https://bugs.eclipse.org/bugs/show_bug.cgi?id=339806
        // should throw an exception? or return an Array type?
        System.err.println("array type in JavaElementResolver. Decision  bug 339806 pending...?");
        return absent();
    }

    if (recType.isNestedType()) {
        final ITypeName declaringType = recType.getDeclaringType();
        final String simpleName = StringUtils.substringAfterLast(recType.getIdentifier(), "$");

        final IType parent = resolveType(declaringType).orNull();
        if (parent != null) {
            try {
                for (final IType nested : parent.getTypes()) {
                    final String key = nested.getKey();
                    if (key.equals(recType.getIdentifier() + ";")) {
                        return fromNullable(nested);
                    }
                }
                // int count = 0;
                for (final IMethod m : parent.getMethods()) {
                    for (final IJavaElement children : m.getChildren()) {
                        if (children instanceof IType) {
                            final IType nested = (IType) children;
                            // count++;
                            if (nested.getKey().endsWith(simpleName + ";")) {
                                return of(nested);
                            }
                            // if (String.valueOf(count).equals(simpleName)) {
                            // return of(nested);
                            // }

                            final String key = nested.getKey();
                            if (key.equals(recType.getIdentifier() + ";")) {
                                return fromNullable(nested);
                            }
                        }
                    }
                }
            } catch (final Exception x) {
                // final IType type =
                // parent.getType(recType.getClassName());
                return absent();
            }
        }
        return absent();
    }
    final IType[] res = new IType[1];
    final IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
    final SearchEngine search = new SearchEngine();
    final String srcTypeName = Names.vm2srcTypeName(recType.getIdentifier());
    final SearchPattern pattern = SearchPattern.createPattern(srcTypeName, IJavaSearchConstants.TYPE,
            IJavaSearchConstants.DECLARATIONS, SearchPattern.R_FULL_MATCH);
    try {
        search.search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, new SearchRequestor() {

            @Override
            public void acceptSearchMatch(final SearchMatch match) throws CoreException {
                IType element = (IType) match.getElement();
                // with the current settings the engine matches 'Lnull' with 'Ljava/lang/ref/ReferenceQueue$Null'
                if (toRecType(element).equals(recType)) {
                    res[0] = element;
                }
            }
        }, null);
    } catch (final CoreException e) {
        throwUnhandledException(e);
    }
    return fromNullable(res[0]);
}

From source file:org.eclipse.stardust.modeling.validation.util.TypeFinder.java

License:Open Source License

public TypeFinder(IJavaProject project) {
    this.project = project;
    scope = project == null ? SearchEngine.createWorkspaceScope()
            : SearchEngine.createJavaSearchScope(new IJavaElement[] { project });
}

From source file:org.eclipse.viatra.query.tooling.ui.queryregistry.handlers.ShowPatternLocationHandler.java

License:Open Source License

protected void showPatternLocation(ExecutionEvent event, IQuerySpecificationProvider provider)
        throws ExecutionException {
    if (provider instanceof IPatternBasedSpecificationProvider) {
        IPatternBasedSpecificationProvider patternBasedProvider = (IPatternBasedSpecificationProvider) provider;
        uriOpener.open(patternBasedProvider.getSpecificationSourceURI(), true);
    } else {/*from   w ww .jav a  2 s .  com*/
        List<String> list = Lists.newArrayList(Splitter.on(".").split(provider.getFullyQualifiedName()));
        Pattern p = PatternLanguageFactory.eINSTANCE.createPattern();
        p.setName(list.get(list.size() - 1));
        list.set(list.size() - 1, new EMFPatternLanguageJvmModelInferrerUtil().matcherClassName(p));

        String fqn = Joiner.on(".").join(list);
        SearchPattern pattern = SearchPattern.createPattern(fqn, IJavaSearchConstants.CLASS,
                IJavaSearchConstants.ALL_OCCURRENCES, SearchPattern.R_EXACT_MATCH);
        IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
        LocationSearchRequestor requestor = new LocationSearchRequestor();

        try {
            new SearchEngine().search(pattern,
                    new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor,
                    new NullProgressMonitor());
            if (!requestor.opened) {
                MessageDialog.openWarning(HandlerUtil.getActiveShellChecked(event), "Show Location",
                        String.format("Cannot open event source. Is contributing project %s indexed by JDT?",
                                provider.getSourceProjectName()));
            }
        } catch (CoreException e) {
            throw new ExecutionException("Error while opening editor", e);
        }

    }
}

From source file:org.eclipse.viatra.transformation.debug.ui.launch.TransformationRemoteDebugTab.java

License:Open Source License

/**
 * @wbp.parser.entryPoint//from  w  w w.j a  va  2s.  c  o m
 */
@Override
public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    setControl(composite);
    composite.setLayout(new GridLayout(1, false));

    Group grpPort = new Group(composite, SWT.NONE);
    grpPort.setText("Target Port");
    grpPort.setLayout(new GridLayout(2, false));
    grpPort.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1));

    portText = new Text(grpPort, SWT.BORDER);
    portText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    final ControlDecoration portNumberDecorator = new ControlDecoration(portText, SWT.TOP | SWT.RIGHT);
    FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
    Image img = fieldDecoration.getImage();
    portNumberDecorator.setImage(img);
    portNumberDecorator.hide();
    portText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            try {
                Integer.parseInt(portText.getText());
                portID = portText.getText();
                portNumberDecorator.hide();

                setErrorMessage(null);
                getLaunchConfigurationDialog().updateMessage();
                getLaunchConfigurationDialog().updateButtons();
            } catch (NumberFormatException e2) {
                portNumberDecorator.setDescriptionText(portText.getText() + " is not a valid port number.");
                portNumberDecorator.show();

                setErrorMessage(portText.getText() + " is not a valid port number.");
                getLaunchConfigurationDialog().updateMessage();

                ViatraQueryLoggingUtil.getDefaultLogger().error(e2.getMessage(), e2);
            }
        }
    });

    Button btnPortQuery = new Button(grpPort, SWT.NONE);
    btnPortQuery.setText("Query Port");
    Group grpTargetTransformation = new Group(composite, SWT.NONE);
    grpTargetTransformation.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
    grpTargetTransformation.setText("Target VIATRA Transformation");
    grpTargetTransformation.setLayout(new GridLayout(1, false));

    comboViewer = new ComboViewer(grpTargetTransformation, SWT.READ_ONLY);
    Combo combo = comboViewer.getCombo();
    combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    comboViewer.setContentProvider(ArrayContentProvider.getInstance());
    comboViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return element.toString();
        }
    });
    comboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            selectedID = ((String) ((StructuredSelection) comboViewer.getSelection()).getFirstElement());
            if (!selectedID.contains(CURRENTVERSION)) {
                setErrorMessage(selectedID + " does not match the current version VIATRA version");
                getLaunchConfigurationDialog().updateMessage();
            } else {
                setErrorMessage(null);
                getLaunchConfigurationDialog().updateMessage();
            }
            getLaunchConfigurationDialog().updateButtons();
        }
    });

    Group transformationTypeGrp = new Group(composite, SWT.NONE);
    transformationTypeGrp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    transformationTypeGrp.setLayout(new GridLayout(2, false));
    transformationTypeGrp.setText("VIATRA Transformation Class");

    transformationTypeText = new Text(transformationTypeGrp, SWT.BORDER | SWT.READ_ONLY);
    transformationTypeText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    transformationTypeText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            typeName = transformationTypeText.getText();
            getLaunchConfigurationDialog().updateButtons();
        }
    });

    Button btnSearchButton = new Button(transformationTypeGrp, SWT.NONE);
    btnSearchButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            handleSearchButtonSelected();
        }

        private void handleSearchButtonSelected() {
            try {
                SelectionDialog dialog = JavaUI.createTypeDialog(JDIDebugUIPlugin.getActiveWorkbenchShell(),
                        JDIDebugUIPlugin.getActiveWorkbenchWindow(), SearchEngine.createWorkspaceScope(),
                        IJavaElementSearchConstants.CONSIDER_CLASSES, false);
                dialog.setTitle("Select Transformation Class");
                dialog.create();
                if (dialog.open() == Window.CANCEL) {
                    return;
                }
                Object[] results = dialog.getResult();
                IType type = (IType) results[0];
                if (type != null) {
                    transformationTypeText.setText(type.getFullyQualifiedName());
                    typeName = type.getFullyQualifiedName();
                    projectName = type.getJavaProject().getElementName();

                    getLaunchConfigurationDialog().updateButtons();
                }
            } catch (JavaModelException e) {
                TransformationDebugUIActivator.getDefault().logException(
                        "An error occured during the creation of the VIATRA debugger wizard tab", e);
            }

        }
    });
    btnSearchButton.setText("Search");

    btnPortQuery.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            List<String> filteredNames = Lists.newArrayList();

            try {
                Integer.parseInt(portText.getText());
                portID = portText.getText();

                JMXServiceURL url = new JMXServiceURL(
                        "service:jmx:rmi:///jndi/rmi://localhost:" + portID + "/jmxrmi");
                try (JMXConnector jmxc = JMXConnectorFactory.connect(url, null)) {
                    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
                    List<ObjectName> queryNames = Lists.newArrayList(mbsc.queryNames(null, null));
                    for (ObjectName objectName : queryNames) {
                        if (objectName.toString().contains(MBEANNAME)) {
                            filteredNames.add(objectName.toString());
                        }
                    }
                }

                if (!filteredNames.isEmpty()) {
                    comboViewer.setInput(filteredNames);
                    comboViewer.setSelection(new StructuredSelection(filteredNames.get(0)));
                    selectedID = filteredNames.get(0).toString();
                    portNumberDecorator.hide();

                    setErrorMessage(null);
                    getLaunchConfigurationDialog().updateMessage();
                    getLaunchConfigurationDialog().updateButtons();
                }
                getLaunchConfigurationDialog().updateButtons();
            } catch (NumberFormatException | IOException e2) {
                ViatraQueryLoggingUtil.getDefaultLogger().error(e2.getMessage(), e2);
                portNumberDecorator.setDescriptionText(NOAGENTS + portText.getText());
                filteredNames.add(NOAGENTS + portText.getText());
                comboViewer.setInput(filteredNames);
                comboViewer.setSelection(new StructuredSelection(filteredNames.get(0)));
                selectedID = filteredNames.get(0).toString();

                setErrorMessage(NOAGENTS + portText.getText());
                getLaunchConfigurationDialog().updateMessage();

                portNumberDecorator.show();

            }
        }
    });

}

From source file:org.eclipse.viatra.transformation.debug.ui.views.transformationbrowser.AdaptableEVMDoubleClickListener.java

License:Open Source License

@Override
public void doubleClick(DoubleClickEvent event) {
    ISelection selection = event.getSelection();
    if (selection instanceof IStructuredSelection) {
        Object firstElement = ((IStructuredSelection) selection).getFirstElement();
        if (firstElement instanceof AdaptableEVM
                && view.getTransformationStateMap().get(firstElement) == null) {
            AdaptableEVM vm = (AdaptableEVM) firstElement;
            String fullyQualifiedName = "";
            String projectName = "";

            ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
            ILaunchConfigurationType launchConfigurationType = manager.getLaunchConfigurationType(
                    "org.eclipse.viatra.transformation.debug.launchViatraTransformation");
            try {
                SelectionDialog dialog = JavaUI.createTypeDialog(JDIDebugUIPlugin.getActiveWorkbenchShell(),
                        JDIDebugUIPlugin.getActiveWorkbenchWindow(), SearchEngine.createWorkspaceScope(),
                        IJavaElementSearchConstants.CONSIDER_CLASSES, false);
                dialog.setTitle("Select Transformation Class");
                dialog.create();//from w  w w  . j av  a 2 s  .c  o m
                if (dialog.open() == Window.CANCEL) {
                    return;

                }
                Object[] results = dialog.getResult();
                IType type = (IType) results[0];
                if (type != null) {
                    fullyQualifiedName = type.getFullyQualifiedName();
                    projectName = type.getJavaProject().getElementName();
                }

                ILaunchConfigurationWorkingCopy workingCopy = launchConfigurationType.newInstance(null,
                        vm.getIdentifier());

                workingCopy.setAttribute(TransformationLaunchConfigurationDelegate.ADAPTABLE_EVM_ATTR,
                        vm.getIdentifier());
                workingCopy.setAttribute(TransformationLaunchConfigurationDelegate.TRANSFORMATION_ATTR,
                        fullyQualifiedName);
                workingCopy.setAttribute(TransformationLaunchConfigurationDelegate.PROJECT_NAME, projectName);

                DebugUITools.launch(workingCopy, "debug");

                TransformationThreadFactory.getInstance().registerListener(view, vm.getIdentifier());

            } catch (CoreException e) {
                e.printStackTrace();
            }

        }
    }

}

From source file:org.eclipse.wb.internal.core.nls.bundle.eclipse.AbstractAccessorSourceNewComposite.java

License:Open Source License

protected final void createAccessorGroup() {
    Group accessorGroup = new Group(this, SWT.NONE);
    GridDataFactory.create(accessorGroup).grabH().fillH();
    GridLayoutFactory.create(accessorGroup).columns(3);
    accessorGroup.setText(Messages.AbstractAccessorSourceNewComposite_accessorGroup);
    // create source folder and package selection field
    {//from   w ww  .  jav  a  2 s.c o  m
        m_accessorPackageField = new PackageRootAndPackageSelectionDialogField(60,
                Messages.AbstractAccessorSourceNewComposite_accessorSourceFolder,
                Messages.AbstractAccessorSourceNewComposite_accessorSourceFolderBrowse,
                Messages.AbstractAccessorSourceNewComposite_accessorPackage,
                Messages.AbstractAccessorSourceNewComposite_accessorPackageBrowse);
        m_accessorPackageField.setDialogFieldListener(m_validateListener);
        m_accessorPackageField.doFillIntoGrid(accessorGroup, 3);
    }
    // create class field
    {
        m_accessorClassField = new StringButtonDialogField(new IStringButtonAdapter() {
            public void changeControlPressed(DialogField field) {
                try {
                    // prepare dialog parameters
                    IPackageFragmentRoot sourceFolder = m_accessorPackageField.getRoot();
                    ProgressMonitorDialog context = new ProgressMonitorDialog(DesignerPlugin.getShell());
                    IJavaSearchScope scope = sourceFolder != null
                            ? SearchEngine.createJavaSearchScope(new IJavaElement[] { sourceFolder })
                            : SearchEngine.createWorkspaceScope();
                    // prepare dialog
                    SelectionDialog dialog = JavaUI.createTypeDialog(getShell(), context, scope,
                            IJavaElementSearchConstants.CONSIDER_TYPES, false, "*Messages<");
                    dialog.setTitle(Messages.AbstractAccessorSourceNewComposite_accessorChooseTitle);
                    dialog.setMessage(Messages.AbstractAccessorSourceNewComposite_accessorChooseMessage);
                    // select type
                    if (dialog.open() != Window.OK) {
                        return;
                    }
                    IType type = (IType) dialog.getResult()[0];
                    // update source folder, package and class fields
                    ICompilationUnit compilationUnit = type.getCompilationUnit();
                    m_accessorPackageField.setCompilationUnit(compilationUnit);
                    m_accessorClassField.setText(type.getElementName());
                } catch (Throwable e) {
                    DesignerPlugin.log(e);
                }
            }
        });
        m_accessorClassField.setDialogFieldListener(m_validateListener);
        m_accessorClassField.setLabelText(Messages.AbstractAccessorSourceNewComposite_accessorChooseLabel);
        m_accessorClassField.setButtonLabel(Messages.AbstractAccessorSourceNewComposite_accessorChooseButton);
        createTextFieldControls(accessorGroup, m_accessorClassField, 3);
    }
    // create additional fields
    createAdditionalAccessorFields(accessorGroup);
}