Skip to main content
summaryrefslogtreecommitdiffstats
blob: b5eaf4a930ac5d7970c6e3ddf2145b0d3c8da1a8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* generated by Xtext
*/
package org.eclipse.e4.ui.contentassist;

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.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
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;
	
	void init() {
		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]);
				}
			}
		}
		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++;
		}
		
		// engine = WidgetElement.getEngine(Display.getCurrent());
		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));
	}
}
}

Back to the top