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;
21 import org.simantics.simulation.ui.preferences.SimulationPreferences.StepMode;
25 * @author Tuukka Lehtonen
27 public final class SimulationPreferenceUtil {
29 public static SimulationPreferences getDefaultPrefs() {
30 return getPrefs(DefaultScope.INSTANCE);
36 public static SimulationPreferences getPrefs() {
37 return getPrefs(InstanceScope.INSTANCE);
43 public static SimulationPreferences getPrefs(IScopeContext context) {
44 IEclipsePreferences node = context.getNode(Activator.PLUGIN_ID);
45 double stepDuration = node.getDouble(SimulationPreferences.P_SIMULATION_STEP_DURATION, SimulationPreferences.DEFAULT_SIMULATION_STEP_DURATION);
46 double stepEndTime = node.getDouble(SimulationPreferences.P_SIMULATION_STEP_END_TIME, SimulationPreferences.DEFAULT_SIMULATION_STEP_END_TIME);
47 int stepMode = node.getInt(SimulationPreferences.P_SIMULATION_STEP_MODE, SimulationPreferences.DEFAULT_SIMULATION_STEP_MODE.ordinal());
49 return new SimulationPreferences(node, stepDuration, stepEndTime, StepMode.fromInt(stepMode));
54 * @throws BackingStoreException
56 public static void setPrefs(SimulationPreferences prefs) {
57 setPrefs(InstanceScope.INSTANCE, prefs);
62 * @throws BackingStoreException
64 public static void flushPrefs(SimulationPreferences prefs) throws BackingStoreException {
65 Preferences p = _setPrefs(InstanceScope.INSTANCE, prefs);
71 * @throws BackingStoreException
73 public static void setPrefs(IScopeContext context, SimulationPreferences prefs) {
74 _setPrefs(context, prefs);
79 * @throws BackingStoreException
81 private static IEclipsePreferences _setPrefs(IScopeContext context, SimulationPreferences prefs) {
82 IEclipsePreferences node = context.getNode(Activator.PLUGIN_ID);
83 node.putDouble(SimulationPreferences.P_SIMULATION_STEP_DURATION, prefs.stepDuration);
84 node.putDouble(SimulationPreferences.P_SIMULATION_STEP_END_TIME, prefs.stepEndTime);
85 node.putInt(SimulationPreferences.P_SIMULATION_STEP_MODE, prefs.stepMode.ordinal());