---
title: "关于RCP中使用系统resource navigator图标和项目名称不显示的问题"
author: "Dollyn"
date: "2007-04-17T14:21:00Z"
tags: []
slug: "rcp-resource-navigator"
draft: false
lastmod: "2007-04-17T14:21:00Z"
id: 79635
url: "https://dollyn.iteye.com/blog/79635"
---

![](http://blog.csdn.net/dollyn/aggbug/1567810.aspx) 首先说明： 这个是不推荐使用的方法，并且现在有了common navigator。

最近毕业设计需要这个东西，所以一直在看。之所以 不使用common navigator，第一是由于时间有限（毕业设计的时间只有一个月多了，现在基本还没有开始做，只是在做一些技术上的验证），所以先使用系统提供的东西 把功能性的东西实现，以后再进行优化；第二能力有限（呵呵），看了两天common navigator的用法，发现需要自己实现的东西太多了，两天也没有理出个头绪，所以决定先不实现自己的navagator 了。

这个方法转自eclipseworld:

**\[FAQ] ResourceNavigator** **中不显示项目 /** **文件名称和图片 .**

Q: 在使用 Eclipse 提供的 ResourceNavigator （它是 IDE plugin 的一部分），在 Navigator 里新建的项目和文件时不显示名称和图片 , 怎么办 ?

A: 目前这个 ResourceNavigator 不被鼓励用在 RCP 程序里，以后版本的 Eclipse 可能会提供更合适的插件。当前解决方法为 , 在 WorkbenchAdvisor 方法中加入下面的代码 :

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)   public   void  preStartup()  ... {  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    //  注册Workbench变量  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   WorkbenchAdapterBuilder.registerAdapters();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    //  声明Workbench图片  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImages();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif) }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif) private   void  declareWorkbenchImages()  ... {  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    final  String ICONS\_PATH  =   " $nl$/icons/full/ " ; // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    final  String PATH\_ELOCALTOOL  =  ICONS\_PATH  +   " elcl16/ " ;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    //  Enabled toolbar icons. // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    final  String PATH\_ETOOL  =  ICONS\_PATH  +   " etool16/ " ;  //  Enabled toolbar icons. // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    final  String PATH\_DTOOL  =  ICONS\_PATH  +   " dtool16/ " ;  //  Disabled toolbar icons. // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    final  String PATH\_OBJECT  =  ICONS\_PATH  +   " obj16/ " ;  //  Model object icons // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    final  String PATH\_WIZBAN  =  ICONS\_PATH  +   " wizban/ " ;  //  Wizard icons // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   Bundle ideBundle  =  Platform.getBundle(IDEWorkbenchPlugin.IDE\_WORKBENCH);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, IDEInternalWorkbenchImages.IMG\_ETOOL\_BUILD\_EXEC, PATH\_ETOOL  +   " build\_exec.gif " ,  false );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, IDEInternalWorkbenchImages.IMG\_ETOOL\_BUILD\_EXEC\_HOVER, PATH\_ETOOL  +   " build\_exec.gif " ,  false );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, IDEInternalWorkbenchImages.IMG\_ETOOL\_BUILD\_EXEC\_DISABLED, PATH\_DTOOL  +   " build\_exec.gif " ,  false );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, IDEInternalWorkbenchImages.IMG\_ETOOL\_SEARCH\_SRC, PATH\_ETOOL  +   " search\_src.gif " ,  false );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, IDEInternalWorkbenchImages.IMG\_ETOOL\_SEARCH\_SRC\_HOVER, PATH\_ETOOL  +   " search\_src.gif " ,  false );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, IDEInternalWorkbenchImages.IMG\_ETOOL\_SEARCH\_SRC\_DISABLED, PATH\_DTOOL  +   " search\_src.gif " ,  false );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, IDEInternalWorkbenchImages.IMG\_ETOOL\_NEXT\_NAV, PATH\_ETOOL  +   " next\_nav.gif " ,  false );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, IDEInternalWorkbenchImages.IMG\_ETOOL\_PREVIOUS\_NAV, PATH\_ETOOL  +   " prev\_nav.gif " ,  false );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, IDEInternalWorkbenchImages.IMG\_WIZBAN\_NEWPRJ\_WIZ, PATH\_WIZBAN  +   " newprj\_wiz.gif " ,  false );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, IDEInternalWorkbenchImages.IMG\_WIZBAN\_NEWFOLDER\_WIZ, PATH\_WIZBAN  +   " newfolder\_wiz.gif " ,  false );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, IDEInternalWorkbenchImages.IMG\_WIZBAN\_NEWFILE\_WIZ, PATH\_WIZBAN  +   " newfile\_wiz.gif " ,  false );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, IDEInternalWorkbenchImages.IMG\_WIZBAN\_IMPORTDIR\_WIZ, PATH\_WIZBAN  +   " importdir\_wiz.gif " ,  false );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, IDEInternalWorkbenchImages.IMG\_WIZBAN\_IMPORTZIP\_WIZ, PATH\_WIZBAN  +   " importzip\_wiz.gif " ,  false );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, IDEInternalWorkbenchImages.IMG\_WIZBAN\_EXPORTDIR\_WIZ, PATH\_WIZBAN  +   " exportdir\_wiz.gif " ,  false );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, IDEInternalWorkbenchImages.IMG\_WIZBAN\_EXPORTZIP\_WIZ, PATH\_WIZBAN  +   " exportzip\_wiz.gif " ,  false );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle,  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   IDEInternalWorkbenchImages.IMG\_WIZBAN\_RESOURCEWORKINGSET\_WIZ, PATH\_WIZBAN  +   " workset\_wiz.gif " ,  false );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, IDEInternalWorkbenchImages.IMG\_DLGBAN\_SAVEAS\_DLG, PATH\_WIZBAN  +   " saveas\_wiz.gif " ,  false );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, IDE.SharedImages.IMG\_OBJ\_PROJECT, PATH\_OBJECT  +   " prj\_obj.gif " ,  true );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, IDE.SharedImages.IMG\_OBJ\_PROJECT\_CLOSED, PATH\_OBJECT  +   " cprj\_obj.gif " ,  true );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, IDE.SharedImages.IMG\_OPEN\_MARKER, PATH\_ELOCALTOOL  +   " gotoobj\_tsk.gif " ,  true );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)    //  task objects  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, IDE.SharedImages.IMG\_OBJS\_TASK\_TSK, PATH\_OBJECT  +   " taskmrk\_tsk.gif " ,  true );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, IDE.SharedImages.IMG\_OBJS\_BKMRK\_TSK, PATH\_OBJECT  +   " bkmrk\_tsk.gif " ,  true );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   String string  =  IDEInternalWorkbenchImages.IMG\_OBJS\_COMPLETE\_TSK;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, string, PATH\_OBJECT  +   " complete\_tsk.gif " ,  true );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, IDEInternalWorkbenchImages.IMG\_OBJS\_INCOMPLETE\_TSK, PATH\_OBJECT  +   " incomplete\_tsk.gif " ,  true );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, IDEInternalWorkbenchImages.IMG\_OBJS\_WELCOME\_ITEM, PATH\_OBJECT  +   " welcome\_item.gif " ,  true );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   declareWorkbenchImage(ideBundle, IDEInternalWorkbenchImages.IMG\_OBJS\_WELCOME\_BANNER, PATH\_OBJECT  +   " welcome\_banner.gif " ,  true );  // $NON-NLS-1$  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif) }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif) private   void  declareWorkspaceImage(Bundle ideBundle, String symbolicName, String path,  boolean  shared)  ... {  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   URL url  =  Platform.find(ideBundle,  new  Path(path));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   ImageDescriptor desc  =  ImageDescriptor.createFromURL(url);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)   getWindowConfigurer().getWorkbenchConfigurer().declareImage(symbolicName, desc, shared);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif) }

当然，你还要在 plugin dependencies 里加上 org.eclipse.ui.ide 和 org.eclipse.ui.views ，所以你的 RCP 程序会变得更大，这就是代价。

 

 

（注：以上是原帖，但个人发现有两个错误：1、最后一个方法名称应该为declareWorkbenchImage ，这个就是前面被调用了n次的方法，这个应该是原作者笔误；2、最后一个方法的最后一条语句：如果是在类workbenchadvisor中调用的话，应该去掉前面的getWindowConfigure，直接

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) getWorkbenchConfigurer().declareImage(symbolicName, desc, shared)

）

另外，上面有些东西应该是用不到的，可以去掉，不过我没有验证。