在workbenchadvisor中的initialize方法中加入:
WorkbenchAdapterBuilder.registerAdapters();
declareWorkbenchImages();
WorkbenchAdapterBuilder是org.eclipse.ui.ide中的类,用registerAdapters方法注册adapter后就可以正常显示项目名称以及文件夹名称,但是这时候还不能显示相关的图标。
declareWorkbenchImages()方法用来解决图标的问题。
private void declareWorkbenchImage(Bundle ideBundle, String symbolicName,
String path, boolean shared)
{
URL url = ideBundle.getEntry(path);
ImageDescriptor desc = ImageDescriptor.createFromURL(url);
getWorkbenchConfigurer().declareImage(symbolicName, desc, shared);
}
private void declareWorkbenchImages()
{
final String ICONS_PATH = "icons/full/";//$NON-NLS-1$
final String PATH_ELOCALTOOL = ICONS_PATH + "elcl16/"; //Enabled
final String PATH_ETOOL = ICONS_PATH + "etool16/"; //Enabled
final String PATH_DTOOL = ICONS_PATH + "dtool16/"; //Disabled
final String PATH_OBJECT = ICONS_PATH + "obj16/"; //Model
final String PATH_WIZBAN = ICONS_PATH + "wizban/"; //Wizard
Bundle ideBundle = Platform.getBundle(IDEWorkbenchPlugin.IDE_WORKBENCH);
declareWorkbenchImage(ideBundle, ISharedImages.IMG_TOOL_NEW_WIZARD,
PATH_ETOOL + "new_wiz.gif", true); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
ISharedImages.IMG_TOOL_NEW_WIZARD_DISABLED, PATH_DTOOL
+ "new_wiz.gif", true); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IWorkbenchGraphicConstants.IMG_ETOOL_IMPORT_WIZ, PATH_ETOOL
+ "import_wiz.gif", false); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IWorkbenchGraphicConstants.IMG_ETOOL_EXPORT_WIZ, PATH_ETOOL
+ "export_wiz.gif", false); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IDEInternalWorkbenchImages.IMG_ETOOL_BUILD_EXEC, PATH_ETOOL
+ "build_exec.gif", false); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IDEInternalWorkbenchImages.IMG_ETOOL_BUILD_EXEC_HOVER,
PATH_ETOOL + "build_exec.gif", false); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IDEInternalWorkbenchImages.IMG_ETOOL_BUILD_EXEC_DISABLED,
PATH_DTOOL + "build_exec.gif", false); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IDEInternalWorkbenchImages.IMG_ETOOL_SEARCH_SRC, PATH_ETOOL
+ "search_src.gif", false); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IDEInternalWorkbenchImages.IMG_ETOOL_SEARCH_SRC_HOVER,
PATH_ETOOL + "search_src.gif", false); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IDEInternalWorkbenchImages.IMG_ETOOL_SEARCH_SRC_DISABLED,
PATH_DTOOL + "search_src.gif", false); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IDEInternalWorkbenchImages.IMG_ETOOL_NEXT_NAV, PATH_ETOOL
+ "next_nav.gif", false); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IDEInternalWorkbenchImages.IMG_ETOOL_PREVIOUS_NAV, PATH_ETOOL
+ "prev_nav.gif", false); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IWorkbenchGraphicConstants.IMG_WIZBAN_NEW_WIZ, PATH_WIZBAN
+ "new_wiz.gif", false); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IDEInternalWorkbenchImages.IMG_WIZBAN_NEWPRJ_WIZ, PATH_WIZBAN
+ "newprj_wiz.gif", false); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IDEInternalWorkbenchImages.IMG_WIZBAN_NEWFOLDER_WIZ,
PATH_WIZBAN + "newfolder_wiz.gif", false); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IDEInternalWorkbenchImages.IMG_WIZBAN_NEWFILE_WIZ, PATH_WIZBAN
+ "newfile_wiz.gif", false); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IWorkbenchGraphicConstants.IMG_WIZBAN_IMPORT_WIZ, PATH_WIZBAN
+ "import_wiz.gif", false); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IDEInternalWorkbenchImages.IMG_WIZBAN_IMPORTDIR_WIZ,
PATH_WIZBAN + "importdir_wiz.gif", false); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IDEInternalWorkbenchImages.IMG_WIZBAN_IMPORTZIP_WIZ,
PATH_WIZBAN + "importzip_wiz.gif", false); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IWorkbenchGraphicConstants.IMG_WIZBAN_EXPORT_WIZ, PATH_WIZBAN
+ "export_wiz.gif", false); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IDEInternalWorkbenchImages.IMG_WIZBAN_EXPORTDIR_WIZ,
PATH_WIZBAN + "exportdir_wiz.gif", false); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IDEInternalWorkbenchImages.IMG_WIZBAN_EXPORTZIP_WIZ,
PATH_WIZBAN + "exportzip_wiz.gif", false); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IDEInternalWorkbenchImages.IMG_WIZBAN_RESOURCEWORKINGSET_WIZ,
PATH_WIZBAN + "workset_wiz.gif", false); //$NON-NLS-1$
declareWorkbenchImage(ideBundle, IDE.SharedImages.IMG_OBJ_PROJECT,
PATH_OBJECT + "prj_obj.gif", true); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IDE.SharedImages.IMG_OBJ_PROJECT_CLOSED, PATH_OBJECT
+ "cprj_obj.gif", true); //$NON-NLS-1$
declareWorkbenchImage(ideBundle, IDE.SharedImages.IMG_OPEN_MARKER,
PATH_ELOCALTOOL + "gotoobj_tsk.gif", true); //$NON-NLS-1$
declareWorkbenchImage(ideBundle, IDE.SharedImages.IMG_OBJS_TASK_TSK,
PATH_OBJECT + "taskmrk_tsk.gif", true); //$NON-NLS-1$
declareWorkbenchImage(ideBundle, IDE.SharedImages.IMG_OBJS_BKMRK_TSK,
PATH_OBJECT + "bkmrk_tsk.gif", true); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IDEInternalWorkbenchImages.IMG_OBJS_COMPLETE_TSK, PATH_OBJECT
+ "complete_tsk.gif", true); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IDEInternalWorkbenchImages.IMG_OBJS_INCOMPLETE_TSK, PATH_OBJECT
+ "incomplete_tsk.gif", true); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IDEInternalWorkbenchImages.IMG_OBJS_WELCOME_ITEM, PATH_OBJECT
+ "welcome_item.gif", true); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IDEInternalWorkbenchImages.IMG_OBJS_WELCOME_BANNER, PATH_OBJECT
+ "welcome_banner.gif", true); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IDEInternalWorkbenchImages.IMG_ETOOL_PROBLEM_CATEGORY, PATH_ETOOL
+ "problem_category.gif", true); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IDEInternalWorkbenchImages.IMG_OBJS_ERROR_PATH, PATH_OBJECT
+ "error_tsk.gif", true); //$NON-NLS-1$
declareWorkbenchImage(ideBundle,
IDEInternalWorkbenchImages.IMG_OBJS_WARNING_PATH, PATH_OBJECT
+ "warn_tsk.gif", true); //$NON-NLS-1$
}