blob: 67c6b85b4e8cffff2c1e0dde986ddcf788603816 (
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
|
/*******************************************************************************
* Copyright (c) 2010, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.e4.ui.internal.css.swt;
import org.eclipse.e4.ui.internal.css.swt.definition.IColorAndFontProvider;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;
public class ColorAndFontUtil {
static IColorAndFontProvider colorAndFontProvider = null;
static {
if (FrameworkUtil.getBundle(ColorAndFontUtil.class).getBundleContext() != null) {
ServiceTracker<IColorAndFontProvider, IColorAndFontProvider> colorAndFontProviderTracker = new ServiceTracker<>(
FrameworkUtil.getBundle(ColorAndFontUtil.class).getBundleContext(),
IColorAndFontProvider.class.getName(), null) {
@Override
public IColorAndFontProvider addingService(ServiceReference<IColorAndFontProvider> reference) {
// this is needed so that the unit test can exchange the color and font provider
// with a mocked version
colorAndFontProvider = super.addingService(reference);
return colorAndFontProvider;
}
};
colorAndFontProviderTracker.open();
}
}
/**
* Util method to access the OSGI immediate component IColorAndFontProvider
* defined in the same bundle as we do life in the same bundle we do not track
* its life-cycle (as it is the same as our life-cycle)
*/
public static IColorAndFontProvider getColorAndFontProvider() {
return colorAndFontProvider;
}
}
|