To save and load preferences, an instance of Preferences
(from the org.osgi.service.prefs
package) is typically obtained from an instance of InstanceScope
(from the org.eclipse.core.runtime.preferences
package). The INSTANCE
singleton returns an instance of Preferences
that has a getNode
method. This returns a store that can be used to persist key/value pairs.
Open the
Activator
of thecom.packtpub.e4.clock.ui
plug-in.Add the following to the
start
method to count the number of times the plug-in has been launched:// import org.osgi.service.prefs.Preferences; // import org.eclipse.core.runtime.preferences.InstanceScope; // ^ add these if necessary to top of the class Preferences preferences = InstanceScope.INSTANCE.getNode("com.packtpub.e4.clock.ui"); int launchCount = preferences.getInt("launchCount", 0)+1; System.out.println("I have been launched "+launchCount+" times"); preferences.putInt("launchCount", launchCount); preferences.sync();
Run the target...