Class AbstractResourceIconProvider

  • All Implemented Interfaces:
    IconProvider

    public abstract class AbstractResourceIconProvider
    extends Object
    implements IconProvider
    This is an abstract base class for implementing icon providers that serve icons from file resources. These files could be read from the file system, directly from the bundle itself or from somewhere else that can provide an InputStream. The resources are expected to follow the naming convention "[-].", e.g. "alarm.png" or "alarm-on.svg". Resource names must be all lower case. Whether an icon is provided or not is determined by the existence of a resource without a state postfix. If a specific resource for a state is available, it will be used. If not, the default icon without a state postfix is used. If the state is a decimal number between 0 and 100, the implementation will look for a resource with the next smaller state postfix available. Example: For category "DimmableLight" and state 84, it will check for the resources dimmablelight-82.png, dimmablelight-81.png, dimmablelight-80.png and return the first one it can find.
    Author:
    Kai Kreuzer - Initial contribution
    • Field Detail

      • context

        protected org.osgi.framework.BundleContext context
        The OSGi bundle context
    • Constructor Detail

      • AbstractResourceIconProvider

        public AbstractResourceIconProvider()
    • Method Detail

      • activate

        protected void activate​(org.osgi.framework.BundleContext context)
        When activating the service, we need to keep the bundle context.
        Parameters:
        context - the bundle context provided through OSGi DS.
      • setTranslationProvider

        protected void setTranslationProvider​(TranslationProvider i18nProvider)
      • unsetTranslationProvider

        protected void unsetTranslationProvider​(TranslationProvider i18nProvider)
      • getIconSets

        public Set<IconSet> getIconSets()
        Description copied from interface: IconProvider
        Returns a set of icon set definitions (meta-data) which this provider defines.
        Specified by:
        getIconSets in interface IconProvider
        Returns:
        a set of icon sets in the default locale
      • hasIcon

        public Integer hasIcon​(String category,
                               String iconSetId,
                               IconSet.Format format)
        Description copied from interface: IconProvider
        determines whether this provider can deliver an icon for a given name
        Specified by:
        hasIcon in interface IconProvider
        Parameters:
        category - the icon category
        iconSetId - the id of the icon set for which the icon is requested
        format - the format of the stream (usually either png or svg)
        Returns:
        a non-negative Integer value defining the priority (higher is more important) or null, if this provider cannot deliver an icon. Default for full icon sets should be 0, so that others have the chance to override icons.
      • getIcon

        public InputStream getIcon​(String category,
                                   String iconSetId,
                                   String state,
                                   IconSet.Format format)
        Description copied from interface: IconProvider
        retrieves the InputStream of an icon
        Specified by:
        getIcon in interface IconProvider
        iconSetId - the id of the icon set for which the icon is requested
        format - the format of the stream (usually either png or svg)
        Returns:
        a byte stream of the icon in the given format or null, if no icon exists
      • getPriority

        protected abstract Integer getPriority()
        Provides the priority of this provider. A higher value will give this provider a precedence over others.
        Returns:
        the priority as a positive integer
      • getResource

        protected abstract InputStream getResource​(String iconSetId,
                                                   String resourceName)
        Provides the content of a resource for a certain icon set as a stream or null, if the resource does not exist.
        Parameters:
        iconSetId - the id of the icon set for which the resource is requested
        resourceName - the name of the resource
        Returns:
        the content as a stream or null, if the resource does not exist
      • hasResource

        protected abstract boolean hasResource​(String iconSetId,
                                               String resourceName)
        Checks whether a certain resource exists for a given icon set.
        Parameters:
        iconSetId - the id of the icon set for which the resource is requested
        resourceName - the name of the resource
        Returns:
        true, if the resource exists, false otherwise