org.eclipse.ui.decorators这个扩展点可以为对应的节点添加不同的图标显示。

使用方式都差不多,以下就转载一下使用方式:

1、添加扩展点 org.eclipse.ui.decorators

2、修改plugin.xml

<extension
         point="org.eclipse.ui.decorators">
      <decorator
            id="my.ui.decorator"
            label="IFolder Decorator"
            state="true"
           class="my.ui.decorators.LabelDecorator">
         <enablement>
            <objectClass name="org.eclipse.core.resources.IFolder"/>
         </enablement>
      </decorator>
   </extension>

添加扩展点后,xml里有很多属性,为了单独对指定的文件夹起作用,删掉其他属性,并增加class属性;

enablement的意思是对什么起作用,这里是对文件夹IFolder起作用;

3、my.ui.decorators.LabelDecorator类源码

package my.ui.decorators;

import org.eclipse.core.internal.resources.Folder;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ILabelDecorator;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.swt.graphics.Image;

import my.ui.BabaowgtkitUIPlugIn;
/**
* 更改图标
* ClassName:LabelDecorator
 */
@SuppressWarnings({ "restriction", "unused" })
public class LabelDecoratorimplementsILabelDecorator{
/**
  *
  * (non-Javadoc)
  * @see org.eclipse.jface.viewers.ILabelDecorator#decorateImage(org.eclipse.swt.graphics.Image, java.lang.Object)
  */
public Image decorateImage(Image image, Object element) {
  //更改src文件夹图标
  if (element instanceof Folder
    && ((Folder) element).getName().equals("src")) {
   return MyUIPlugIn.getImage("icons/packagefolder_obj.gif");
  }
  returnnull;
}

public String decorateText(String text, Object element) {
  // TODO Auto-generated method stub
  return null;
}

public void addListener(ILabelProviderListener listener) {
  // TODO Auto-generated method stub
 
}

public void dispose() {
  // TODO Auto-generated method stub
 
}

public boolean isLabelProperty(Object element, String property) {
  // TODO Auto-generated method stub
  return false;
}

public void removeListener(ILabelProviderListener listener) {
  // TODO Auto-generated method stub
 
}
}

上面用到了MyUIPlugIn.getImage的方法,下面贴出源码,目的就是取项目目录下的图标文件;

MyUIPlugIn是建立插件项目时自动生成的,继承了 AbstractUIPlugin;

public static ImageDescriptor getImageDescriptor(String path) {
  return imageDescriptorFromPlugin(PLUGIN_ID, path);
}

public static Image getImage(String path){
  return getImageDescriptor(path).createImage();
}

PLUGIN_ID是插件项目的ID;

rcp(插件开发)org.eclipse.ui.decorators 使用的更多相关文章

  1. 【eclipse插件开发实战】Eclipse插件开发1——eclipse内核结构、扩展点机制

    Eclipse插件开发实战1--eclipse内核结构.扩展点机制 一.前言 本系列总体介绍eclipse插件开发基本理论.插件项目结构及开发步骤,最后再给出两个插件开发实例. 总体安排结构如下: 1 ...

  2. Application "org.eclipse.ui.ide.workbench" could not be found in the registry.问题的解决

    今天升级Eclipse,升级完Restart,碰到启动不了让看日志,日志里主要错误信息即是Application "org.eclipse.ui.ide.workbench" co ...

  3. 【Eclipse】一个简单的 RCP 应用 —— 显示Eclipse 的启动时间。

    1 创建一个插件项目 1.1 File - New - Plug-in Project 注: 1 如果 New 下没有 Plug-in Project , 到 Other 里面去找. 2 如上截图的下 ...

  4. org.eclipse.ui.menus扩展点学习

    Eclipse菜单: menu:help?after=addtions menu:navigate?after=open.ext2 menu:window?after=newEditor menu:f ...

  5. JFace dailog button事件中刷新透视图异常 Trying to execute the disabled command org.eclipse.ui.window.closePerspective

    报错的代码为 protected void buttonPressed(int buttonId) { Display.getDefault().syncExec(new Runnable() { p ...

  6. How to set font and colors of Eclipse UI

    The original URL of this article is https://codeyarns.com/2014/11/03/how-to-set-font-and-font-size-o ...

  7. 【eclipse插件开发实战】 Eclipse插件开发6——eclipse在线翻译插件Translator开发实例详解

    Eclipse插件开发6--eclipse在线翻译插件Translator开发实例详解 在上一篇文章中讲到了一个简单的eclipse插件开发实例,主要是对插件工程的基本创建步骤进行了讲解,这篇文章当中 ...

  8. 【转】RCP中org.eclipse.core.runtime.CoreException

    org.eclipse.core.runtime.CoreException: Plug-in TRAIN was unable to load class train.Application. 利用 ...

  9. org.eclipse.ui.PartInitException: Unable to open editor, unknown editor ID: org.xmen.ui.text.XMLTextEditor

    无法打开struts模式的编译xml的编译器,然后打开.project文件,编辑最后一行,找到<natures>结点,增加一条<nature>com.genuitec.ecli ...

随机推荐

  1. Java数据流格式转换

    1 字节流InputStream                  ->FileInputStreamOutputStream                 ->FileOutputSt ...

  2. C#写PDF文件类库PDF File Writer介绍

    .NET平台开源项目速览(16)C#写PDF文件类库PDF File Writer介绍   阅读目录 1.PDF File Writer基本介绍 2.一个简单的使用案例 3.资源 1年前,我在文章:这 ...

  3. spoj 1812 lcsII (后缀自动机)

    spoj 1812 lcsII (后缀自动机) 题意:求多个串的lcs,最多10个串,每个串最长10w 解题思路:后缀自动机.先建好第一个串的sam,然后后面的串拿上去跑(这个过程同前一题).sam上 ...

  4. OCP-1Z0-051-题目解析-第8题

    8. View the Exhibit and examine the structure of the CUSTOMERS table. Which two tasks would require ...

  5. C#面向对象2 静态类、静态成员的理解

    理解:静态成员属于类所有,为各个类的实例所公用,与实例无关,需要全局共享的属性或者方法定义成静态的 C#静态成员:  1.静态成员属于类所有,故用类名调用,非静态成员属于类的实例所有,用实例名调用  ...

  6. Eclipse 优化方法(经典收藏)

    第一步: 取消自动validationvalidation有一堆,什么xml.jsp.jsf.js等等,我们没有必要全部都去自动校验一下,只是需要的时候才会手工校验一下! 取消方法:windows–& ...

  7. windows api 梳理

    PathMatchSpec Function Searches a string using a Microsoft MS-DOS wild card match type. Syntax BOOL  ...

  8. WCF技术剖析之十一:异步操作在WCF中的应用(上篇)

    原文:WCF技术剖析之十一:异步操作在WCF中的应用(上篇) 按照操作执行所需的资源类型,我们可以将操作分为CPU绑定型(CPU Bound)操作和I/O绑定型(I/O Bound)操作.对于前者,操 ...

  9. Ubuntu 挂载ISO文件的方法

    1.在终端中输入:sudo mkdir /media/iso 在/media下生成一个iso文件夹用来挂载iso文件2.然后输入:sudo mount -o loop /home/X/X/XXXX.i ...

  10. vs2010中将复制过来的文件或文件夹显示到解决方案管理

    今天在给一个做好的页面上加.net程序,我先将程序中的文件夹复制到解决方案中,可是在VS2010的解决方案资源管理器中并没有这样的文件夹,可明明 在这里,为什么显示不出来,应该在VS2010的哪个地方 ...