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