0

I'm creating my own PreferencePage for Eclipse for a RCP application. There is a FileFieldEditor which I want to be enabled and disabled by an BooleanFieldEditor.

Now I can't figure out how to implement this.

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);

Any ideas where to place the code to enable and disable the FileFieldEditor? I know how to enable/disable but in which method has the code to be placed?

Already tried in createFieldEditors(), checkState(), updateFieldEditors() and createControl().

Yeti
  • 1,108
  • 19
  • 28

1 Answers1

3

You can override the

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

  super.propertyChange(event);
}

method of FieldEditorPreferencePage to get the property change events (for all the fields).

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • Thank you very much! That solved the problem together with DirkNM's if-clause. Thank you too! – Yeti Nov 13 '14 at 14:39
  • Is there no functionality in the field editor API to handle this automatically? It would be convenient to setup some field editors as children to a `OptionalFieldEditor` to have all children to automatically be enabled/disabled by their parent. – Lii Feb 22 '18 at 09:05
  • @Lii No, there is no such functionality – greg-449 Feb 22 '18 at 09:49