Bug 549731: Display EASE jobs in the Progress view

  EASE engines that terminate after execution will be displayed as user
  jobs.
  Shell engines still run as system jobs as they do not terminate.

Change-Id: I2df6716c8d09c99dcaf985e31b651f5581e25c07
diff --git a/plugins/org.eclipse.ease.ui/src/org/eclipse/ease/ui/view/ScriptShell.java b/plugins/org.eclipse.ease.ui/src/org/eclipse/ease/ui/view/ScriptShell.java
index 0b1e626..46aee5d 100644
--- a/plugins/org.eclipse.ease.ui/src/org/eclipse/ease/ui/view/ScriptShell.java
+++ b/plugins/org.eclipse.ease.ui/src/org/eclipse/ease/ui/view/ScriptShell.java
@@ -482,7 +482,7 @@
 			fScriptEngine.setTerminateOnIdle(false);
 
 			// set view title
-			final String partName = fScriptEngine.getName() + " Script Shell";
+			final String partName = scriptService.getEngineByID(id).getName() + " Script Shell";
 			setPartName(partName);
 
 			// prepare console
diff --git a/plugins/org.eclipse.ease/src/org/eclipse/ease/AbstractReplScriptEngine.java b/plugins/org.eclipse.ease/src/org/eclipse/ease/AbstractReplScriptEngine.java
index 55ae088..de78362 100644
--- a/plugins/org.eclipse.ease/src/org/eclipse/ease/AbstractReplScriptEngine.java
+++ b/plugins/org.eclipse.ease/src/org/eclipse/ease/AbstractReplScriptEngine.java
@@ -16,6 +16,7 @@
 import java.util.Map;
 import java.util.Map.Entry;
 
+import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.ease.debugging.model.EaseDebugLastExecutionResult;
 import org.eclipse.ease.debugging.model.EaseDebugVariable;
 import org.eclipse.ease.debugging.model.EaseDebugVariable.Type;
@@ -44,6 +45,12 @@
 	@Override
 	public final void setTerminateOnIdle(final boolean terminate) {
 		fTerminateOnIdle = terminate;
+
+		// if the engine remains active when IDLE this is likely a shell, therefore hide its job from users
+		if (getState() == Job.NONE)
+			// we can only set this before the engine got started
+			setSystem(!terminate);
+
 		synchronized (this) {
 			notifyAll();
 		}
diff --git a/plugins/org.eclipse.ease/src/org/eclipse/ease/AbstractScriptEngine.java b/plugins/org.eclipse.ease/src/org/eclipse/ease/AbstractScriptEngine.java
index d6e922f..4c6f1b1 100644
--- a/plugins/org.eclipse.ease/src/org/eclipse/ease/AbstractScriptEngine.java
+++ b/plugins/org.eclipse.ease/src/org/eclipse/ease/AbstractScriptEngine.java
@@ -35,6 +35,7 @@
 import org.eclipse.ease.debugging.ScriptStackTrace;
 import org.eclipse.ease.security.ScriptUIAccess;
 import org.eclipse.ease.service.EngineDescription;
+import org.eclipse.ease.tools.ResourceTools;
 
 /**
  * Base implementation for a script engine. Handles Job implementation of script engine, adding script code for execution, module loading support and a basic
@@ -126,10 +127,10 @@
 	 *            name of script engine job
 	 */
 	public AbstractScriptEngine(final String name) {
-		super(name);
+		super("[EASE " + name + " Engine]");
 
-		// make this a system job (not visible to the user)
-		setSystem(true);
+		// by default an engine shall be visible to the user. If the engine
+		setSystem(false);
 	}
 
 	@Override
@@ -199,9 +200,9 @@
 
 	private static String getFilename(Object file) {
 		if (file instanceof IFile) {
-			return ((IFile) file).toString();
+			return ResourceTools.toAbsoluteLocation(file, null);
 		} else if (file instanceof File) {
-			return ((File) file).getAbsolutePath();
+			return ResourceTools.toAbsoluteLocation(file, null);
 		} else {
 			return null;
 		}
@@ -226,6 +227,7 @@
 				Logger.trace(Activator.PLUGIN_ID, TRACE_SCRIPT_ENGINE, "Executing script (" + script.getTitle() + "):", script.getCode());
 				final String filename = getFilename(script.getFile());
 				fStackTrace.add(0, new EaseDebugFrame(script, 0, IScriptDebugFrame.TYPE_FILE, filename));
+				updateJobName(filename);
 
 				// apply security checks
 				final List<ISecurityCheck> securityChecks = fSecurityChecks.get(ActionType.INJECT_CODE);
@@ -272,6 +274,19 @@
 		return script.getResult();
 	}
 
+	/**
+	 * @param filename
+	 */
+	private void updateJobName(String filename) {
+		if (filename != null) {
+			String baseName = getName();
+			if (baseName.contains("]"))
+				baseName = baseName.substring(0, baseName.indexOf(']') + 1);
+
+			setName(baseName + " " + filename);
+		}
+	}
+
 	@Override
 	protected IStatus run(final IProgressMonitor monitor) {
 		fMonitor = monitor;