package eu.scasefp7.eclipse.core.builder;

import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.Platform;

/**
 * Utility methods for project handling.
 * 
 * @author Marin Orlic
 */
public class ProjectUtils 
{
    /**
	 * Returns the project that the selected resource(s) belong to.
	 * 
	 * @param selectionList the selected resource(s).
	 * @return the project that the selected resource(s) belong to.
	 */
	public static IProject getProjectOfSelectionList(List<Object> selectionList) {
		IProject project = null;
		for (Object object : selectionList) {
			IProject theproject = getProjectOfSelectionElement(object);
			if (theproject != null) {
				if (project == null) {
					project = theproject;
				} else {
					if (!project.equals(theproject)) {
						return null;
					}
				}
			}
		}
		return project;
	}

    /**
     * Returns the project that the selected resource belongs to.
     * 
     * @param element the selected resource.
     * @return the project that the selected resources belong to.
     */
    public static IProject getProjectOfSelectionElement(Object element) {
        IProject project = null;
        IResource resource = (IResource) Platform.getAdapterManager().getAdapter(element, IResource.class);
        if (resource != null) {
            project = resource.getProject();
        } else {
            project = (IProject) Platform.getAdapterManager().getAdapter(element, IProject.class);
        }
        return project;
    }
}


@@ -148,59 +148,260 @@
 es.I
-Resource;%0D%0Aimport org.eclipse.core.runtime.Platform
+ProjectDescription;%0D%0Aimport org.eclipse.core.resources.IResource;%0D%0Aimport org.eclipse.core.runtime.CoreException;%0D%0Aimport org.eclipse.core.runtime.IProgressMonitor;%0D%0Aimport org.eclipse.core.runtime.Platform;%0D%0A%0D%0Aimport eu.scasefp7.eclipse.core.Activator
 ;%0D%0A%0D
@@ -1809,13 +1809,909 @@
 %0A    %7D%0D%0A
+    %0D%0A    /**%0D%0A     * Adds the S-CASE nature to the project.%0D%0A     * %0D%0A     * @param project to add the nature to%0D%0A     * @param monitor progress monitor%0D%0A     * @throws CoreException%0D%0A     */%0D%0A    public static void addNature(IProject project, IProgressMonitor monitor) throws CoreException %7B%0D%0A        try %7B%0D%0A            IProjectDescription description = project.getDescription();%0D%0A            String%5B%5D natures = description.getNatureIds();%0D%0A            String%5B%5D newNatures = new String%5Bnatures.length + 1%5D;%0D%0A            System.arraycopy(natures, 0, newNatures, 0, natures.length);%0D%0A            newNatures%5Bnatures.length%5D = ScaseNature.NATURE_ID;%0D%0A            description.setNatureIds(newNatures);%0D%0A            project.setDescription(description, monitor);%0D%0A        %7D catch (CoreException e) %7B%0D%0A            Activator.log(%22Unable to add S-CASE project nature to project.%22, e);%0D%0A        %7D%0D%0A    %7D%0D%0A
 %7D%0D%0A%0D%0A

Add utility method to add nature to project