Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 336697 - [JFace] FontFieldEditor fires default value as a String not FontData[]
Summary: [JFace] FontFieldEditor fires default value as a String not FontData[]
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.6.1   Edit
Hardware: PC Windows 7
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-09 06:48 EST by Ben Rowlands CLA
Modified: 2020-03-21 13:17 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.