Own PreferencePage:通过BooleanFieldEditor启用和禁用FieldEditor

时间:2014-11-13 13:19:44

标签: java eclipse eclipse-rcp rcp

我正在为RCP应用程序创建自己的Eclipse PreferencePage。 我希望BradFieldEditor启用和禁用FileFieldEditor。

现在我无法弄清楚如何实现这一点。

public class PreferencePage extends FieldEditorPreferencePage implements
IWorkbenchPreferencePage {

FileFieldEditor subversionPathEditor;
BooleanFieldEditor subversionSupportBooleanFieldEditor;

public PreferencePage() {
super(GRID);
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setDescription(""); //$NON-NLS-1$
}


protected void createFieldEditors() {
subversionSupportBooleanFieldEditor = new BooleanFieldEditor
    ("subversionSupport", "Enable Subversion support", BooleanFieldEditor.DEFAULT, getFieldEditorParent());
System.out.println(subversionSupportBooleanFieldEditor.getPreferenceName());

subversionSupportBooleanFieldEditor.setPropertyChangeListener(new IPropertyChangeListener() {
    @Override
    public void propertyChange(PropertyChangeEvent event) {
    if ("field_editor_value".equalsIgnoreCase(event.getProperty())) {
        Boolean enabled = (Boolean)event.getNewValue();
        subversionPathEditor.setEnabled(enabled, getFieldEditorParent());
    }

    }
});
addField(subversionSupportBooleanFieldEditor);
subversionPathEditor = new FileFieldEditor("SubversionPathEditor", "Subversion client executable: ", true, 
    FileFieldEditor.VALIDATE_ON_KEY_STROKE, getFieldEditorParent());
subversionPathEditor.setStringValue(VCSSettings.getSubversionPath());
    addField(subversionPathEditor);

任何想法放置代码以启用和禁用FileFieldEditor的想法?我知道如何启用/禁用但在哪种方法中放置代码?

已在createFieldEditors(),checkState(),updateFieldEditors()和createControl()中尝试过。

1 个答案:

答案 0 :(得分:2)

您可以覆盖

@Override
public void propertyChange(PropertyChangeEvent event)
{
  ... extra here

  super.propertyChange(event);
}

获取属性更改事件的FieldEditorPreferencePage方法(适用于所有字段)。