Project specific preference page in Eclipse RCP ap

2020-07-24 07:06发布

问题:

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>


标签: java eclipse rcp