Java Code Examples for org.eclipse.core.resources.IFolder#getProject()

The following examples show how to use org.eclipse.core.resources.IFolder#getProject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CheckCatalogCreator.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
  SubMonitor subMonitor = SubMonitor.convert(monitor, "create new Catalog:" + getProjectInfo().getCatalogName(), 2);

  IFolder outputFolder = (IFolder) getProjectInfo().getPackageFragment().getResource();
  IProject project = outputFolder.getProject();
  IPath path = project.getLocation().makeAbsolute();
  try {
    generatorUtil.generateCheckFile(path, getProjectInfo());
    generatorUtil.generateDefaultQuickfixProvider(path, getProjectInfo());
    project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
  } finally {
    setResult(outputFolder.getFile(getProjectInfo().getCatalogName() + '.' + CheckConstants.FILE_EXTENSION));
    subMonitor.done();
  }
}
 
Example 2
Source File: NavigatorObjViewerFilter.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
	try {
		if (element instanceof IFolder) {
			IFolder folder = (IFolder) element;
			IProject project = folder.getProject();
			
			if (project.hasNature(GoNature.NATURE_ID)) {
				return !folder.getName().equals("_obj");
			}
		}
	} catch (CoreException e) {
		
	}
	
	return true;
}
 
Example 3
Source File: NavigatorPackageViewerFilter.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
	try {
		if (element instanceof IFolder) {
			IFolder folder = (IFolder) element;
			IProject project = folder.getProject();
			
			if (folder.getParent() instanceof IProject && project.hasNature(GoNature.NATURE_ID)) {
				return !(folder.getName().equals("bin") || folder.getName().equals("pkg"));
			}
		}
	} catch (CoreException e) {
		
	}
	
	return true;
}
 
Example 4
Source File: OutputFolderFilter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the result of this filter, when applied to the
 * given element.
 *
 * @param viewer the viewer
 * @param parent the parent
 * @param element the element to test
 * @return <code>true</code> if element should be included
 * @since 3.0
 */
@Override
public boolean select(Viewer viewer, Object parent, Object element) {
	if (element instanceof IFolder) {
		IFolder folder= (IFolder)element;
		IProject proj= folder.getProject();
		try {
			if (!proj.hasNature(JavaCore.NATURE_ID))
				return true;

			IJavaProject jProject= JavaCore.create(folder.getProject());
			if (jProject == null || !jProject.exists())
				return true;

			// Check default output location
			IPath defaultOutputLocation= jProject.getOutputLocation();
			IPath folderPath= folder.getFullPath();
			if (defaultOutputLocation != null && defaultOutputLocation.equals(folderPath))
				return false;

			// Check output location for each class path entry
			IClasspathEntry[] cpEntries= jProject.getRawClasspath();
			for (int i= 0, length= cpEntries.length; i < length; i++) {
				IPath outputLocation= cpEntries[i].getOutputLocation();
				if (outputLocation != null && outputLocation.equals(folderPath))
					return false;
			}
		} catch (CoreException ex) {
			return true;
		}
	}
	return true;
}
 
Example 5
Source File: PythonModelProvider.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Converts elements to the python model -- but only creates it if it's parent is found in the python model
 */
protected boolean convertToPythonElementsUpdateOrRefresh(Set<Object> currentChildren) {
    final Map<PythonNature, Set<String>> natureToSourcePathSet = new HashMap<>();
    LinkedHashSet<Object> convertedChildren = new LinkedHashSet<>();
    for (Iterator<Object> childrenItr = currentChildren.iterator(); childrenItr.hasNext();) {
        Object child = childrenItr.next();

        if (child == null) {
            //only case when a child is removed and another one is not added (null)
            childrenItr.remove();
            continue;
        }

        if (child instanceof IResource && !(child instanceof IWrappedResource)) {
            IResource res = (IResource) child;

            Object resourceInPythonModel = getResourceInPythonModel(res, true);
            if (resourceInPythonModel != null) {
                //if it is in the python model, just go on
                childrenItr.remove();
                convertedChildren.add(resourceInPythonModel);

            } else {
                //now, if it's not but its parent is, go on and create it
                IContainer p = res.getParent();
                if (p == null) {
                    continue;
                }

                Object pythonParent = getResourceInPythonModel(p, true);
                if (pythonParent instanceof IWrappedResource) {
                    IWrappedResource parent = (IWrappedResource) pythonParent;

                    if (res instanceof IProject) {
                        throw new RuntimeException("A project's parent should never be an IWrappedResource!");

                    } else if (res instanceof IFolder) {
                        childrenItr.remove();
                        convertedChildren.add(new PythonFolder(parent, (IFolder) res, parent.getSourceFolder()));

                    } else if (res instanceof IFile) {
                        childrenItr.remove();
                        convertedChildren.add(new PythonFile(parent, (IFile) res, parent.getSourceFolder()));

                    } else if (child instanceof IResource) {
                        childrenItr.remove();
                        convertedChildren.add(new PythonResource(parent, (IResource) child, parent
                                .getSourceFolder()));
                    }

                } else if (res instanceof IFolder) {
                    //ok, still not in the model... could it be a PythonSourceFolder
                    IFolder folder = (IFolder) res;
                    IProject project = folder.getProject();
                    if (project == null) {
                        continue;
                    }
                    PythonNature nature = PythonNature.getPythonNature(project);
                    if (nature == null) {
                        continue;
                    }

                    Set<String> sourcePathSet = this.getSourcePathSet(natureToSourcePathSet, nature);

                    PythonSourceFolder wrapped = tryWrapSourceFolder(p, folder, sourcePathSet);
                    if (wrapped != null) {
                        childrenItr.remove();
                        convertedChildren.add(wrapped);
                    }
                }
            }
        }
    }
    if (!convertedChildren.isEmpty()) {
        currentChildren.addAll(convertedChildren);
        return true;
    }
    return false;

}