How to use IDecorationContext api from Eclipse JFace

Is there an example of using IDecorationContext to decorate shortcuts?

In appearance, the IDecorationContext class seems to provide some support for contextual decoration, but for the life of me I cannot find any sample code using this function ...

Has anyone really used the context decoration function, and if so, what use cases did he allow?


PS: I’m looking for a way to apply image decorations to the labels of objects, and depending on where the object is displayed, the size of the base icon changes (for example, traditional “small” icons in tables and tree elements and larger icons for content headers).

Jewelery applied to the original badges must choose the appropriate sizes accordingly.

IDecorationContext seems to fit the vector, for which I need it, but the documentation is as rare as you might expect from a minor open source library function, and there are no examples to be found.

Googling for "IDecorationContext" also didn’t show anything interesting, so I move on to the crowd of StackOverflow crowds in the hope that the next guy who gets the question will be able to get an answer faster;)

+7
java eclipse api swt jface
source share
1 answer

I did not use IDecorationContext, but you can see that it is used in org.eclipse.jface.viewers.LabelDecorator .

Also discussed in this thread (even if there is no answer that can at least give you a starting point)

My current approach is to extend org.eclipse.ui.decorators using ILightweightLabelDecorator will add an overlay replacement to the corresponding icon:

 public class ProjectLabelDecorator extends LabelProvider implements ILightweightLabelDecorator { ... public void decorate(Object element, IDecoration decoration) { if (element instanceof IFolder) { IFolder folder = (IFolder) element; try { if (folder.getProject().hasNature("rttdt.nature")) { if (ProjectNature.isTestcase(folder)) { IDecorationContext context = decoration.getDecorationContext(); if (context instanceof DecorationContext) { ((DecorationContext) context).putProperty( IDecoration.ENABLE_REPLACE, Boolean.TRUE); } decoration.addOverlay(fTestcaseOverlay, IDecoration.REPLACE); } } catch (CoreException e) { } } } ... } 
+7
source share

All Articles