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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.simulation.ui.preferences;
\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
24 * @author Tuukka Lehtonen
\r
26 public final class SimulationPreferenceUtil {
\r
28 public static SimulationPreferences getDefaultPrefs() {
\r
29 return getPrefs(DefaultScope.INSTANCE);
\r
35 public static SimulationPreferences getPrefs() {
\r
36 return getPrefs(InstanceScope.INSTANCE);
\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
46 return new SimulationPreferences(node, stepDuration);
\r
51 * @throws BackingStoreException
\r
53 public static void setPrefs(SimulationPreferences prefs) {
\r
54 setPrefs(InstanceScope.INSTANCE, prefs);
\r
59 * @throws BackingStoreException
\r
61 public static void flushPrefs(SimulationPreferences prefs) throws BackingStoreException {
\r
62 Preferences p = _setPrefs(InstanceScope.INSTANCE, prefs);
\r
68 * @throws BackingStoreException
\r
70 public static void setPrefs(IScopeContext context, SimulationPreferences prefs) {
\r
71 _setPrefs(context, prefs);
\r
76 * @throws BackingStoreException
\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