How would one use IDecorationContext api from Eclipse JFace

前端 未结 1 1336
甜味超标
甜味超标 2020-12-07 02:02

Is there an example out there for using IDecorationContext for label decorations?

By the looks of it, IDecorationContext class seems to pro

相关标签:
1条回答
  • 2020-12-07 02:42

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

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

    My current approach is to extend org.eclipse.ui.decorators using a ILightweightLabelDecorator to add a replace overlay to the respective icons:

    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) {
             }
          }
       }
    
       ...
    }
    
    0 讨论(0)
提交回复
热议问题