Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Schindl2011-03-12 00:42:48 +0000
committerThomas Schindl2011-03-12 00:42:48 +0000
commit1da4e03cb568203749750f885bc49b70d41df40f (patch)
tree5af638c84e4e2aa69ab70e94ad2ddf9d65c63440
parent29c232cf6a4054570599f1f7d87f8b6d06969a2a (diff)
downloadorg.eclipse.e4.tools-1da4e03cb568203749750f885bc49b70d41df40f.tar.gz
org.eclipse.e4.tools-1da4e03cb568203749750f885bc49b70d41df40f.tar.xz
org.eclipse.e4.tools-1da4e03cb568203749750f885bc49b70d41df40f.zip
Bug 339299 - [ModelTooling] Add scripting supportv20110312-8000
-rw-r--r--bundles/org.eclipse.e4.tools.emf.ui.script.js/src/org/eclipse/e4/tools/emf/ui/script/js/JavaScriptSupport.java36
1 files changed, 36 insertions, 0 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.ui.script.js/src/org/eclipse/e4/tools/emf/ui/script/js/JavaScriptSupport.java b/bundles/org.eclipse.e4.tools.emf.ui.script.js/src/org/eclipse/e4/tools/emf/ui/script/js/JavaScriptSupport.java
index aa67d2f8..f8c0a4a2 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui.script.js/src/org/eclipse/e4/tools/emf/ui/script/js/JavaScriptSupport.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui.script.js/src/org/eclipse/e4/tools/emf/ui/script/js/JavaScriptSupport.java
@@ -17,12 +17,16 @@ import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Widget;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
@@ -65,6 +69,38 @@ public class JavaScriptSupport implements IScriptingSupport {
ScriptableObject.putProperty(sc, "mainObject", mainElement);
ScriptableObject.putProperty(sc, "additionalData", additionalData);
+ ScriptableObject.putProperty(sc, "swt", new SWTSupport(Display.getCurrent()));
cx.evaluateString(sc, script, "<cmd>", 1, null);
}
+
+ public static class SWTSupport {
+ private Display d;
+
+ public static SWT SWT = new SWT();
+
+ public SWTSupport(Display d) {
+ this.d = d;
+ }
+
+ public Color newColor(String color) {
+ if( color.startsWith("#") ) {
+ if( color.length() == 7 ) {
+ return new Color(d, new RGB(
+ Integer.parseInt(color.substring(1,3), 16),
+ Integer.parseInt(color.substring(3,5), 16),
+ Integer.parseInt(color.substring(5,7), 16)));
+ } else {
+ return new Color(d, new RGB(
+ Integer.parseInt( color.charAt(1) + "" +color.charAt(1), 16),
+ Integer.parseInt( color.charAt(2) + "" +color.charAt(2), 16),
+ Integer.parseInt( color.charAt(3) + "" +color.charAt(3), 16)));
+ }
+ }
+ return null;
+ }
+
+ public Widget newText(Composite parent, int style) {
+ return new Text(parent, style);
+ }
+ }
}

Back to the top