stojelenov
stojelenov

Reputation: 13

How to avoid validating specific DirectoryFieldEditor on org.eclipse.jface.preference.PreferencePage?

We do have got preference page:

public class PreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage
{
  // another preferences...

  // add checkbox - enable export path setting
  Composite exportPathControl = getFieldEditorParent();
  exportPathC = new BooleanFieldEditor(PreferenceConstants.P_SETEXPORTPATHPREFERENCEPAGE, SetExportPathStrPref, exportPathControl);
  addField(exportPathC);
  boolean enableSetExportPathControl = Activator.getDefault().
    getPreferenceStore().getBoolean(PreferenceConstants.P_SETEXPORTPATHPREFERENCEPAGE);
  boolean checked = exportPathC.getBooleanValue();

  // Path
  setExportPathControl = getFieldEditorParent();
  browserFE = new CustomDirectoryFieldEditor(PreferenceConstants.P_EXPORTPATHPREFERENCEPAGE, 
    ExportPathStrPref, setExportPathControl ,enableSetExportPathControl);
  browserFE.setEmptyStringAllowed(false);
  addField(browserFE);

  // enable/disable export path DirectoryFieldEditor according to exportPathC
  browserFE.setEnabled(enableSetExportPathControl, setExportPathControl);
    
  ((Button) exportPathC.getDescriptionControl(exportPathControl)).addSelectionListener(exportPathControlListener());
}

We do need avoid of checking browserFE if is disabled (exportPathC is deselected). We handled error message with browserFE.enableValidation(setExportPathEnabled):

// enable/disable possibility to set path according BooleanFieldEditor exportPathC
  private SelectionListener exportPathControlListener()
  {
    return new SelectionListener()
    {
      @Override
      public void widgetSelected(SelectionEvent event)
      {
        if (event.widget instanceof Button)
        {
          Boolean setExportPathEnabled = ((Button) event.widget).getSelection();
          browserFE.setEnabled(setExportPathEnabled, setExportPathControl);
          browserFE.enableValidation(setExportPathEnabled);
          browserFE.checkState();
        }
      }

      @Override
      public void widgetDefaultSelected(SelectionEvent e)
      {
        widgetSelected(e);
      }
    };
  }

But how to enable Apply button?

There is org.eclipse.jface.preference.FieldEditorPreferencePage.checkState(), but protected.

We could override org.eclipse.jface.preference.PreferencePage.isValid() and set it's output to true, but what is more paths are wrong? We do knot know, which path causes trouble, org.eclipse.jface.preference.FieldEditorPreferencePage.invalidFieldEditor is private as well.

Any idea? Thanks for any hint!!

Upvotes: 0

Views: 42

Answers (0)

Related Questions