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. QT序列化操作(比较复杂和完善)

    应用需求: 在网盘开发过程中有这样一个需求,即对文件版本进行控制,即记录文件版本的更替信息,这里说的更替信息仅仅是记录不同时刻的文件变化,即文件的增.删.改.重命名等操作.在每个待监控的目录下都会保存 ...

  2. jetty插件开发配置

    <plugins> <!-- jetty插件 --> <plugin> <groupId>org.mortbay.jetty</groupId&g ...

  3. 基于visual Studio2013解决算法导论之006最大堆排序

     题目 最大堆排序 解决代码及点评 #include <stdio.h> #include <stdlib.h> #include <malloc.h> #i ...

  4. 清华集训2014 day2 task1 简单回路

    题目 如题. 算法 就是刚学习的插头DP. 从前往后和从后往前分别进行一次DP. 要点 合法的括号序列只有103个 如何合并两次dp的信息 一开始犯傻了,以为当且仅当两个轮廓线的状态相同才是合法的方案 ...

  5. 查询SystemFeature的方法

    查询SystemFeature的方法可以在adb shell下敲如下的命令: dumpsys package 然后搜feature关键字. 例如,我的平台的SystemFeature,如下所示: Fe ...

  6. EF 简单的 CRUD、分页 代码笔记

    添加: static void Main(string[] args)        {            CCDBEntities ccdbContext = new CCDBEntities( ...

  7. TImage也有OnClick事件,可以当按钮使用,配上合适的图片(背景透明,效果前凸)更是几乎以假乱真

    本质上TImage与TSpeedButton没有什么区别,都是没有句柄的,但都可以执行OnClick事件.有空分析一下.

  8. (转载)Jvm工作原理学习笔记

    一.        JVM的生命周期 1.      JVM实例相应了一个独立执行的java程序它是进程级别 a)    启动.启动一个Java程序时.一个JVM实例就产生了.不论什么一个拥有publ ...

  9. 设计模式模式适配器(Adapter)摘录

    23种子GOF设计模式一般分为三类:创建模式.结构模型.行为模式. 创建模式抽象的实例,他们帮助建立一个系统,是独立于如何.这是一个这些对象和陈述的组合.创建使用继承一个类架构更改实例,一个对象类型模 ...

  10. 【C语言】超大数乘法运算

    昨天做排列组合的时候遇到A(a,b)这个问题,需要计算A(20,20)超大,计算机32位的,最大数只能是2^32,这让我很悲伤! 于是乎就自己研究了如何进行超大数的计算! /************* ...