Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 336697

Summary: [JFace] FontFieldEditor fires default value as a String not FontData[]
Product: [Eclipse Project] Platform Reporter: Ben Rowlands <ben.rowlands>
Component: UIAssignee: Platform UI Triaged <platform-ui-triaged>
Status: CLOSED WONTFIX QA Contact:
Severity: minor    
Priority: P3 CC: mseele, piotr.aniola
Version: 3.6.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard: stalebug

Description Ben Rowlands CLA 2011-02-09 06:48:26 EST
Build Identifier: 20100917-0705

FontFieldEditor is used to select a font in a preference page. Code that reacts to font changes register an IPropertyChangeListener with the PreferenceStore. When a new font is chosen this listener is invoked with a FontData[] instance as the new value. But when the "Restore Defaults" button is clicked on the preference page, the listener is called with a String representation of the default font.

Note, I use PreferenceConverter.setDefault(store, FONT, defaultFont) to initialized the default font in the preference store.

Stack trace showing the call path:

  ...
  at org.eclipse.jface.preference.PreferenceStore$1.run(PreferenceStore.java:136)
  at org.eclipse.jface.util.SafeRunnable$1.run(SafeRunnable.java:128)
  at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
  at org.eclipse.jface.preference.PreferenceStore.firePropertyChangeEvent(PreferenceStore.java:133)
  at org.eclipse.jface.preference.PreferenceStore.setToDefault(PreferenceStore.java:565)
  at org.eclipse.jface.preference.FieldEditor.store(FieldEditor.java:678)
  at org.eclipse.jface.preference.FieldEditorPreferencePage.performOk(FieldEditorPreferencePage.java:343)
  at org.eclipse.jface.preference.PreferencePage.performApply(PreferencePage.java:432)
  ...

When FieldEditor.store() is called it does this:

  ...
  if (isDefaultPresented) {
    preferenceStore.setToDefault(preferenceName);
  } else {
    doStore();
  }
  ...

Note, FontFieldEditor#setToDefault() does do the right thing. But I don't see anyone calling it. I think the fix would be to call instead of calling setToDefault above:

  protected void setToDefault() {
     FontData[] defaultFontData = PreferenceConverter.getDefaultFontDataArray(getPreferenceStore(), getPreferenceName());
     PreferenceConverter.setValue(getPreferenceStore(), getPreferenceName(), defaultFontData);
  }

Easy enough (but ugly) to workaround by checking argument type and re-parsing String into FontData instance.

Reproducible: Always
Comment 1 Piotr Aniola CLA 2015-01-27 05:27:58 EST
Can you please explain what the impact is? Is any code failing due to the unexpected value from FontFieldEditor?
Comment 2 Piotr Aniola CLA 2015-01-29 11:10:17 EST
Could you please attach a minimal test project that reproduces the issue?
Comment 3 Eclipse Genie CLA 2020-03-21 13:17:48 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.