Add Package explorer in RCP-Application result in loosing some icon

夙愿已清 提交于 2019-12-20 04:47:22

问题


In my eclispe rcp application I added a package explorer adding org.eclipse.jdt.ui

When I use my rcp-app, as I create a new Project by "New Project Wizard" to add a "General Project", the project is correctely created, but the corresponding icon in package explorer view is not loaded.

What is the plugin I have to add to my application to see that all the (platform) Icons correctly ?

Thanks a lot


回答1:


This is a known issue in Eclipse RCP applications.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=234252

The work around is to add some code to your ApplicationWorkbenchAdvisor.java

Here's some more documentation about this issue in RCP

http://help.eclipse.org/ganymede/topic/org.eclipse.platform.doc.isv/guide/cnf_rcp.htm

In this code example, I've added the images for the Project Explorer and the Problems View.

Here's what I had to add to my initialize method...

  public void initialize(IWorkbenchConfigurer configurer) {
     super.initialize(configurer);

     // here's some of my code that does some typical RCP  configuration
     configurer.setSaveAndRestore(true);
     PlatformUI.getPreferenceStore().setValue(
            IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS, false);

    // here is the work around code
    /*
     * This is a hack to get Project tree icons to show up in the Project Explorer.
     * It is descriped in the Eclipse Help Documents here.
     * 
     * http://help.eclipse.org/ganymede/topic/org.eclipse.platform.doc.isv/guide/cnf_rcp.htm
     * 
     */

    IDE.registerAdapters();

    final String ICONS_PATH = "icons/full/";

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

    declareWorkbenchImage(
            configurer, 
            ideBundle,
            IDE.SharedImages.IMG_OBJ_PROJECT, 
            ICONS_PATH + "obj16/prj_obj.gif",
            true);

    declareWorkbenchImage(
            configurer, 
            ideBundle,
            IDE.SharedImages.IMG_OBJ_PROJECT_CLOSED, 
            ICONS_PATH + "obj16/cprj_obj.gif", 
            true);

    declareWorkbenchImage(
            configurer, 
            ideBundle, 
            IDEInternalWorkbenchImages.IMG_ETOOL_PROBLEMS_VIEW, 
            ICONS_PATH + "eview16/problems_view.gif", 
            true);

    declareWorkbenchImage(
            configurer, 
            ideBundle, 
            IDEInternalWorkbenchImages.IMG_ETOOL_PROBLEMS_VIEW_ERROR, 
            ICONS_PATH + "eview16/problems_view_error.gif", 
            true);


    declareWorkbenchImage(
            configurer, 
            ideBundle, 
            IDEInternalWorkbenchImages.IMG_ETOOL_PROBLEMS_VIEW_WARNING, 
            ICONS_PATH + "eview16/problems_view_warning.gif", 
            true);

    declareWorkbenchImage(
            configurer, 
            ideBundle, 
            IDEInternalWorkbenchImages.IMG_OBJS_ERROR_PATH, 
            ICONS_PATH + "obj16/error_tsk.gif", 
            true);

    declareWorkbenchImage(
            configurer, 
            ideBundle, 
            IDEInternalWorkbenchImages.IMG_OBJS_WARNING_PATH, 
            ICONS_PATH + "obj16/warn_tsk.gif", 
            true);

    /*
     * End of hack in this method... 
     */
}

private void declareWorkbenchImage(IWorkbenchConfigurer configurer_p, Bundle ideBundle, String symbolicName, String path, boolean shared)  
{
    URL url = ideBundle.getEntry(path);
    ImageDescriptor desc = ImageDescriptor.createFromURL(url);
    configurer_p.declareImage(symbolicName, desc, shared);
}

Hope this helps.

Thanks!




回答2:


You should probably using the Project Explorer rather than the Package Explorer. The Package Explorer is Java-specific, the Project Explorer can do Java and everything else.

Here is some more information: http://help.eclipse.org/indigo/topic/org.eclipse.platform.doc.isv/guide/cnf.htm




回答3:


You have to register some adapters in your WorkbenchAdvisor#initialize(IWorkbenchConfigurer) method manually.

Call in this method (you'll find the IDE class in bundle org.eclipse.ui.ide.application

org.eclipse.ui.ide.IDE.registerAdapters();


来源:https://stackoverflow.com/questions/8277902/add-package-explorer-in-rcp-application-result-in-loosing-some-icon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!