Although it is possible to inject an entire preference node, sometimes it is more convenient to inject just a single preference value. This can reduce the amount of code needed to extract and use a preference value. In addition, this can remove the runtime dependency on IEclipsePreferences
, which can make the code more portable.
Replace the injected
IEclipsePreferences
node with anint launchCount
field, and appendvalue = "launchCount"
to the@Preferences
annotation:@Preference(nodePath = "com.packtpub.e4.clock.ui", value = "launchCount") @Inject // IEclipsePreferences preferences; int launchCount;
Update the print message to use the
launchCount
value directly:System.out.println("Launch count is: " + launchCount);
Run the target Eclipse instance, and open the Time Zone Tree View. In the Console view, there should be a Launch count is: message with the same value as before.