X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.simulation.ui%2Fsrc%2Forg%2Fsimantics%2Fsimulation%2Fui%2Fpreferences%2FSimulationPreferenceUtil.java;fp=bundles%2Forg.simantics.simulation.ui%2Fsrc%2Forg%2Fsimantics%2Fsimulation%2Fui%2Fpreferences%2FSimulationPreferenceUtil.java;h=a5517ff5d63ee6f88797a52432546bd285a4fe31;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/preferences/SimulationPreferenceUtil.java b/bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/preferences/SimulationPreferenceUtil.java new file mode 100644 index 000000000..a5517ff5d --- /dev/null +++ b/bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/preferences/SimulationPreferenceUtil.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.simulation.ui.preferences; + +import org.eclipse.core.runtime.preferences.DefaultScope; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.IScopeContext; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.osgi.service.prefs.BackingStoreException; +import org.osgi.service.prefs.Preferences; +import org.simantics.simulation.ui.Activator; + + +/** + * @author Tuukka Lehtonen + */ +public final class SimulationPreferenceUtil { + + public static SimulationPreferences getDefaultPrefs() { + return getPrefs(DefaultScope.INSTANCE); + } + + /** + * @return + */ + public static SimulationPreferences getPrefs() { + return getPrefs(InstanceScope.INSTANCE); + } + + /** + * @return + */ + public static SimulationPreferences getPrefs(IScopeContext context) { + IEclipsePreferences node = context.getNode(Activator.PLUGIN_ID); + double stepDuration = node.getDouble(SimulationPreferences.P_SIMULATION_STEP_DURATION, SimulationPreferences.DEFAULT_SIMULATION_STEP_DURATION); + + return new SimulationPreferences(node, stepDuration); + } + + /** + * @return + * @throws BackingStoreException + */ + public static void setPrefs(SimulationPreferences prefs) { + setPrefs(InstanceScope.INSTANCE, prefs); + } + + /** + * @return + * @throws BackingStoreException + */ + public static void flushPrefs(SimulationPreferences prefs) throws BackingStoreException { + Preferences p = _setPrefs(InstanceScope.INSTANCE, prefs); + p.flush(); + } + + /** + * @return + * @throws BackingStoreException + */ + public static void setPrefs(IScopeContext context, SimulationPreferences prefs) { + _setPrefs(context, prefs); + } + + /** + * @return + * @throws BackingStoreException + */ + private static IEclipsePreferences _setPrefs(IScopeContext context, SimulationPreferences prefs) { + IEclipsePreferences node = context.getNode(Activator.PLUGIN_ID); + node.putDouble(SimulationPreferences.P_SIMULATION_STEP_DURATION, prefs.stepDuration); + return node; + } + +}