Major improvements to @Preference in e(fx)clipse 2.2.0


With 2.1.0 we introduced our custom @Preference annotation who is to be preferred over the one available as part of the Eclipse 4 Application Platform.

With the next nightly build there are even more reasons to use our annotation because you get even cooler features:

Support for default values

If there’s no value found in the preference store you most likely don’t want to retrieve a default value null (String), false (boolean), 0 (int & long & float & double) but a custom one. You can now define the default value in the annotation

class Component {
@Inject
@Preference(key="velocity",defaultValue="1000")
private int velocity;
}

Support for more value types

It is fairly likely that you want not only store/retrieve standard values like int, long, float, double and String but eg date or time.

class Component {
@Inject
@Preference(key="lastModified")
private java.time.Instant lastModified;
}

The support for “value types” is provided by a new service named ValueSerializer who supports the most common value types (eg values in java.time) and if you have your own types you contribute your own serializers.

Complex objects

While the above introduced support for “value types” works for things like date and time it is not unlikely that you have to remember non trivial objects like configurations the new support for complex values might get you excited

@XmlRootElement
public class Complex {
private String name;
private int value;
private List<Complex> children;

// ....
}

class Component {
@Inject
@Preference(key="complexData")
private Complex complexData;
}

Serialization and Deserialization is provided through the ObjectSerializer service

3 thoughts on “Major improvements to @Preference in e(fx)clipse 2.2.0

    • Tom Schindl September 30, 2015 / 10:09 pm

      The build has not been renamed to 2.2.0

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s