0xCAB / idocit

Automatically exported from code.google.com/p/idocit
0 stars 0 forks source link

SWTException in PreferencePage #137

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
After working with the 0.0.11-release for a while, I wasn't able to open the 
Preference Page "Thematic Grids" due to a SWTException (see attached log). I 
guess, there is a listener which is not removed when a dialog is closed.

Original issue reported on code.google.com by krauseda...@web.de on 23 Nov 2012 at 8:09

Attachments:

GoogleCodeExporter commented 8 years ago
This can happen when the iDocIt! ConfigurationChange event 
(IConfigurationChangeListener) is fired and a listening PreferencePage is 
already disposed and can not be updated by the event.

Maybe the following code snippet helps to improve the listener management.

/**
 * Useful code snippets: how to hook the preference page change event.
 * @author Dirk Meier-Eickhoff
 */
public class GetPreferencePageChangeEvent
{
    private IPageChangedListener pageChangedListener;

    public void init() {
        initAllListener();
        addAllListener();
    }

    private void initAllListener()
    {
        pageChangedListener = new IPageChangedListener() {

            @Override
            public void pageChanged(PageChangedEvent event)
            {
                if (event.getSelectedPage() != null
                        && event.getSelectedPage() instanceof ThematicGridPreferencePage)
                {
                    // refresh dialog content on open
                    setSelection(getSelection());
                }
            }
        };
    }

    private WorkbenchPreferenceDialog getWorkbenchPreferenceDialog()
    {
        // there can be only one WorkbenchPreferenceDialog within Eclipse, so I will get
        // the existing one
        return WorkbenchPreferenceDialog.createDialogOn(null, null);

        // alternative if you are within the PreferencePages, but maybe not stable:
        // return (WorkbenchPreferenceDialog) getShell().getData();
    }

    private void addAllListener()
    {
        getWorkbenchPreferenceDialog().addPageChangedListener(this.pageChangedListener);
    }

    private void removeAllListener()
    {
        getWorkbenchPreferenceDialog()
                .removePageChangedListener(this.pageChangedListener);
    }
}

Original comment by dirk.mei...@gmail.com on 23 Nov 2012 at 8:33