Example usage for org.eclipse.jdt.core IJavaElement JAVA_MODEL

List of usage examples for org.eclipse.jdt.core IJavaElement JAVA_MODEL

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaElement JAVA_MODEL.

Prototype

int JAVA_MODEL

To view the source code for org.eclipse.jdt.core IJavaElement JAVA_MODEL.

Click Source Link

Document

Constant representing a Java model (workspace level object).

Usage

From source file:org.xulux.eclipse.wizards.NewDictionaryWizardPage.java

License:Apache License

/**
 * Uses the standard container selection dialog to
 * choose the new value for the container field.
 */// w  w w.j a va2 s  . c om

private void handleClassBrowse() {
    IJavaElement element = null;
    IWorkbenchPart part = JavaPlugin.getActivePage().getActivePart();
    System.out.println("part : " + part);
    if (part instanceof IViewPartInputProvider) {
        Object elem = ((IViewPartInputProvider) part).getViewPartInput();
        if (elem instanceof IJavaElement) {
            System.out.println("java element " + (IJavaElement) elem);
            element = (IJavaElement) elem;
        }
    }
    if (element.getElementType() == IJavaElement.JAVA_MODEL) {
        try {
            IJavaProject[] projects = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot())
                    .getJavaProjects();
            if (projects.length == 1) {
                element = projects[0];
            }
        } catch (JavaModelException e) {
            e.printStackTrace();
        }
    }
    IJavaElement[] elements = new IJavaElement[] { element };
    IJavaSearchScope scope = SearchEngine.createJavaSearchScope(elements);

    TypeSelectionDialog dialog = new TypeSelectionDialog(getShell(), getWizard().getContainer(),
            IJavaSearchConstants.TYPE, scope);
    dialog.setTitle("Select Dictionary Base Class");
    dialog.setMessage("Selet a base class to be used as the base of the dictionary to be created");

    if (dialog.open() == Window.OK) {
        System.out.println("Selected type : " + ((IType) dialog.getFirstResult()).getFullyQualifiedName());
        baseClassText.setText(((IType) dialog.getFirstResult()).getFullyQualifiedName());
    }
}