Project specific preference page in Eclipse RCP application

我们两清 提交于 2019-12-22 00:11:31

问题


I want to enable project-based Preference-dialogs for our product. I stumble upon 2 different problems:

How do I store those project related informations. As an educated guess I would try this one:

  • IPreferenceStore store = new ScopedPreferenceStore(new ProjectScope(project.getIProject()), Activator.PLUGIN_ID);
  • Afterwards set the "project store" as I want (for example inside a preference page as store)

How do I enable a Preference Page only for a project? I know I can call a preference dialog with some preselected pages using the PreferenceUtils.createPreferenceDialogOn(…). Unfortunately the IDs of the preference pages have to defined in the org.eclipse.ui.preferencePagesextension point. But if they are inside this extension point, these pages are also in the global "Preferences" of the product. If they are not specified inside the EP the pages are not shown.

Any hints on that? Thanks in advance :)

EDIT: What I actually wanted was a properties dialog, not a preference dialog. If you are working with property pages, the PreferenceUtils does not work at all. If you contribute a properties page via org.eclipse.ui.propertyPages it works well for the standard eclipse navigator - but how do I handle this inside a custom navigator (Common Navigator Framework)?


回答1:


You will need to subclass PropertiesPage and then put a reference to it in your plugin.xml like this for example. This uses two different properties pages, one that is shown when a project is select, the other for a file. And they are both only present in the projects with the specified project nature.

<extension point="org.eclipse.ui.propertyPages">
    <page
        class="com.oaklandsw.transform.editor.TransformProjectPropertiesPage"
    id="com.oaklandsw.transform.filePropPage"
    name="%appHandle">
    <enabledWhen>
    <and>
            <instanceof
             value="org.eclipse.core.resources.IProject">
        </instanceof>
            <adapt type="org.eclipse.core.resources.IResource" >
                <test
                 property="org.eclipse.core.resources.projectNature"
                value="com.oaklandsw.transform.runtime.nature">
                </test>
            </adapt>   
    </and>
    </enabledWhen>
    </page> 
    <page class="com.oaklandsw.transform.editor.TransformFilePropertiesPage"
        id="com.oaklandsw.transform.projectPropPage" name="%appHandle">
        <enabledWhen>
            <and>
        <instanceof
            value="org.eclipse.core.resources.IFile">
        </instanceof>
            <adapt type="org.eclipse.core.resources.IResource" >
                <test property="org.eclipse.core.resources.projectNature"
                    value="com.oaklandsw.transform.runtime.nature" />
            </adapt>        
            </and>
        </enabledWhen>
    </page>
</extension>


来源:https://stackoverflow.com/questions/10652221/project-specific-preference-page-in-eclipse-rcp-application

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