/**
 * (c) 2014 by Christian Schenk
 **/
package de.schenk.jrtrace.ui.handler;

import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.ISources;
import org.eclipse.ui.part.WorkbenchPart;

public class EvaluationContextUtil {

	/**
	 * 
	 * @param evaluationContext
	 * @return the currently active part
	 */
	static public WorkbenchPart getPart(Object evaluationContext) {
		IEvaluationContext e = (IEvaluationContext) evaluationContext;
		return (WorkbenchPart) e.getVariable(ISources.ACTIVE_PART_NAME);
	}

	/**
	 * 
	 * @param evaluationContext
	 * @return true, if the selection of this evaluation context is a java
	 *         project
	 */
	static public boolean isJavaProject(Object evaluationContext) {

		IEvaluationContext e = (IEvaluationContext) evaluationContext;
		Object selVar = e.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);
		Object obj = null;
		if (selVar instanceof IStructuredSelection) {
			obj = ((IStructuredSelection) selVar).getFirstElement();
		}

		if (obj == null) {
			return false;
		}

		IJavaProject project = (IJavaProject) Platform.getAdapterManager()
				.getAdapter(obj, IJavaProject.class);
		if (project == null) {
			return false;
		}
		return true;
	}
}

@@ -129,16 +129,107 @@
 ontext;%0A
+import org.eclipse.core.resources.IProject;%0Aimport org.eclipse.core.runtime.CoreException;%0A
 import o
@@ -296,32 +296,70 @@
 e.IJavaProject;%0A
+import org.eclipse.jdt.core.JavaCore;%0A
 import org.eclip
@@ -1309,16 +1309,237 @@
 se;%0A%09%09%7D%0A
+%09%09if (obj instanceof IProject) %7B%0A%09%09%09IProject prj = (IProject) obj;%0A%09%09%09try %7B%0A%09%09%09%09if (prj.getNature(JavaCore.NATURE_ID) != null)%0A%09%09%09%09%09return true;%0A%09%09%09%7D catch (CoreException e1) %7B%0A%09%09%09%09throw new RuntimeException(e1);%0A%09%09%09%7D%0A%09%09%7D
 %0A%09%09IJava

configure JRTracce only visible on Java Perspective.