Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 56c621453e068e2daee0937a254285d6e974e846 (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
/*****************************************************************************
 * Copyright (c) 2016 Christian W. Damus and others.
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Christian W. Damus - Initial API and implementation
 *   
 *****************************************************************************/

package org.eclipse.papyrus.infra.gmfdiag.css.service;

import java.util.function.Predicate;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.gmfdiag.css.Activator;
import org.eclipse.papyrus.infra.gmfdiag.css.spi.IStylingProvider;
import org.eclipse.papyrus.infra.tools.util.CompositeServiceTracker;
import org.osgi.framework.BundleContext;

/**
 * The notation view styling service. It delegates to registered
 * OSGi service implementations of the {@link IStylingProvider} protocol.
 * 
 */
public class StylingService implements IStylingProvider {

	private final CompositeServiceTracker<IStylingProvider> tracker;

	public StylingService(BundleContext context) {
		super();

		tracker = new CompositeServiceTracker<>(context,
				IStylingProvider.class,
				IStylingProvider.NONE,
				IStylingProvider::compose);
		tracker.open();
	}

	/**
	 * Obtains the Styling Service that delegates to registered providers.
	 * 
	 * @return the Styling Service
	 */
	public static StylingService getInstance() {
		return Activator.getDefault().getStylingService();
	}

	public void dispose() {
		tracker.close();
	}

	@Override
	public void resetStyle(View view) {
		tracker.getService().resetStyle(view);
	}

	@Override
	public Iterable<EClass> getSupportedSemanticClasses() {
		return tracker.getService().getSupportedSemanticClasses();
	}

	@Override
	public Predicate<EStructuralFeature> getSemanticPropertySupportedPredicate() {
		return tracker.getService().getSemanticPropertySupportedPredicate();
	}
}

Back to the top