双桅渔船  
漂泊,没有终点
日历
<2006年1月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
2930311234
统计
  • 随笔 - 5
  • 文章 - 0
  • 评论 - 3
  • 引用 - 0

导航

常用链接

留言簿(1)

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜

 
 自己遇到了这方面问题,在瀚海星云上咨询了一下,解决后总结了一下。现在收录到自己的空间里:)
前段时间为了使用jdt中的package explorer进行一个rcp程序的开发。在版面上进行了
提问,得到了simon lei,pandawang 的热情帮助,在此表示感谢。经过一番学习,在几个论
坛上问了一下,当时仍没有找到解决方法(主要是使用package explorer时项目和文件
夹的显示问题),又看到rcp的faq中有reusable 的说法就得出不能在rcp中复用jdt组件
的结论。实际上这个结论是错误的,只要提供相关的插件支持是可以重用jdt中组件的,
我再一次重复这个问题是为了避免我那个回帖误导别人。

我在rcp的perspective中用addview加入package explorer是没有问题的,之所以不能显
示项目名称是因为没有注册相关的adapter。

只要在workbenchadvisor中的initialize方法中加入:
WorkbenchAdapterBuilder.registerAdapters();
declareWorkbenchImages();
就可以解决问题。WorkbenchAdapterBuilder是org.eclipse.ui.ide中的类,用
registerAdapters方法注册adapter后就可以正常显示项目名称以及文件夹名称,但是这
时候还不能显示相关的图标。
declareWorkbenchImages()方法用来解决图标的问题。
实现如下:

private void declareWorkbenchImages() {

            
final String ICONS_PATH = "$nl$/icons/full/";//$NON-NLS-1$
            final String PATH_ELOCALTOOL = ICONS_PATH + "elcl16/"//Enabled
toolbar icons.//$NON-NLS-1$
            final String PATH_ETOOL = ICONS_PATH + "etool16/"//Enabled toolbar
icons.//$NON-NLS-1$
            final String PATH_DTOOL = ICONS_PATH + "dtool16/"//Disabled
toolbar icons.//$NON-NLS-1$
            final String PATH_OBJECT = ICONS_PATH + "obj16/"//Model object
icons//$NON-NLS-1$
            final String PATH_WIZBAN = ICONS_PATH + "wizban/"//Wizard
icons//$NON-NLS-1$

            Bundle ideBundle 
= Platform.getBundle(IDEWorkbenchPlugin.IDE_WORKBENCH);

            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,
                    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,
                    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,
                    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,
                    IDEInternalWorkbenchImages.IMG_DLGBAN_SAVEAS_DLG,
                    PATH_WIZBAN 
+ "saveas_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$

            
// task objects
           
//declareRegistryImage(IDEInternalWorkbenchImages.IMG_OBJS_HPRIO_TSK,
PATH_OBJECT+"hprio_tsk.gif");
           
//declareRegistryImage(IDEInternalWorkbenchImages.IMG_OBJS_MPRIO_TSK,
PATH_OBJECT+"mprio_tsk.gif");
           
//declareRegistryImage(IDEInternalWorkbenchImages.IMG_OBJS_LPRIO_TSK,
PATH_OBJECT+"lprio_tsk.gif");

            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$

            
// synchronization indicator objects
           
//declareRegistryImage(IDEInternalWorkbenchImages.IMG_OBJS_WBET_STAT,
PATH_OVERLAY+"wbet_stat.gif");
           
//declareRegistryImage(IDEInternalWorkbenchImages.IMG_OBJS_SBET_STAT,
PATH_OVERLAY+"sbet_stat.gif");
           
//declareRegistryImage(IDEInternalWorkbenchImages.IMG_OBJS_CONFLICT_STAT,
PATH_OVERLAY+"conflict_stat.gif");

            
// content locality indicator objects
           
//declareRegistryImage(IDEInternalWorkbenchImages.IMG_OBJS_NOTLOCAL_STAT,
PATH_STAT+"notlocal_stat.gif");
           
//declareRegistryImage(IDEInternalWorkbenchImages.IMG_OBJS_LOCAL_STAT,
PATH_STAT+"local_stat.gif");
           
//declareRegistryImage(IDEInternalWorkbenchImages.IMG_OBJS_FILLLOCAL_STAT,
PATH_STAT+"filllocal_stat.gif");
        }


        
/**
         * Declares an IDE-specific workbench image.
         * 
         * 
@param symbolicName the symbolic name of the image
         * 
@param path the path of the image file; this path is relative to the base
         * of the IDE plug-in
         * 
@param shared <code>true</code> if this is a shared image, and
         * <code>false</code> if this is not a shared image
         * 
@see IWorkbenchConfigurer#declareImage
         
*/

        
private void declareWorkbenchImage(Bundle ideBundle, String symbolicName,
                String path, 
boolean shared) {
            URL url 
= Platform.find(ideBundle, new Path(path));
            ImageDescriptor desc 
= ImageDescriptor.createFromURL(url);
            getWorkbenchConfigurer().declareImage(symbolicName, desc, shared);
        }

由于jdt是在为ide服务的,所以在重用组件时遇到的问题应该可以在eclipse源码中找到 答案。
posted on 2006-01-08 14:47 USTCEric 阅读(1116) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
博客园   IT新闻   Chat2DB   C++博客   博问  
 
 
Copyright © USTCEric Powered by: 博客园 模板提供:沪江博客