RCP程序的Navigator View中图标丢失解决办法
在XXXWorkbenchAdvisor.java中,处理如下代码:
public void postStartup() {
try{
//setup Navigator View's custom image
IWorkbenchPage activePage = this.getWorkbenchConfigurer().getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart view = activePage.showView("org.eclipse.ui.views.ResourceNavigator");
ResourceNavigator navigator = ((ResourceNavigator)view);
//NavigatorLabelProvider为我们新建立的一个类,具体见下边.
navigator.getViewer().setLabelProvider(new NavigatorLabelProvider());
other codes
....
}catch(Exception e){
//
}
#NavigatorLabelProvider.java
public class NavigatorLabelProvider extends LabelProvider {
public Image getImage(Object element) {
Image image = null;
String text = element.toString();
if (text.startsWith("P/",0)){
image = ImageUtil.getServiceImageDescriptor("project.gif").createImage();
}
if (text.startsWith("L/",0)){
if (text.endsWith(".project")){
image = ImageUtil.getServiceImageDescriptor("dotproject.gif").createImage();
}else{
image = ImageUtil.getServiceImageDescriptor("xxxfile.gif").createImage();
}
}
return image;
}
public String getText(Object element) {
String text = element.toString();
text = text.substring(2,text.length());
int pos = text.indexOf("/");
if (pos == -1){
return text;
}else{
if (text.endsWith(".project")){
return "YourName";
}else{
text = text.substring(pos+1,text.length());
}
}
return text;
}
}
另外,在Navigator View中,有些文件(例如:.project文件不想显示给客户看)
在此,我们可以为eclipse建立filter来处理.主要是在plugin.xml中增加filters
extention.一定要把selected设置为true,否则不能直接filter.
例如:
<!-- hide .project file in Navigator View -->
<extension point="org.eclipse.ui.ide.resourceFilters">
<filter
selected="true"
pattern=".project">
</filter>
</extension>