Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBogdan Gheorghe2011-10-27 15:10:52 +0000
committerBogdan Gheorghe2011-10-27 15:10:52 +0000
commit3a409865a82a23745352abe947faed1b9211c187 (patch)
treeefb6e4f3998332aa7d7dd7ec6daab5aab3546257
parent9f28e4622537fdf7819b8a70259274b3f80a8345 (diff)
downloadorg.eclipse.e4.tools-3a409865a82a23745352abe947faed1b9211c187.tar.gz
org.eclipse.e4.tools-3a409865a82a23745352abe947faed1b9211c187.tar.xz
org.eclipse.e4.tools-3a409865a82a23745352abe947faed1b9211c187.zip
Added CSS editor ui improvementsv20111027-1510
-rw-r--r--bundles/org.eclipse.e4.tools.css.editor.ui/META-INF/MANIFEST.MF5
-rw-r--r--bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/CSSUiModule.java16
-rw-r--r--bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/contentassist/CSSProposalProvider.java116
-rw-r--r--bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/labeling/CSSLabelProvider.java64
-rw-r--r--bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/syntaxcoloring/CSSAntlrToAttribute.java14
-rw-r--r--bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/syntaxcoloring/CSSHighlightingConfiguration.java51
-rw-r--r--bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/syntaxcoloring/CSSSemanticHighlightCalculator.java55
7 files changed, 309 insertions, 12 deletions
diff --git a/bundles/org.eclipse.e4.tools.css.editor.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.tools.css.editor.ui/META-INF/MANIFEST.MF
index 893b4a32..afe56dcc 100644
--- a/bundles/org.eclipse.e4.tools.css.editor.ui/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.e4.tools.css.editor.ui/META-INF/MANIFEST.MF
@@ -14,7 +14,10 @@ Require-Bundle: org.eclipse.e4.tools.css.editor;visibility:=reexport,
org.eclipse.xtext.builder,
org.antlr.runtime,
org.eclipse.xtext.common.types.ui,
- org.eclipse.xtext.ui.codetemplates.ui
+ org.eclipse.xtext.ui.codetemplates.ui,
+ org.eclipse.e4.ui.css.core;bundle-version="0.10.0",
+ org.eclipse.e4.ui.css.swt;bundle-version="0.10.0",
+ org.eclipse.e4.ui.css.swt.theme;bundle-version="0.9.1"
Import-Package: org.apache.log4j,
org.apache.commons.logging
Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/CSSUiModule.java b/bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/CSSUiModule.java
index 318a2698..4d629c19 100644
--- a/bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/CSSUiModule.java
+++ b/bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/CSSUiModule.java
@@ -3,7 +3,12 @@
*/
package org.eclipse.e4.ui;
+import org.eclipse.e4.ui.syntaxcoloring.CSSAntlrToAttribute;
+import org.eclipse.e4.ui.syntaxcoloring.CSSHighlightingConfiguration;
+import org.eclipse.e4.ui.syntaxcoloring.CSSSemanticHighlightCalculator;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfiguration;
+import org.eclipse.xtext.ui.editor.syntaxcoloring.ISemanticHighlightingCalculator;
/**
* Use this class to register components to be used within the IDE.
@@ -12,4 +17,15 @@ public class CSSUiModule extends org.eclipse.e4.ui.AbstractCSSUiModule {
public CSSUiModule(AbstractUIPlugin plugin) {
super(plugin);
}
+ public Class<? extends IHighlightingConfiguration> bindILexicalHighlightingConfiguration() {
+ return CSSHighlightingConfiguration.class;
+ }
+
+ public Class<? extends org.eclipse.xtext.ui.editor.syntaxcoloring.AbstractAntlrTokenToAttributeIdMapper> bindAbstractAntlrTokenToAttributeIdMapper() {
+ return CSSAntlrToAttribute.class;
+ }
+
+ public Class<? extends ISemanticHighlightingCalculator> bindSemanticHighlightingCalculator() {
+ return CSSSemanticHighlightCalculator.class;
+ }
}
diff --git a/bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/contentassist/CSSProposalProvider.java b/bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/contentassist/CSSProposalProvider.java
index 30ae690f..f316eb24 100644
--- a/bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/contentassist/CSSProposalProvider.java
+++ b/bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/contentassist/CSSProposalProvider.java
@@ -3,10 +3,122 @@
*/
package org.eclipse.e4.ui.contentassist;
-import org.eclipse.e4.ui.contentassist.AbstractCSSProposalProvider;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+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.cSS.selector;
+import org.eclipse.e4.cSS.impl.RulesImpl;
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.internal.theme.ThemeEngine;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.xtext.RuleCall;
+import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext;
+import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor;
/**
* see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#contentAssist on how to customize content assistant
*/
public class CSSProposalProvider extends AbstractCSSProposalProvider {
-
+
+ String[] completions;
+ boolean init = false;
+ CSSEngine engine;
+
+ void init() {
+ IExtensionRegistry registry = RegistryFactory.getRegistry();
+ IExtensionPoint extPoint = registry
+ .getExtensionPoint("org.eclipse.e4.ui.css.swt.property.handler");
+ 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]);
+ }
+ }
+ }
+ completions = new String[matchingElements.size()];
+ Iterator iter = matchingElements.iterator();
+ int counter = 0;
+ while (iter.hasNext()) {
+ IConfigurationElement type = (IConfigurationElement) iter.next();
+ completions[counter] = type.getAttribute("name");
+ counter++;
+ }
+
+ Object themeEngine = Display.getCurrent().getData("org.eclipse.e4.ui.css.swt.theme");
+ if (themeEngine instanceof ThemeEngine) {
+ engine = ((ThemeEngine) themeEngine).getCSSEngine();
+ }
+// Shell[] shells = Display.getCurrent().getShells();
+// if (shells.length > 0) {
+// //This is from AbstractPartRenderer, should be in IPresentationEngine
+// String OWNING_ME = "modelElement"; //$NON-NLS-1$
+// Object obj = null;
+// for (int i = 0; i < shells.length; i++) {
+// obj = shells[i].getData(OWNING_ME);
+// if (obj != null) break;
+// }
+// if (obj != null && obj instanceof MTrimmedWindow) {
+// MTrimmedWindow context = (MTrimmedWindow) obj;
+// IStylingEngine stylingengine = (IStylingEngine) context.getContext().get(IStylingEngine.SERVICE_NAME);
+// engine = (CSSEngine) stylingengine.getEngine();
+// }
+// }
+// IEclipseContext context = application.getContext();
+// IStylingEngine engine = (IStylingEngine) context
+// .get(IStylingEngine.SERVICE_NAME);
+//
+ init = true;
+// for (IExtension e : extPoint.getExtensions()) {
+// for (IConfigurationElement ce : getPlatformMatches(e
+// .getConfigurationElements())) {
+// if (ce.getName().equals("theme")) {
+ }
+@Override
+public void complete_declaration(EObject model, RuleCall ruleCall,
+ ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
+ if (!init) init();
+// DocumentCSS doc = engine.getDocumentCSS();
+// StyleSheetList sslist = doc.getStyleSheets();
+// for (int i = 0; i < sslist.getLength(); i++) {
+// StyleSheet ss = sslist.item(i);
+// }
+// ViewCSS view = engine.getViewCSS();
+
+ RulesImpl test = (RulesImpl) model;
+ EList<selector> sel = test.getSelectors();
+ String[] calCompletions = null;
+// for (Iterator iterator = sel.iterator(); iterator.hasNext();) {
+// selector selector = (selector) iterator.next();
+// simple_selector selectors = selector.getSimpleselectors();
+// element_name name = selectors.getElement();
+// if (name != null) {
+// //look for element name in provider
+// if (engine instanceof CSSSWTEngineImpl) {
+// calCompletions = ((CSSSWTEngineImpl) engine).retrieveCSSPropertiesForElement(name.getName());
+// }
+// }
+//
+// //if id or classname, look
+//// String elementName = name.getName();
+//// engine.getCSSCompositePropertiesNames(elementName);
+////
+////// ep.getElement(element, engine)
+// }
+ String[] iter = calCompletions == null ? completions : calCompletions;
+ for (int i = 0; i < iter.length; i++) {
+ acceptor.accept(createCompletionProposal(iter[i], context));
+ }
+}
}
diff --git a/bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/labeling/CSSLabelProvider.java b/bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/labeling/CSSLabelProvider.java
index 675c4f21..c7bca8a5 100644
--- a/bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/labeling/CSSLabelProvider.java
+++ b/bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/labeling/CSSLabelProvider.java
@@ -3,6 +3,14 @@
*/
package org.eclipse.e4.ui.labeling;
+import java.util.Iterator;
+
+import org.eclipse.e4.cSS.Rules;
+import org.eclipse.e4.cSS.expr;
+import org.eclipse.e4.cSS.selector;
+import org.eclipse.e4.cSS.stylesheet;
+import org.eclipse.e4.cSS.term;
+import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider;
@@ -20,15 +28,53 @@ public class CSSLabelProvider extends DefaultEObjectLabelProvider {
super(delegate);
}
-/*
- //Labels and icons can be computed like this:
+ public String text(stylesheet ss) {
+ StringBuilder builder = new StringBuilder();
+// builder.append(notNull(ss.getName()));
+ builder.append("StyleSheet : ");
+ builder.append(ss.getLocation());
+ return builder.toString();
+ }
- String text(MyModel ele) {
- return "my "+ele.getName();
+ public String text(Rules r) {
+ StringBuilder builder = new StringBuilder();
+ builder.append("Rules : ");
+ EList<selector> sels = r.getSelectors();
+ Iterator<selector> iter = sels.iterator();
+ while (iter.hasNext()) {
+ selector s = (selector) iter.next();
+ builder.append(s.getSimpleselectors().getElement().getName());
+// st<simple_selector>simple = s.getSimp ELileselectors();
+// Iterator<simple_selector> simple_iter = simple.iterator();
+// while (simple_iter.hasNext()) {
+// builder.append(((simple_selector) simple_iter).getElement().getName());
+// }
+ }
+ return builder.toString();
+ }
+
+ public String text(expr r) {
+ StringBuilder builder = new StringBuilder();
+ builder.append("expr : ");
+ return builder.toString();
+ }
+
+ public String text(selector s) {
+ StringBuilder builder = new StringBuilder();
+ builder.append("selector : ");
+ return builder.toString();
+ }
+
+// public String text(simple_selector s) {
+// StringBuilder builder = new StringBuilder();
+// builder.append("simple selector : ");
+// return builder.toString();
+// }
+
+ public String text(term s) {
+ StringBuilder builder = new StringBuilder();
+ builder.append("term: ");
+ builder.append(s.getName());
+ return builder.toString();
}
-
- String image(MyModel ele) {
- return "MyModel.gif";
- }
-*/
}
diff --git a/bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/syntaxcoloring/CSSAntlrToAttribute.java b/bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/syntaxcoloring/CSSAntlrToAttribute.java
new file mode 100644
index 00000000..32dbba6c
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/syntaxcoloring/CSSAntlrToAttribute.java
@@ -0,0 +1,14 @@
+package org.eclipse.e4.ui.syntaxcoloring;
+
+import org.eclipse.xtext.ui.editor.syntaxcoloring.DefaultAntlrTokenToAttributeIdMapper;
+import org.eclipse.xtext.ui.editor.syntaxcoloring.DefaultHighlightingConfiguration;
+
+public class CSSAntlrToAttribute extends DefaultAntlrTokenToAttributeIdMapper {
+@Override
+protected String calculateId(String tokenName, int tokenType) {
+ if (tokenName.equals("px")) {
+ return DefaultHighlightingConfiguration.KEYWORD_ID;
+ }
+ return super.calculateId(tokenName, tokenType);
+}
+}
diff --git a/bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/syntaxcoloring/CSSHighlightingConfiguration.java b/bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/syntaxcoloring/CSSHighlightingConfiguration.java
new file mode 100644
index 00000000..ce87741b
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/syntaxcoloring/CSSHighlightingConfiguration.java
@@ -0,0 +1,51 @@
+package org.eclipse.e4.ui.syntaxcoloring;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.xtext.ui.editor.syntaxcoloring.DefaultHighlightingConfiguration;
+import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfigurationAcceptor;
+import org.eclipse.xtext.ui.editor.utils.TextStyle;
+
+public class CSSHighlightingConfiguration extends
+ DefaultHighlightingConfiguration {
+
+ public final static String CSS_Element = "Element";
+ public final static String CSS_ClassID = "ClassID";
+ public final static String CSS_Declaration = "Declaration";
+
+ @Override
+ public void configure(IHighlightingConfigurationAcceptor acceptor) {
+ // TODO Auto-generated method stub
+ super.configure(acceptor);
+ acceptor.acceptDefaultHighlighting(CSS_Element, "Element", elementStyle());
+ acceptor.acceptDefaultHighlighting(CSS_ClassID, "Class ID", classIDStyle());
+ acceptor.acceptDefaultHighlighting(CSS_Declaration, "Declaration", declarationStyle());
+ }
+ @Override
+ public TextStyle numberTextStyle() {
+ TextStyle textStyle = new TextStyle();
+ textStyle.setColor(new RGB(251, 81, 4));
+ textStyle.setStyle(SWT.ITALIC);
+ return textStyle;
+ }
+
+ public TextStyle elementStyle() {
+ TextStyle textStyle = new TextStyle();
+ textStyle.setColor(new RGB(127, 0, 85));
+ textStyle.setStyle(SWT.ITALIC);
+ return textStyle;
+ }
+
+ public TextStyle classIDStyle() {
+ TextStyle textStyle = new TextStyle();
+ textStyle.setColor(new RGB(35, 177, 76));
+ textStyle.setStyle(SWT.ITALIC);
+ return textStyle;
+ }
+
+ public TextStyle declarationStyle() {
+ TextStyle textStyle = new TextStyle();
+ textStyle.setColor(new RGB(92, 0, 255));
+ return textStyle;
+ }
+}
diff --git a/bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/syntaxcoloring/CSSSemanticHighlightCalculator.java b/bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/syntaxcoloring/CSSSemanticHighlightCalculator.java
new file mode 100644
index 00000000..07c6c438
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.css.editor.ui/src/org/eclipse/e4/ui/syntaxcoloring/CSSSemanticHighlightCalculator.java
@@ -0,0 +1,55 @@
+package org.eclipse.e4.ui.syntaxcoloring;
+
+import java.util.Iterator;
+
+import org.eclipse.e4.cSS.Rules;
+import org.eclipse.e4.cSS.simple_selector;
+import org.eclipse.e4.cSS.impl.stylesheetImpl;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.xtext.impl.RuleCallImpl;
+import org.eclipse.xtext.nodemodel.INode;
+import org.eclipse.xtext.resource.XtextResource;
+import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightedPositionAcceptor;
+import org.eclipse.xtext.ui.editor.syntaxcoloring.ISemanticHighlightingCalculator;
+
+public class CSSSemanticHighlightCalculator implements
+ ISemanticHighlightingCalculator {
+
+ public void provideHighlightingFor(XtextResource resource,
+ IHighlightedPositionAcceptor acceptor) {
+ if (resource.getContents().size() > 0) {
+ EObject obj = resource.getContents().get(0);
+// List<Rules> list = EcoreUtil2.typeSelect(obj.eContents(), Rules.class);
+// for (Iterator iterator = list.iterator(); iterator.hasNext();) {
+// Rules rules = (Rules) iterator.next();
+// }
+ Iterator<INode> allNodes = resource.getParseResult().getRootNode().getAsTreeIterable().iterator();
+ while(allNodes.hasNext()) {
+ INode node = allNodes.next();
+ EObject eoj = node.getGrammarElement();
+ if (eoj instanceof RuleCallImpl) {
+
+ if (((RuleCallImpl) eoj).getRule().getName().equals("element_name")) {
+// node.getGrammarElement()
+ acceptor.addPosition(node.getOffset(), node.getLength(), CSSHighlightingConfiguration.CSS_Element);
+ } else if (((RuleCallImpl) eoj).getRule().getName().equals("css_hash_class")) {
+// node.getGrammarElement()
+ acceptor.addPosition(node.getOffset(), node.getLength(), CSSHighlightingConfiguration.CSS_ClassID);
+ } else if (((RuleCallImpl) eoj).getRule().getName().equals("ident")) {
+// node.getGrammarElement()
+// acceptor.addPosition(node.getOffset(), node.getLength(), CSSHighlightingConfiguration.CSS_Declaration);
+ }
+ }
+ }
+
+// Object m = resource.getContents().get(0);
+// if (m instanceof stylesheetImpl) {
+// stylesheetImpl ss = (stylesheetImpl) m;
+// EList<Rules> r = ss.getRuleset();
+// }
+
+ }
+ }
+
+}

Back to the top