Search code examples
eclipse-rcprcpe4

How to include a preference page into the preference dialog


I know the way to add preference pages into the common preference dialog for an e3 RCP application. I have an e4 RCP application and I read that the preference dialog works different.

I found the way to open the common preference dialog, but I didn't find a way to include a customized preference page into the dialog.

public class PreferenceHandler {

    @CanExecute
    public boolean canExecute()
    {
        return true;    
    }

    @Execute
    public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell,  E4PreferenceRegistry  prefReg,
            @Optional @Named("preferencePageId") String pageId) {
        PreferenceManager pm = prefReg.getPreferenceManager();
        // Can display the standard dialog.
        PreferenceDialog dialog = new PreferenceDialog(shell, pm);
        if (pageId != null)
        {
            dialog.setSelectedNode(pageId);
        }
        dialog.create();
        dialog.getTreeViewer().setComparator(new ViewerComparator());
        dialog.getTreeViewer().expandAll();
        dialog.open();
    }
}


Solution

  • Most of the preference page code is part of e3 and isn't available in e4. Only the very basic JFace code is available.

    So you will have to add each preference page you want directly to the PreferenceManager. Something like:

    PreferenceManager pm = ... preference manager
    
    IPreferencePage page = ... create your preference page
    
    page.setTitle("title of the page");
    
    IPreferenceNode node = new PreferenceNode("id of the page", page);
    
    pm.addToRoot(node);