Class ElementImageHelper


  • @OpenApiAll
    public class ElementImageHelper
    extends java.lang.Object
    Utility class to work with 'Image' property, which is contained by all elements.
    • Field Detail

      • mCache

        private static final java.util.Map<java.lang.Object,​ResizableIcon> mCache
        Stores ImageInformation as key and ResizableIcon as value. This is used to get already created icon.
    • Constructor Detail

      • ElementImageHelper

        public ElementImageHelper()
    • Method Detail

      • getCustomImageTaggedValue

        @CheckForNull
        private static TaggedValue getCustomImageTaggedValue​(Element element,
                                                             java.lang.String propertyName)
        Gets slot of image property by element and property name.
        Parameters:
        element - element, which contains image property.
        propertyName - name of property.
        Returns:
        gets slot of image.
      • getCustomImageTaggedValue

        @CheckForNull
        private static TaggedValue getCustomImageTaggedValue​(Element element,
                                                             java.lang.String propertyName,
                                                             Stereotype stereotype)
        Gets slot of image property by element and property name.
        Parameters:
        element - element, which contains image property.
        propertyName - name of property.
        Returns:
        gets slot of image.
      • getCustomImageSlotValue

        @CheckForNull
        private static java.lang.String getCustomImageSlotValue​(Element element,
                                                                java.lang.String propertyName,
                                                                Stereotype stereotype)
        Gets slot of image property by element and property name and takes its value.
        Parameters:
        element - element, which contains image property.
        propertyName - name of property.
        Returns:
        gets slot of image.
      • getCustomImageInformation

        @CheckForNull
        public static ElementImageHelper.ImageInformation getCustomImageInformation​(Element element)
        Gets image information by element if image is set.
        Parameters:
        element - element, which contains image property.
        Returns:
        image information if image to element is set, otherwise null.
      • getCustomImageInformation

        @CheckForNull
        public static ElementImageHelper.ImageInformation getCustomImageInformation​(Element element,
                                                                                    Stereotype stereotype)
        Gets image information by element if image is set.
        Parameters:
        element - element, which contains image property.
        Returns:
        image information if image to element is set, otherwise null.
      • setCustomImageInformation

        public static void setCustomImageInformation​(Element element,
                                                     Image image)
        Set image information to given element: stereotype 'CustomImageHolder' is applied on element and image information are saved to the tags of this stereotype.
        Parameters:
        element - element, which contains image property.
        image - information source used to set image.
      • setCustomImageInformation

        public static void setCustomImageInformation​(Element element,
                                                     @CheckForNull
                                                     ElementImageHelper.ImageInformation imageInformation)
        Set image information to given element: stereotype 'CustomImageHolder' is applied on element and image information are saved to the tags of this stereotype. If image is removed, stereotype is removed too.
        Parameters:
        element - element, which contains image property.
        imageInformation - structure, which contains information of image: content, format and location.
      • setOrClearValue

        private static void setOrClearValue​(TaggedValue taggedValue,
                                            @CheckForNull
                                            java.lang.String value)
      • getImageHolderStereotype

        public static Stereotype getImageHolderStereotype​(Project project)
        Return image holder stereotype from a given project.
        Parameters:
        project - project
        Returns:
        image holder stereotype
      • getIconFromCustomImageProperty

        @CheckForNull
        public static ResizableIcon getIconFromCustomImageProperty​(@CheckForNull
                                                                   Element element)
        Gets 'ResizableIcon', which is created from the image information.
        Parameters:
        element - element, which contains image property.
        Returns:
        'ResizableIcon' if image is set to element's 'Image' property, otherwise null.
      • getIconFromCustomImageProperty

        @CheckForNull
        public static ResizableIcon getIconFromCustomImageProperty​(@CheckForNull
                                                                   ElementImageHelper.ImageInformation imageInformation)
        A helper method to create resizable icon from image information.
        Parameters:
        imageInformation - image info
        Returns:
        icon
      • constructCacheKey

        @CheckForNull
        private static java.lang.Object constructCacheKey​(Element element)
        Construct icon cache key for a given element.
        Parameters:
        element - element
        Returns:
        cache key or null if Element has no Image
      • constructCacheKey

        @CheckForNull
        private static java.lang.Object constructCacheKey​(@CheckForNull
                                                          java.lang.String imageContent,
                                                          @CheckForNull
                                                          java.lang.String location)
        Construct icon cache key for a given image content.
        Parameters:
        imageContent - image content
        Returns:
        cache key or null if content is null
      • getElementToSetImage

        @CheckForNull
        public static Element getElementToSetImage​(ModelElementProvider pElement)
        Returns element to set image property
        Parameters:
        pElement - presentation element
        Returns:
        element to which image should be set
      • getProvidedElementImageInformation

        @CheckForNull
        public static ElementImageHelper.ImageInformation getProvidedElementImageInformation​(ModelElementProvider pElement)
        Returns image information of provided element
        Parameters:
        pElement - presentation element
        Returns:
        element to which image should be set