Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Webster2013-08-23 16:26:55 -0400
committerPaul Webster2013-08-23 16:26:55 -0400
commit7efae2e3d56bb8b0e744ac4bbd02cfaa4dec4e00 (patch)
treed41d37523585297c883c5c3bb017a254ab59a4fd
parent3a63904a843687c5364b00668c4e4ffd069564af (diff)
downloadorg.eclipse.e4.tools-7efae2e3d56bb8b0e744ac4bbd02cfaa4dec4e00.tar.gz
org.eclipse.e4.tools-7efae2e3d56bb8b0e744ac4bbd02cfaa4dec4e00.tar.xz
org.eclipse.e4.tools-7efae2e3d56bb8b0e744ac4bbd02cfaa4dec4e00.zip
Hook in basic keyword completion from the extension point.
-rw-r--r--bundles/org.eclipse.e4.tools.orion.css.editor/src/org/eclipse/e4/tools/orion/css/editor/views/SampleCSSView.java85
-rw-r--r--bundles/org.eclipse.e4.tools.orion.css.editor/web/css.html38
-rw-r--r--bundles/org.eclipse.e4.tools.orion.css.editor/web/swtContentAssist.js66
3 files changed, 171 insertions, 18 deletions
diff --git a/bundles/org.eclipse.e4.tools.orion.css.editor/src/org/eclipse/e4/tools/orion/css/editor/views/SampleCSSView.java b/bundles/org.eclipse.e4.tools.orion.css.editor/src/org/eclipse/e4/tools/orion/css/editor/views/SampleCSSView.java
index 544d8af3..d4ec3c6d 100644
--- a/bundles/org.eclipse.e4.tools.orion.css.editor/src/org/eclipse/e4/tools/orion/css/editor/views/SampleCSSView.java
+++ b/bundles/org.eclipse.e4.tools.orion.css.editor/src/org/eclipse/e4/tools/orion/css/editor/views/SampleCSSView.java
@@ -6,9 +6,16 @@ import java.io.InputStreamReader;
import java.io.Reader;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.RegistryFactory;
import org.eclipse.e4.tools.orion.css.editor.Activator;
import org.eclipse.e4.ui.css.swt.internal.theme.ThemeEngine;
import org.eclipse.e4.ui.css.swt.theme.ITheme;
@@ -64,33 +71,85 @@ public class SampleCSSView extends ViewPart {
try {
initContent();
final Bundle bundle = Activator.getDefault().getBundle();
- final InputStream in = bundle
- .getEntry("/web/css.html").openStream();
- String cssTemplate = loadFile(in, 1024);
- final String editorCssUrl = FileLocator.toFileURL(bundle.getEntry("/web/built-editor.css")).toExternalForm();
- final String editorJsUrl = FileLocator.toFileURL(bundle.getEntry("/web/built-editor.js")).toExternalForm();
-
- editorHtml = String.format(cssTemplate, editorCssUrl, editorJsUrl, editorContent);
+ final InputStream contentAssistInput = bundle.getEntry(
+ "/web/swtContentAssist.js").openStream();
+ String contentAssistTemplate = loadFile(contentAssistInput, 1024);
+ String keywords = loadKeywords();
+ String contentAssist = String.format(contentAssistTemplate,
+ keywords);
+ final InputStream cssTemplateInput = bundle.getEntry(
+ "/web/css.html").openStream();
+ String cssTemplate = loadFile(cssTemplateInput, 1024);
+ final String editorCssUrl = FileLocator.toFileURL(
+ bundle.getEntry("/web/built-editor.css")).toExternalForm();
+ final String editorJsUrl = FileLocator.toFileURL(
+ bundle.getEntry("/web/built-editor.js")).toExternalForm();
+
+ editorHtml = String.format(cssTemplate, editorCssUrl, editorJsUrl,
+ contentAssist, editorContent);
System.out.println(editorHtml);
} catch (IOException e) {
throw new PartInitException("Failed to load CSS editor", e);
}
}
-
+
+ private String loadKeywords() {
+ StringBuilder buf = new StringBuilder();
+
+ IExtensionRegistry registry = RegistryFactory.getRegistry();
+ IExtensionPoint extPoint = registry
+ .getExtensionPoint("org.eclipse.e4.ui.css.core.propertyHandler");
+ ArrayList<IConfigurationElement> matchingElements = new ArrayList<IConfigurationElement>();
+ ArrayList<IConfigurationElement> controlAdapters = new ArrayList<IConfigurationElement>();
+ for (IExtension e : extPoint.getExtensions()) {
+ IConfigurationElement[] elements = e.getConfigurationElements();
+ for (int i = 0; i < elements.length; i++) {
+ IConfigurationElement element = elements[i];
+ controlAdapters.add(element);
+ IConfigurationElement[] child = element
+ .getChildren("property-name");
+ for (int j = 0; j < child.length; j++) {
+ matchingElements.add(child[j]);
+ }
+ }
+ }
+ Iterator<IConfigurationElement> iter = matchingElements.iterator();
+ boolean once = true;
+ while (iter.hasNext()) {
+ IConfigurationElement type = iter.next();
+ String name = type.getAttribute("name");
+ if (!once) {
+ buf.append(',');
+ buf.append('\n');
+ }
+ buf.append('"');
+ buf.append(name);
+ buf.append('"');
+ once = false;
+ }
+ buf.append('\n');
+
+ return buf.toString();
+ }
+
private void initContent() throws MalformedURLException, IOException {
- IThemeEngine engine = (IThemeEngine) getSite().getService(IThemeEngine.class);
+ IThemeEngine engine = (IThemeEngine) getSite().getService(
+ IThemeEngine.class);
final ITheme theme = engine.getActiveTheme();
- final List<String> sheets = ((ThemeEngine)engine).getStylesheets(theme);
- if (sheets.size()>0) {
+ final List<String> sheets = ((ThemeEngine) engine)
+ .getStylesheets(theme);
+ if (sheets.size() > 0) {
String path = sheets.get(0);
- final InputStream in = FileLocator.toFileURL(new URL(sheets.get(0))).openStream();
+ final InputStream in = FileLocator
+ .toFileURL(new URL(sheets.get(0))).openStream();
editorContent = loadFile(in, 1024);
} else {
editorContent = "/*\n * This is an Orion editor sample.\n */\nfunction() {\n var a = 'hi there!';\n window.console.log(a);\n}";
}
}
- public String loadFile(final InputStream in, final int bufferSize) throws IOException {
+ public String loadFile(final InputStream in, final int bufferSize)
+ throws IOException {
final char[] buffer = new char[bufferSize];
final StringBuilder out = new StringBuilder();
final Reader reader = new InputStreamReader(in, "UTF-8");
diff --git a/bundles/org.eclipse.e4.tools.orion.css.editor/web/css.html b/bundles/org.eclipse.e4.tools.orion.css.editor/web/css.html
index 84555880..716dd05f 100644
--- a/bundles/org.eclipse.e4.tools.orion.css.editor/web/css.html
+++ b/bundles/org.eclipse.e4.tools.orion.css.editor/web/css.html
@@ -1,16 +1,44 @@
<html>
<head>
+<title>Theme CSS editor</title>
+<style>
+#editor {
+ border: 1px solid teal;
+ position: absolute;
+ top: 0px;
+ left: 0px;
+ bottom: 0px;
+ right: 0px;
+ margin: 20px;
+}
+
+pre {
+ margin: 0px;
+}
+</style>
<link rel="stylesheet" type="text/css" href="%s"/>
<script src="%s"></script>
<script>
- require(["orion/editor/edit"], function(edit) {
- window.editor = edit({className: "editor"})[0];
+%s
+</script>
+<script>
+ /*globals require*/
+ require(["orion/editor/edit", "examples/editor/swtContentAssist"], function(edit, mSWTContentAssist) {
+ var editor = edit({
+ lang: "css"
+ });
+ //ADD THE SWT CONTENT ASSIST
+ var contentAssist = editor.getContentAssist ? editor.getContentAssist() : editor._contentAssist;
+ contentAssist.addEventListener("Activating", function() { //$NON-NLS-0$
+ contentAssist.providers.push(new mSWTContentAssist.SWTContentAssistProvider());
+ });
+ window.editor = editor;
+ //----------------
});
</script>
</head>
-<body>
-<h2>Sample CSS Editor</h2>
-<pre id="regulus" class="editor" data-editor-lang="css">
+<body spellcheck="false">
+<pre id="editor" class="editor" data-editor-lang="css">
%s
</pre>
</body>
diff --git a/bundles/org.eclipse.e4.tools.orion.css.editor/web/swtContentAssist.js b/bundles/org.eclipse.e4.tools.orion.css.editor/web/swtContentAssist.js
new file mode 100644
index 00000000..b371f6dd
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.orion.css.editor/web/swtContentAssist.js
@@ -0,0 +1,66 @@
+
+/*global define */
+
+define('examples/editor/swtContentAssist', [ //$NON-NLS-0$
+ 'orion/editor/templates' //$NON-NLS-0$
+], function(mTemplates) {
+
+ var colorValues = {
+ type: "link", //$NON-NLS-0$
+ values: [
+ "COLOR_BLACK", //$NON-NLS-0$
+ "COLOR_INFO_BACKGROUND", //$NON-NLS-0$
+ "black", //$NON-NLS-0$
+ "white", //$NON-NLS-0$
+ "red", //$NON-NLS-0$
+ "green", //$NON-NLS-0$
+ "blue", //$NON-NLS-0$
+ "magenta", //$NON-NLS-0$
+ "yellow", //$NON-NLS-0$
+ "cyan", //$NON-NLS-0$
+ "grey", //$NON-NLS-0$
+ "darkred", //$NON-NLS-0$
+ "darkgreen", //$NON-NLS-0$
+ "darkblue", //$NON-NLS-0$
+ "darkmagenta", //$NON-NLS-0$
+ "darkcyan", //$NON-NLS-0$
+ "darkyellow", //$NON-NLS-0$
+ "darkgray", //$NON-NLS-0$
+ "lightgray" //$NON-NLS-0$
+ ]
+ };
+ function fromJSON(o) {
+ return JSON.stringify(o).replace("}", "\\}"); //$NON-NLS-1$ //$NON-NLS-0$
+ }
+ var templates = [
+ {
+ prefix: "swt-outer-keyline-color", //$NON-NLS-0$
+ description: "ctab folder keyline - keyline color", //$NON-NLS-0$
+ template: "swt-outer-keyline-color: ${color:" + fromJSON(colorValues) + "};" //$NON-NLS-1$ //$NON-NLS-0$
+ },
+ {
+ prefix: "frame-image", //$NON-NLS-0$
+ description: "image - the frame image", //$NON-NLS-0$
+ template: "frame-image: url(\"${uri}\");" //$NON-NLS-0$
+ }
+ ];
+ var keywords = [
+ %s
+ ];
+
+ function SWTContentAssistProvider() {
+ }
+ SWTContentAssistProvider.prototype = new mTemplates.TemplateContentAssist(keywords, templates);
+
+ SWTContentAssistProvider.prototype.getPrefix = function(buffer, offset, context) {
+ var index = offset;
+ while (index && /[A-Za-z\-\@]/.test(buffer.charAt(index - 1))) {
+ index--;
+ }
+ return index ? buffer.substring(index, offset) : "";
+ };
+
+ return {
+ SWTContentAssistProvider: SWTContentAssistProvider
+ };
+}); \ No newline at end of file

Back to the top