* added preferences to control right to execute UI code in scripts

Change-Id: I5a0fe3c3fdaba932ff43f7572a62795102aaa37a
diff --git a/Plugins/core/org.eclipse.ease.ui/src/org/eclipse/ease/ui/preferences/ScriptingPage.java b/Plugins/core/org.eclipse.ease.ui/src/org/eclipse/ease/ui/preferences/ScriptingPage.java
index d0eadae..8b46220 100644
--- a/Plugins/core/org.eclipse.ease.ui/src/org/eclipse/ease/ui/preferences/ScriptingPage.java
+++ b/Plugins/core/org.eclipse.ease.ui/src/org/eclipse/ease/ui/preferences/ScriptingPage.java
@@ -1,38 +1,66 @@
 package org.eclipse.ease.ui.preferences;
 
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.ease.Activator;
 import org.eclipse.jface.preference.PreferencePage;
-import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.osgi.service.prefs.Preferences;
 
 public class ScriptingPage extends PreferencePage implements IWorkbenchPreferencePage {
 
+	private Button btnAllowUIAccess;
+
 	public ScriptingPage() {
-		// TODO Auto-generated constructor stub
-	}
-
-	public ScriptingPage(String title) {
-		super(title);
-		// TODO Auto-generated constructor stub
-	}
-
-	public ScriptingPage(String title, ImageDescriptor image) {
-		super(title, image);
-		// TODO Auto-generated constructor stub
 	}
 
 	@Override
-	public void init(IWorkbench workbench) {
-		// TODO Auto-generated method stub
-
+	public void init(final IWorkbench workbench) {
+		setPreferenceStore(Activator.getDefault().getPreferenceStore());
 	}
 
 	@Override
-	protected Control createContents(Composite parent) {
-		// TODO Auto-generated method stub
-		return null;
+	protected Control createContents(final Composite parent) {
+		Composite container = new Composite(parent, SWT.NONE);
+		container.setLayout(new GridLayout(1, false));
+
+		Group grpSecurisecurty = new Group(container, SWT.NONE);
+		grpSecurisecurty.setLayout(new FillLayout(SWT.HORIZONTAL));
+		grpSecurisecurty.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+		grpSecurisecurty.setText("Security");
+
+		btnAllowUIAccess = new Button(grpSecurisecurty, SWT.CHECK);
+		btnAllowUIAccess.setText("Allow scripts to run code in UI thread");
+
+		performDefaults();
+
+		return container;
 	}
 
+	@Override
+	protected void performDefaults() {
+		Preferences prefs = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID).node(Activator.PREFERENCES_NODE_SCRIPTS);
+
+		boolean allowUIAccess = prefs.getBoolean(Activator.SCRIPTS_ALLOW_UI_ACCESS, Activator.DEFAULT_SCRIPTS_ALLOW_UI_ACCESS);
+		btnAllowUIAccess.setSelection(allowUIAccess);
+
+		super.performDefaults();
+	}
+
+	@Override
+	public boolean performOk() {
+		Preferences prefs = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID).node(Activator.PREFERENCES_NODE_SCRIPTS);
+
+		prefs.putBoolean(Activator.SCRIPTS_ALLOW_UI_ACCESS, btnAllowUIAccess.getSelection());
+
+		return super.performOk();
+	}
 }
diff --git a/Plugins/core/org.eclipse.ease/src/org/eclipse/ease/AbstractScriptEngine.java b/Plugins/core/org.eclipse.ease/src/org/eclipse/ease/AbstractScriptEngine.java
index e1955fb..13c1e83 100644
--- a/Plugins/core/org.eclipse.ease/src/org/eclipse/ease/AbstractScriptEngine.java
+++ b/Plugins/core/org.eclipse.ease/src/org/eclipse/ease/AbstractScriptEngine.java
@@ -22,12 +22,14 @@
 import org.eclipse.core.runtime.ListenerList;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.preferences.InstanceScope;
 import org.eclipse.ease.FileTrace.Trace;
 import org.eclipse.ease.debug.ITracingConstant;
 import org.eclipse.ease.debug.Tracer;
 import org.eclipse.ease.service.EngineDescription;
 import org.eclipse.ease.service.IScriptService;
 import org.eclipse.ui.PlatformUI;
+import org.osgi.service.prefs.Preferences;
 
 /**
  * Base implementation for a script engine. Handles Job implementation of script engine, adding script code for execution, module loading support and a basic
@@ -111,6 +113,11 @@
 
 	@Override
 	public final Object injectUI(final Object content) {
+		Preferences prefs = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID).node(Activator.PREFERENCES_NODE_SCRIPTS);
+		boolean allowUIAccess = prefs.getBoolean(Activator.SCRIPTS_ALLOW_UI_ACCESS, Activator.DEFAULT_SCRIPTS_ALLOW_UI_ACCESS);
+		if (!allowUIAccess)
+			throw new RuntimeException("Script UI access disabled by user preferences.");
+
 		return internalInject(content, true);
 	}
 
@@ -148,7 +155,6 @@
 	 */
 	private ScriptResult inject(final Script script, final boolean notifyListeners, final boolean uiThread) {
 
-		// FIXME make UI access optional by using preferences
 		synchronized (script.getResult()) {
 
 			try {
diff --git a/Plugins/core/org.eclipse.ease/src/org/eclipse/ease/Activator.java b/Plugins/core/org.eclipse.ease/src/org/eclipse/ease/Activator.java
index 1e26a59..e6bf935 100644
--- a/Plugins/core/org.eclipse.ease/src/org/eclipse/ease/Activator.java
+++ b/Plugins/core/org.eclipse.ease/src/org/eclipse/ease/Activator.java
@@ -18,6 +18,11 @@
 
 	public static final String PLUGIN_ID = "org.eclipse.ease";
 
+	public static String PREFERENCES_NODE_SCRIPTS = "scripts";
+
+	public static String SCRIPTS_ALLOW_UI_ACCESS = "scriptUIAccess";
+	public static boolean DEFAULT_SCRIPTS_ALLOW_UI_ACCESS = false;
+
 	private static Activator fInstance;
 
 	public static Activator getDefault() {