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. 基于visual Studio2013解决C语言竞赛题之0810链表去重

     题目

  2. SQL 多个表之间联合查询

    非常少用join,这次学学,并备忘两篇文章! 转自:http://hcx-2008.javaeye.com/blog/285661 连接查询 通过连接运算符能够实现多个表查询.连接是关系数据库模型的主 ...

  3. Codeforces Round #189 (Div. 2)

    题目地址:http://codeforces.com/contest/320 第一题:基本题,判断mod 1000,mod 100.,mod 10是不是等于144.14.1,直到为0 代码如下: #i ...

  4. Linux OpenCV读取视频失败,cvCreateFileCapture失败的解决

    背景: 近期想在嵌入式平台上开发QT+Opencv,无料PC机上编写的OpenCV程序老是打不开视频. 開始提示:OpenCV Error: Bad argument (Array should be ...

  5. 路径中“/” "\" "\\"的区别

    Unix使用斜杆/ 作为路径分隔符,而web应用最新使用在Unix系统上面,所以目前所有的网络地址都采用 斜杆/ 作为分隔符. Windows由于使用 斜杆/ 作为DOS命令提示符的参数标志了,为了不 ...

  6. 创建Activity

     创建Activity 创建 Activity 分为3个步骤: 1.创建一个扩展子Activity的class 2.创建一个Layout 3.在 AndroidMainfest 中 配置这个Activ ...

  7. oc 可变參数传递

    - (id)initWithFrame:(CGRect)frame delegate:(id<SGFocusImageFrameDelegate>)delegate focusImageI ...

  8. 学习算法-基数排序(radix sort)卡片分类(card sort) C++数组实现

    基数排序称为卡片分类,这是一个比较早的时间越多,排名方法. 现代计算机出现之前,它已被用于排序老式打孔卡. 说下基数排序的思想.前面我有写一个桶式排序,基数排序的思想是桶式排序的推广. 桶式排序:ht ...

  9. CentOS 6.4 x86_64 安装GCC 4.7.3

    下载gcc-4.7.3.tar.gz, 解压缩 wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.7.3/gcc-4.7.3.tar.gz tar -xzvf gcc-4.7. ...

  10. POJ 3481 &amp; HDU 1908 Double Queue (map运用)

    题目链接: PKU:http://poj.org/problem?id=3481 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1908 Descript ...