Skip to main content
summaryrefslogtreecommitdiffstats
blob: 911231ba570a288d3d57cb3d6c93c9c6c34cff63 (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
package org.eclipse.fx.code.editor.configuration.text.internal;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.e4.core.contexts.ContextFunction;
import org.eclipse.e4.core.contexts.IContextFunction;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.fx.code.editor.Input;
import org.eclipse.fx.code.editor.configuration.text.ConfigurationModelProvider;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.component.annotations.ReferencePolicyOption;

@SuppressWarnings("restriction")
@Component(service=IContextFunction.class,property={"service.context.key=org.eclipse.fx.code.editor.configuration.LanguageDe"})
public class ConfigurationModelCF extends ContextFunction {
	private List<ConfigurationModelProvider> providerList = new ArrayList<>();

	@Reference(cardinality=ReferenceCardinality.MULTIPLE,policy=ReferencePolicy.DYNAMIC,policyOption=ReferencePolicyOption.GREEDY)
	public void registerProvider(ConfigurationModelProvider provider) {
		synchronized (providerList) {
			providerList.add(provider);
		}
	}

	public void unregisterProvider(ConfigurationModelProvider provider) {
		synchronized (providerList) {
			providerList.remove(provider);
		}
	}

	@Override
	public Object compute(IEclipseContext context) {
		List<ConfigurationModelProvider> list;

		synchronized (providerList) {
			list = new ArrayList<>(providerList);
		}

		Input<?> input = context.get(Input.class);

		return list.stream()
						.filter( p -> p.applies(input))
						.findFirst()
						.map( p -> p.getModel(input)).orElse(null);
	}
}

Back to the top