Example usage for org.eclipse.jdt.internal.core PackageFragment getChildren

List of usage examples for org.eclipse.jdt.internal.core PackageFragment getChildren

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core PackageFragment getChildren.

Prototype

public IJavaElement[] getChildren() throws JavaModelException 

Source Link

Usage

From source file:hydrograph.ui.propertywindow.widgets.utility.FilterOperationClassUtility.java

License:Apache License

/**
 * Open file editor to view java file./* w  w  w  . ja  v  a2  s  . c om*/
 * 
 * @param fileName
 *            the file name
 * @return true, if successful
 */
@SuppressWarnings("restriction")
public boolean openFileEditor(Text filePath, String pathFile) {
    String fullQualifiedClassName = filePath.getText();
    try {
        logger.debug("Searching " + fullQualifiedClassName + " in project's source folder");
        PackageFragment packageFragment = null;
        String[] packages = StringUtils.split(fullQualifiedClassName, ".");
        String className = fullQualifiedClassName;
        String packageStructure = "";
        IFile javaFile = null;
        if (packages.length > 1) {
            className = packages[packages.length - 1];
            packageStructure = StringUtils.replace(fullQualifiedClassName, "." + className, "");
        }
        IFileEditorInput editorInput = (IFileEditorInput) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
                .getActivePage().getActiveEditor().getEditorInput();
        IProject project = editorInput.getFile().getProject();
        IJavaProject iJavaProject = JavaCore.create(project);
        IPackageFragmentRoot packageFragmentRoot = iJavaProject
                .getPackageFragmentRoot(project.getFolder(Constants.ProjectSupport_SRC));
        if (packageFragmentRoot != null) {
            for (IJavaElement iJavaElement : packageFragmentRoot.getChildren()) {
                if (iJavaElement instanceof PackageFragment
                        && StringUtils.equals(iJavaElement.getElementName(), packageStructure)) {
                    packageFragment = (PackageFragment) iJavaElement;
                    break;
                }
            }
        }
        if (packageFragment != null) {
            for (IJavaElement element : packageFragment.getChildren()) {
                if (element instanceof CompilationUnit && StringUtils.equalsIgnoreCase(element.getElementName(),
                        className + Constants.JAVA_EXTENSION)) {
                    javaFile = (IFile) element.getCorrespondingResource();
                    break;
                }
            }
        }
        if (javaFile != null && javaFile.exists()) {
            IFileStore fileStore = EFS.getLocalFileSystem().getStore(javaFile.getLocationURI());
            IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
            IDE.openEditorOnFileStore(page, fileStore);
            return true;
        }
    } catch (Exception e) {
        logger.error("Fail to open file");
        return false;
    }
    return false;

}

From source file:org.eclipse.mylyn.java.ui.DoiViewerFilter.java

License:Open Source License

private boolean acceptPackageFragment(PackageFragment fragment) {
    try {//from  www  . ja  v a 2 s .c o m
        if (fragment.getChildren() == null)
            return false;
        if (fragment.getChildren().length == 0)
            return false;
    } catch (JavaModelException e) {
        ContextCorePlugin.fail(e, "Could not determine if package fragment had children", false);
    }
    return true;
}