Class ResourceLocator


  • public final class ResourceLocator
    extends java.lang.Object
    This class contains a collection of helper methods for finding JFace resources in bundles.
    Since:
    3.17
    Restriction:
    This class is not intended to be instantiated by clients.
    • Constructor Summary

      Constructors 
      Constructor Description
      ResourceLocator()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Optional<ImageDescriptor> imageDescriptorFromBundle​(java.lang.Class<?> classFromBundle, java.lang.String imageFilePath)
      Returns a new Optional<ImageDescriptor> for an image file located within the specified bundle or Optional.empty().
      static java.util.Optional<ImageDescriptor> imageDescriptorFromBundle​(java.lang.String bundleSymbolicName, java.lang.String imageFilePath)
      Returns a new Optional<ImageDescriptor> for an image file located within the specified bundle or Optional.empty().
      static java.util.Optional<java.net.URL> locate​(java.lang.Class<?> classFromBundle, java.lang.String filePath)
      Returns an Optional<URL> containing the URL for the given path in the given bundle.
      static java.util.Optional<java.net.URL> locate​(java.lang.String bundleSymbolicName, java.lang.String filePath)
      Returns an Optional<URL> containing the URL for the given path in the given bundle.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ResourceLocator

        public ResourceLocator()
    • Method Detail

      • locate

        public static java.util.Optional<java.net.URL> locate​(java.lang.String bundleSymbolicName,
                                                              java.lang.String filePath)
        Returns an Optional<URL> containing the URL for the given path in the given bundle. Returns Optional.empty() if the URL could not be computed or created.
        Parameters:
        bundleSymbolicName - the Bundle symbolic name
        filePath - the path of the resource file in the given bundle, relative to the root of the bundle
        Returns:
        an Optional<URL> or Optional.empty().
        See Also:
        FileLocator.find(URL), ImageDescriptor.createFromURL(URL)
      • locate

        public static java.util.Optional<java.net.URL> locate​(java.lang.Class<?> classFromBundle,
                                                              java.lang.String filePath)
        Returns an Optional<URL> containing the URL for the given path in the given bundle. Returns Optional.empty() if the URL could not be computed or created.
        Parameters:
        classFromBundle - A class defined by a bundle class loader.
        filePath - the path of the resource file in the given bundle, relative to the root of the bundle
        Returns:
        an Optional<URL> or Optional.empty().
        See Also:
        FileLocator.find(URL), ImageDescriptor.createFromURL(URL)
      • imageDescriptorFromBundle

        public static java.util.Optional<ImageDescriptor> imageDescriptorFromBundle​(java.lang.String bundleSymbolicName,
                                                                                    java.lang.String imageFilePath)
        Returns a new Optional<ImageDescriptor> for an image file located within the specified bundle or Optional.empty().

        This is a convenience method that simply locates the image file in within the bundle. The path is relative to the root of the bundle, and takes into account files coming from bundle fragments. The path may include $arg$ elements. However, the path must not have a leading "." or path separator. Clients should use a path like "icons/mysample.png" rather than "./icons/mysample.png" or "/icons/mysample.png".

        Parameters:
        bundleSymbolicName - the Bundle symbolic name
        imageFilePath - the path of the image file in the given bundle, relative to the root of the bundle
        Returns:
        Optional<ImageDescriptor> or Optional.empty()
        See Also:
        ImageDescriptor.createFromURL(URL)
      • imageDescriptorFromBundle

        public static java.util.Optional<ImageDescriptor> imageDescriptorFromBundle​(java.lang.Class<?> classFromBundle,
                                                                                    java.lang.String imageFilePath)
        Returns a new Optional<ImageDescriptor> for an image file located within the specified bundle or Optional.empty().

        This is a convenience method that simply locates the image file in within the bundle. The path is relative to the root of the bundle, and takes into account files coming from bundle fragments. The path may include $arg$ elements. However, the path must not have a leading "." or path separator. Clients should use a path like "icons/mysample.png" rather than "./icons/mysample.png" or "/icons/mysample.png".

        Parameters:
        classFromBundle - A class defined by a bundle class loader.
        imageFilePath - the path of the image file in the given bundle, relative to the root of the bundle
        Returns:
        Optional<ImageDescriptor> or Optional.empty()
        See Also:
        ImageDescriptor.createFromURL(URL)