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. linux eclipse中运行android AVD 错误

    当使用android的AVD时提示以下错误: Starting emulator for AVD 'NexusOne' ERROR: 32-bit Linux Android emulator bin ...

  2. dll文件32位64位检测工具以及Windows文件夹SysWow64的坑(很详细,还有自动动手编程探测dll)

    阅读目录 dll文件不匹配导致数据库无法启动 究竟是System32还是SysWow64 区分dll文件32位64位的程序让我倍感迷惑 再次判断究竟是System32还是SysWow64——意想不到的 ...

  3. STLport在vc6中的集成

    STLport的下载 http://sourceforge.net/projects/stlport/ STLport的编译 * 试验环境 : win7x64sp1 + vc6sp6* 打开控制台窗口 ...

  4. Flex中怎么给表格中的滚动栏定位

    1.问题背景 假设表格中的字段过多,会出现滚动栏,在将滚动栏滚到一定的位置时,又一次刷新表格.滚动栏会回到原处,原来查看的字段还得继续滚动,才干查看到. 2.实现实例 <? xml versio ...

  5. RedHat Linux 5.5安装JDK+Tomcat并部署Java项目

    与大家分享下RedHat Linux 5.5安装JDK+Tomcat并部署Java项目的步骤,希望对大家有用. 1.下载并安装jdk 虚拟机中安装RedHat Linux 5.5 64位企业版, 这里 ...

  6. javascript笔记整理(对象基础)

    一.名词解释 1.基于对象(一切皆对象,以对象的概念来编程) 2.面向对象编程(Object Oriented Programming,OOP) A.对象(JavaScript 中的所有事物都是对象) ...

  7. 三家DirectUI的商业公司

    目前正在研究DirectUI技术,分享一点心得给大家.关于DirectUI技术的介绍我在这里就不说了,可以上Google查一下,非常丰富.目前使用DirectUI技术开发的软件产品原来原丰富,比如QQ ...

  8. 修改OpenSSL默认编译出的动态库文件名称

    在 Windows 平台上调用动态链接库 dll 文件时,有两种方式:a) 隐式的加载时链接:使用 *.lib (导入库)文件,在 IDE 的链接器相关设置中加入导入库 lib 文件的名称,或在程序中 ...

  9. Ajax Post提交事例及SpringMVC注解@RequestMapping取不到参数值解决办法

    var xmlHttp; //定义变量,用来创建xmlHttp对象 function ajaxfunction(url,onreadystatechangMethod,param){ // 创建xml ...

  10. ActiveMQ持久化方式(转)

    消息持久性对于可靠消息传递来说应该是一种比较好的方法,有了消息持久化,即使发送者和接受者不是同时在线或者消息中心在发送者发送消息后宕机了,在消息 中心重新启动后仍然可以将消息发送出去,如果把这种持久化 ...