属性更改后Eclipse插件刷新

时间:2015-04-27 06:37:35

标签: eclipse eclipse-plugin

我开发了一个基于GEF的eclipse插件。当我更改属性时,我需要关闭所有文件并手动打开它们。 如何在更改属性后刷新插件的实例?

public class MyPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {   
    public MyPreferencePage() {
        super(GRID);
    }

    public void createFieldEditors() {
        addField(new StringFieldEditor(PreferenceConstants.MY_CONF,
            "Label", getFieldEditorParent()));
    }

    public void init(IWorkbench workbench) {
        setPreferenceStoreMyEditorPlugin.getDefault().getPreferenceStore());
    }

    @Override
    public boolean performOk() {
        boolean res = super.performOk();
        // Validated input
        // I think I have to refresh the config here
        return res;
    }
}

1 个答案:

答案 0 :(得分:0)

您可以向首选商店添加一个监听器,该监听器将通过以下方式告知首选项的更改:

MyEditorPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(listener);

其中listenerorg.eclipse.jface.util.IPropertyChangeListener的实现。此接口中的单个方法是

 public void propertyChange(PropertyChangeEvent event)
 {
    String changedPropertyId = event.getProperty();

    // TODO check if you need to do something for the changed property
 }