package org.eclipse.maven.ui;
import java.util.Iterator;
import org.eclipse.core.internal.propertytester.ResourcePropertyTester;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jface.viewers.IStructuredSelection;
@SuppressWarnings("restriction")
public class MavenProjectTester extends ResourcePropertyTester {
@Override
public boolean test(Object receiver, String method, Object[] args,
Object expectedValue) {
boolean result = false;
// We look for a maven project in the current selection
if ( receiver instanceof IStructuredSelection ) {
IProject project = getProject((IStructuredSelection) receiver);
if ( project != null )
if ( project.findMember("pom.xml") != null )
result = true;
}
return result;
}
/**
* We look if there is a project in the current selection
* @param selection - current selection
* @return
*/
@SuppressWarnings("rawtypes")
protected IProject getProject(IStructuredSelection selection) {
IProject project = null;
for ( Iterator it = selection.iterator(); it.hasNext(); ) {
Object obj = it.next();
if ( obj instanceof IProject ) {
project = (IProject) obj;
} else if ( obj instanceof IResource ) {
IResource resource = (IResource) obj;
project = resource.getProject();
} else if ( obj instanceof IJavaElement ) {
project = (IProject) ((IJavaElement)obj).getResource().getProject();
}
if ( project != null )
break;
}
return project;
}
}