]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/preferences/SimulationPreferenceUtil.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.simulation.ui / src / org / simantics / simulation / ui / preferences / SimulationPreferenceUtil.java
diff --git a/bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/preferences/SimulationPreferenceUtil.java b/bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/preferences/SimulationPreferenceUtil.java
new file mode 100644 (file)
index 0000000..a5517ff
--- /dev/null
@@ -0,0 +1,84 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.simulation.ui.preferences;\r
+\r
+import org.eclipse.core.runtime.preferences.DefaultScope;\r
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;\r
+import org.eclipse.core.runtime.preferences.IScopeContext;\r
+import org.eclipse.core.runtime.preferences.InstanceScope;\r
+import org.osgi.service.prefs.BackingStoreException;\r
+import org.osgi.service.prefs.Preferences;\r
+import org.simantics.simulation.ui.Activator;\r
+\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public final class SimulationPreferenceUtil {\r
+\r
+    public static SimulationPreferences getDefaultPrefs() {\r
+        return getPrefs(DefaultScope.INSTANCE);\r
+    }\r
+\r
+    /**\r
+     * @return\r
+     */\r
+    public static SimulationPreferences getPrefs() {\r
+        return getPrefs(InstanceScope.INSTANCE);\r
+    }\r
+\r
+    /**\r
+     * @return\r
+     */\r
+    public static SimulationPreferences getPrefs(IScopeContext context) {\r
+        IEclipsePreferences node = context.getNode(Activator.PLUGIN_ID);\r
+        double stepDuration = node.getDouble(SimulationPreferences.P_SIMULATION_STEP_DURATION, SimulationPreferences.DEFAULT_SIMULATION_STEP_DURATION);\r
+\r
+        return new SimulationPreferences(node, stepDuration);\r
+    }\r
+\r
+    /**\r
+     * @return\r
+     * @throws BackingStoreException \r
+     */\r
+    public static void setPrefs(SimulationPreferences prefs) {\r
+        setPrefs(InstanceScope.INSTANCE, prefs);\r
+    }\r
+\r
+    /**\r
+     * @return\r
+     * @throws BackingStoreException \r
+     */\r
+    public static void flushPrefs(SimulationPreferences prefs) throws BackingStoreException {\r
+        Preferences p = _setPrefs(InstanceScope.INSTANCE, prefs);\r
+        p.flush();\r
+    }\r
+\r
+    /**\r
+     * @return\r
+     * @throws BackingStoreException \r
+     */\r
+    public static void setPrefs(IScopeContext context, SimulationPreferences prefs) {\r
+        _setPrefs(context, prefs);\r
+    }\r
+\r
+    /**\r
+     * @return\r
+     * @throws BackingStoreException \r
+     */\r
+    private static IEclipsePreferences _setPrefs(IScopeContext context, SimulationPreferences prefs) {\r
+        IEclipsePreferences node = context.getNode(Activator.PLUGIN_ID);\r
+        node.putDouble(SimulationPreferences.P_SIMULATION_STEP_DURATION, prefs.stepDuration);\r
+        return node;\r
+    }\r
+\r
+}\r