Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-ui-dev] OverlayDecoratorIcon, Image parameter and dispose

Hi Mickael,

Since it is a LabelProvider you should assume that the baseImage is
only needed for the life time of the LabelProvider, which itself has a
dispose method, which can be overridden.
In terms of Resources, like Image, I always suggest to use a JFace
ResourceManager.
In the constructor or init method of the
ResourceExtensionLabelProvider you could create a
LocalResourceManager, which can create the images based on the given
ImageDescriptor like this:

ResourceManager resourceManager;

public ResourceExtensionLabelProvider{
    this.resourceManager = new
LocalResourceManager(JFaceResources.getResources());
}

@Override
public ImageDescriptor decorateImage() {

// ....
       Image baseImage = this.resourceManager.createImage(res)
// ...
}

@Override
public void dispose() {
   this.resourceManager.dispose();
}

The parent AbstractResourceManager obtained from
JFaceResources.getResources() counts the references of this descriptor
and ensures that the baseImage is only created once, which is a huge
advantage compared to "res.createImage();".

We should consider to make more use of ResourceManagers to save
resources and therefore SWT handles.


I have to admit that I do not have a lot of experience with the
DecorationOverlayIcon, but IMHO this class should not be in charge for
disposing the image.

On Tue, Oct 11, 2016 at 1:58 PM, Mickael Istria <mistria@xxxxxxxxxx> wrote:
> Hi all,
>
> In https://git.eclipse.org/r/82899 , I wrote this piece of code:
>
>   @Override
>   protected ImageDescriptor decorateImage(ImageDescriptor input, Object
> element) {
>     ImageDescriptor res = super.decorateImage(input, element);
>     // ...
>     if (overlay != null) {
>       Image baseImage = res.createImage();
>       res = new DecorationOverlayIcon(baseImage, overlay,
> IDecoration.BOTTOM_LEFT);
>     }
>     return res;
>   }
>
>
> I have multiple questions about that:
> * Am I responsible of disposing the "baseImage", as it seems to be used by
> the DecorationOverlayIcon? Or does the DecorationOverlayIcon take
> * If I'm responsible of disposing the image, when should I do it? If I
> dispose it just after creation of the DecorationOverlayIcon, I get failure
> later (when the DecorationOverlayIcon tries to create its image); and from
> this method, I don't see how to get the lifecycle of the image to dispose it
> at the right time?
> * Maybe there's something better to use for that?
>
> Thanks in advance
> --
> Mickael Istria
> Eclipse developer for Red Hat Developers
> My blog - My Tweets
>
> _______________________________________________
> platform-ui-dev mailing list
> platform-ui-dev@xxxxxxxxxxx
> To change your delivery options, retrieve your password, or unsubscribe from
> this list, visit
> https://dev.eclipse.org/mailman/listinfo/platform-ui-dev



-- 
--
Trainer, Consultant and Developer

vogella GmbH
Haindaalwisch 17a, 22395 Hamburg
Amtsgericht Hamburg: HRB 127058
Geschäftsführer: Lars Vogel, Jennifer Nerlich de Vogel
USt-IdNr.: DE284122352
Tel (040) 78804360, Fax (032) 221739404, Email:
simon.scholz@xxxxxxxxxxx, Web: http://www.vogella.com


Back to the top