]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.simulation.ui.preferences;\r
13 \r
14 import org.eclipse.core.runtime.preferences.DefaultScope;\r
15 import org.eclipse.core.runtime.preferences.IEclipsePreferences;\r
16 import org.eclipse.core.runtime.preferences.IScopeContext;\r
17 import org.eclipse.core.runtime.preferences.InstanceScope;\r
18 import org.osgi.service.prefs.BackingStoreException;\r
19 import org.osgi.service.prefs.Preferences;\r
20 import org.simantics.simulation.ui.Activator;\r
21 \r
22 \r
23 /**\r
24  * @author Tuukka Lehtonen\r
25  */\r
26 public final class SimulationPreferenceUtil {\r
27 \r
28     public static SimulationPreferences getDefaultPrefs() {\r
29         return getPrefs(DefaultScope.INSTANCE);\r
30     }\r
31 \r
32     /**\r
33      * @return\r
34      */\r
35     public static SimulationPreferences getPrefs() {\r
36         return getPrefs(InstanceScope.INSTANCE);\r
37     }\r
38 \r
39     /**\r
40      * @return\r
41      */\r
42     public static SimulationPreferences getPrefs(IScopeContext context) {\r
43         IEclipsePreferences node = context.getNode(Activator.PLUGIN_ID);\r
44         double stepDuration = node.getDouble(SimulationPreferences.P_SIMULATION_STEP_DURATION, SimulationPreferences.DEFAULT_SIMULATION_STEP_DURATION);\r
45 \r
46         return new SimulationPreferences(node, stepDuration);\r
47     }\r
48 \r
49     /**\r
50      * @return\r
51      * @throws BackingStoreException \r
52      */\r
53     public static void setPrefs(SimulationPreferences prefs) {\r
54         setPrefs(InstanceScope.INSTANCE, prefs);\r
55     }\r
56 \r
57     /**\r
58      * @return\r
59      * @throws BackingStoreException \r
60      */\r
61     public static void flushPrefs(SimulationPreferences prefs) throws BackingStoreException {\r
62         Preferences p = _setPrefs(InstanceScope.INSTANCE, prefs);\r
63         p.flush();\r
64     }\r
65 \r
66     /**\r
67      * @return\r
68      * @throws BackingStoreException \r
69      */\r
70     public static void setPrefs(IScopeContext context, SimulationPreferences prefs) {\r
71         _setPrefs(context, prefs);\r
72     }\r
73 \r
74     /**\r
75      * @return\r
76      * @throws BackingStoreException \r
77      */\r
78     private static IEclipsePreferences _setPrefs(IScopeContext context, SimulationPreferences prefs) {\r
79         IEclipsePreferences node = context.getNode(Activator.PLUGIN_ID);\r
80         node.putDouble(SimulationPreferences.P_SIMULATION_STEP_DURATION, prefs.stepDuration);\r
81         return node;\r
82     }\r
83 \r
84 }\r