View Javadoc
1   package org.argeo.cms.e4.maintenance;
2   
3   import java.util.Collection;
4   
5   import org.apache.commons.logging.Log;
6   import org.apache.commons.logging.LogFactory;
7   import org.argeo.cms.ui.util.CmsUiUtils;
8   import org.eclipse.swt.SWT;
9   import org.eclipse.swt.layout.GridData;
10  import org.eclipse.swt.widgets.Composite;
11  import org.osgi.framework.BundleContext;
12  import org.osgi.framework.FrameworkUtil;
13  import org.osgi.framework.InvalidSyntaxException;
14  import org.osgi.framework.ServiceReference;
15  
16  abstract class AbstractOsgiComposite extends Composite {
17  	private static final long serialVersionUID = -4097415973477517137L;
18  	protected final BundleContext bc = FrameworkUtil.getBundle(getClass()).getBundleContext();
19  	protected final Log log = LogFactory.getLog(getClass());
20  
21  	public AbstractOsgiComposite(Composite parent, int style) {
22  		super(parent, style);
23  		parent.setLayout(CmsUiUtils.noSpaceGridLayout());
24  		setLayout(CmsUiUtils.noSpaceGridLayout());
25  		setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
26  		initUi(style);
27  	}
28  
29  	protected abstract void initUi(int style);
30  
31  	protected <T> T getService(Class<? extends T> clazz) {
32  		return bc.getService(bc.getServiceReference(clazz));
33  	}
34  
35  	protected <T> Collection<ServiceReference<T>> getServiceReferences(Class<T> clazz, String filter) {
36  		try {
37  			return bc.getServiceReferences(clazz, filter);
38  		} catch (InvalidSyntaxException e) {
39  			throw new IllegalArgumentException("Filter " + filter + " is invalid", e);
40  		}
41  	}
42  }