Skip to content

Commit e224055

Browse files
committed
add versioning to preference handling
Signed-off-by: Andre Bossert <anb0s@anbos.de>
1 parent 53dc3d6 commit e224055

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

plugin/src/de/anbos/eclipse/easyshell/plugin/Activator.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@
2121
import org.eclipse.core.runtime.Path;
2222
import org.eclipse.core.runtime.Platform;
2323
import org.eclipse.core.runtime.Status;
24+
import org.eclipse.core.runtime.preferences.InstanceScope;
25+
import org.eclipse.jface.preference.IPreferenceStore;
2426
import org.eclipse.jface.resource.ImageDescriptor;
2527
import org.eclipse.jface.resource.ImageRegistry;
2628
import org.eclipse.ui.plugin.AbstractUIPlugin;
29+
import org.eclipse.ui.preferences.ScopedPreferenceStore;
2730
import org.osgi.framework.Bundle;
2831
import org.osgi.framework.BundleContext;
2932

@@ -36,12 +39,17 @@
3639
*/
3740
public class Activator extends AbstractUIPlugin {
3841

39-
// The shared instance
42+
// The shared instance
4043
private static Activator plugin;
4144

4245
//Resource bundle.
4346
private ResourceBundle resourceBundle;
4447

48+
/**
49+
* Storage for preferences.
50+
*/
51+
private IPreferenceStore myPreferenceStore;
52+
4553
/**
4654
* The constructor
4755
*/
@@ -213,4 +221,18 @@ public static void logDebug(String string) {
213221
}
214222
}
215223

224+
@Override
225+
public IPreferenceStore getPreferenceStore() {
226+
// Create the preference store lazily.
227+
if (myPreferenceStore == null) {
228+
myPreferenceStore = getNewPreferenceStoreByVersion(Constants.PREF_VERSIONS[0]);
229+
}
230+
return myPreferenceStore;
231+
}
232+
233+
public IPreferenceStore getNewPreferenceStoreByVersion(String version) {
234+
String pluginNodeName = getBundle().getSymbolicName();
235+
return new ScopedPreferenceStore(InstanceScope.INSTANCE, pluginNodeName + "/" + version, pluginNodeName);
236+
}
237+
216238
}

plugin/src/de/anbos/eclipse/easyshell/plugin/Constants.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public interface Constants {
1616
// Plugin
1717
public static final String PLUGIN_ID = "de.anbos.eclipse.easyshell.plugin";
1818

19-
// Images
19+
// Images
2020
public static final String IMAGE_PATH = "icons/";
2121
public static final String IMAGE_UNKNOWN = "sample.gif";
2222
public static final String IMAGE_OPEN = "prompt.gif";
@@ -26,6 +26,10 @@ public interface Constants {
2626
public static final String IMAGE_OTHER = "editor.gif";
2727

2828
// Preferences
29+
// version with index = 0 is the used one
30+
public static final String[] PREF_VERSIONS = {
31+
"v2_0_001"
32+
};
2933
public static final String PREF_COMMANDS = "COMMANDS";
3034
public static final String PREF_MENU = "MENU";
3135

plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/Initializer.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,35 @@
1212
package de.anbos.eclipse.easyshell.plugin.preferences;
1313

1414
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
15+
//import org.eclipse.core.runtime.preferences.IEclipsePreferences;
16+
//import org.eclipse.core.runtime.preferences.InstanceScope;
1517
import org.eclipse.jface.preference.IPreferenceStore;
18+
//import org.osgi.service.prefs.BackingStoreException;
19+
//import org.osgi.service.prefs.Preferences;
1620

1721
import de.anbos.eclipse.easyshell.plugin.Activator;
1822
import de.anbos.eclipse.easyshell.plugin.Constants;
1923

2024
public class Initializer extends AbstractPreferenceInitializer {
2125

2226
public void initializeDefaultPreferences() {
27+
// get the actual preference store
2328
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
29+
/*
30+
IEclipsePreferences instanceNode = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
31+
Preferences preferences = instanceNode.node(Constants.PREF_VERSIONS[0]);
32+
preferences.put("test", "value");
33+
try {
34+
preferences.flush();
35+
} catch (BackingStoreException e) {
36+
// TODO Auto-generated catch block
37+
e.printStackTrace();
38+
}
39+
*/
2440
String defaultCommand = PreferenceValueConverter.asCommandDataString(CommandDataDefaultCollection.getCommandsNative(null, true));
2541
String defaultMenu = PreferenceValueConverter.asCommandMenuDataString(CommandDataDefaultCollection.getCommandsNativeAsMenu(true));
2642
store.setDefault(Constants.PREF_COMMANDS, defaultCommand);
2743
store.setDefault(Constants.PREF_MENU, defaultMenu);
28-
//getDefaultPresets();
29-
/*
30-
store.setDefault(PreferenceConstants.P_BOOLEAN, true);
31-
store.setDefault(PreferenceConstants.P_CHOICE, "choice2");
32-
store.setDefault(PreferenceConstants.P_STRING,
33-
"Default value");
34-
*/
3544
}
3645

3746
}

0 commit comments

Comments
 (0)