Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » LocationManager in Eclipse 4
LocationManager in Eclipse 4 [message #1393307] Thu, 03 July 2014 15:36 Go to next message
Kris Slowinski is currently offline Kris SlowinskiFriend
Messages: 18
Registered: August 2011
Junior Member
I am attempting to use the Compatibility Layer. I need to rewrite the code using LocationManager in Eclipse 3.x application, specifically LocationManager.getInstallLocation(). Was that class refactored or is there another way to get the installation location?

[Updated on: Thu, 03 July 2014 15:36]

Report message to a moderator

Re: LocationManager in Eclipse 4 [message #1396697 is a reply to message #1393307] Tue, 08 July 2014 17:01 Go to previous messageGo to next message
Eclipse UserFriend
See org.eclipse.osgi.service.datalocation.Location, specifically the INSTALL_FILTER. See org.eclipse.core.internal.runtime.Activator's getInstallLocation() for a code snippet for how to use it.

Brian.
Re: LocationManager in Eclipse 4 [message #1397853 is a reply to message #1396697] Thu, 10 July 2014 08:40 Go to previous message
Kris Slowinski is currently offline Kris SlowinskiFriend
Messages: 18
Registered: August 2011
Junior Member
Brian de Alwis wrote on Tue, 08 July 2014 13:01
See org.eclipse.osgi.service.datalocation.Location, specifically the INSTALL_FILTER. See org.eclipse.core.internal.runtime.Activator's getInstallLocation() for a code snippet for how to use it.

Brian.


Using Brian's suggestion the solution can be based on the ServiceTracker as presented in org.eclipse.core.internal.runtime.Activator#getInstallLocation():
public Location getInstallLocation() {
  if (installLocationTracker == null) {
    Filter filter = null;
    try {
      filter = bundleContext.createFilter(Location.INSTALL_FILTER);
    } catch (InvalidSyntaxException e) {
      // should not happen
    }
    installLocationTracker = new ServiceTracker(bundleContext, filter, null);
    installLocationTracker.open();
  }
  return (Location) installLocationTracker.getService();
}


It can also be solved by finding all the services that match the Location.INSTALL_FILTER filter as presented in the snippet below:
public List<Location> getInstallLocation() {
  List<Location> locations = new ArrayList<Location>():
  try {
    final Collection<ServiceReference<Location>> locationServices = context.getServiceReferences(Location.class, Location.INSTALL_FILTER);
    if (locationServices == null || locationServices.isEmpty()) {
      if (logger.isErrorEnabled()) { logger.error("Could not find the installation location - no services available"); }
    } else {
      for (final ServiceReference<Location> locationService : locationServices) {
        final Location location = bundleContext.getService(locationService);
        try {
          if (location != null) {
            locations.add(location);
          }
        } finally {
          bundleContext.ungetService(locationService);
        }
      }
    }
  } catch (final Exception e) {
    if (logger.isErrorEnabled()) { logger.error("Error when trying to find installation location"); }
  }
  return locations;
}


Those code snippets assume that you have an access to the BundleContext (bundleContext) object of the bundle.
Previous Topic:Updating command contributions on handler switch
Next Topic:DnD doesn't work when tab-position of MPartStack is bottom
Goto Forum:
  


Current Time: Tue Mar 19 10:46:27 GMT 2024

Powered by FUDForum. Page generated in 0.02763 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top