Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 129578 Details for
Bug 269661
[Contributions] Add ISourceProvider and variable for OSGi services
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Initial implemenation
clipboard.txt (text/plain), 2.34 KB, created by
Philipp Kursawe
on 2009-03-23 06:30:30 EDT
(
hide
)
Description:
Initial implemenation
Filename:
MIME Type:
Creator:
Philipp Kursawe
Created:
2009-03-23 06:30:30 EDT
Size:
2.34 KB
patch
obsolete
>import java.util.ArrayList; >import java.util.HashMap; >import java.util.List; >import java.util.Map; > >import org.eclipse.ui.AbstractSourceProvider; >import org.eclipse.ui.ISources; >import org.eclipse.ui.internal.WorkbenchPlugin; >import org.osgi.framework.AllServiceListener; >import org.osgi.framework.Constants; >import org.osgi.framework.InvalidSyntaxException; >import org.osgi.framework.ServiceEvent; >import org.osgi.framework.ServiceReference; > >@SuppressWarnings("restriction") >public class OSGISourceProvider extends AbstractSourceProvider implements AllServiceListener { > > private static final String SERVICES_NAME = "osgi.services"; //$NON-NLS-1$ > private static final String[] PROVIDED_SOURCE_NAMES = new String[] { > SERVICES_NAME > }; > > public OSGISourceProvider() { > WorkbenchPlugin.getDefault().getBundle().getBundleContext().addServiceListener(this); > } > > public void dispose() { > WorkbenchPlugin plugin = WorkbenchPlugin.getDefault(); > if (plugin != null) { > plugin.getBundle().getBundleContext().removeServiceListener(this); > } > } > > class ServiceReferenceAdapter { > public ServiceReferenceAdapter(ServiceReference reference) { > this.reference = reference; > } > > @Override > public boolean equals(Object obj) { > if (obj instanceof String) { > for (String clazz : ((String[])reference.getProperty(Constants.OBJECTCLASS))) { > if (clazz.equals(obj)) { > return true; > } > } > } > return super.equals(obj); > } > > private final ServiceReference reference; > > }; > > List<ServiceReferenceAdapter> getServiceReferences() { > try { > List<ServiceReferenceAdapter> adapters = new ArrayList<ServiceReferenceAdapter>(); > for (ServiceReference reference : WorkbenchPlugin.getDefault().getBundle().getBundleContext().getServiceReferences(null, null)) { > adapters.add(new ServiceReferenceAdapter(reference)); > } > return adapters; > } catch (InvalidSyntaxException e) { > } > return null; > } > > @SuppressWarnings("unchecked") > public Map getCurrentState() { > Map map = new HashMap(1); > map.put(SERVICES_NAME, getServiceReferences()); > return map; > } > > public String[] getProvidedSourceNames() { > return PROVIDED_SOURCE_NAMES; > } > > public void serviceChanged(ServiceEvent event) { > fireSourceChanged(ISources.ACTIVE_MENU, SERVICES_NAME, getServiceReferences()); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 269661
: 129578