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