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; } }