-2

I'm porting a large Java application into Eclipse 4.x RCP. I've been using a variety of JFace classes, especially some of the preference features, instead of the Eclipse or OSGI preference choices.

Why does the JFace PreferenceStore not have a BigDecimal/Decimal/double/float pref? From the default implemented FieldEditors eclipse.org website:

org.eclipse.jface.preference.FieldEditor

org.eclipse.jface.preference.BooleanFieldEditor
org.eclipse.jface.preference.ColorFieldEditor
org.eclipse.jface.preference.ComboFieldEditor
org.eclipse.jface.preference.FontFieldEditor
org.eclipse.jface.preference.ListEditor
    org.eclipse.jface.preference.PathEditor
org.eclipse.jface.preference.RadioGroupFieldEditor
org.eclipse.jface.preference.ScaleFieldEditor
org.eclipse.jface.preference.StringFieldEditor
    org.eclipse.jface.preference.IntegerFieldEditor
    org.eclipse.jface.preference.StringButtonFieldEditor
        org.eclipse.jface.preference.DirectoryFieldEditor
        org.eclipse.jface.preference.FileFieldEditor

Do people all hand-code a subclass for doubles? Is there a commonly used implementation? Seems like I am missing something... In my specific case, I need USD $ preferences, like pricing or per-item costs, so I happen to need "$6.99" as a price pref, needing to use an epsilon or precision to 2 base-10 digits.

EclipseE4
  • 13
  • 2

1 Answers1

0

We are not the JFace designers so we can't tell you why they didn't do something.

For currency you should stick to BigDecimal. double and float are not suitable for currency - see here.

To store BigDecimal as a preference you would have to store it as a String. You can extend the StringFieldEditor class and override the doCheckState method to check that the string is a valid big decimal value.

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • Thanks you for the override comment, I eventually found a derived class by Google that handles double as I needed. – EclipseE4 Dec 18 '17 at 04:39