王吉元-NWPU

导航

 
package com.repositoryclient.treeview;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.tmatesoft.svn.core.SVNNodeKind;

public class TreeLabelProvider extends LabelProvider implements ILabelProvider{
    public Image iconFolder = null;     
    public Image iconFile = null;
    
    public TreeLabelProvider() {
        this.iconFolder = getImageDescriptor("icons/folder.png").createImage();     //folder.png是本项目中icons文件夹中的图片
        this.iconFile = getImageDescriptor("icons/file.png").createImage();
    }
    
    
    public ImageDescriptor getImageDescriptor(String path) {
       return AbstractUIPlugin.imageDescriptorFromPlugin("RepositoryClient", path);  //这里这个函数的第一个参数是本插件的ID,第二个参数是本插件中图片的的相对路径
    }
    
    public String getText(Object element){
        FileNode node=(FileNode)element;
        return node.getFileName();
    }
    public Image getImage(Object element){
       
        FileNode node=(FileNode)element;
        if (node.getKind() == SVNNodeKind.DIR) {
            return iconFolder;
        }
        if (node.getKind() == SVNNodeKind.FILE) {
            return iconFile;
        }
        return null;
    }
}

 

posted on 2013-10-31 14:39  王吉元  阅读(1246)  评论(0编辑  收藏  举报