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;h=5ca1591ca306ae67953e41706e07f9cd398b39a9;hb=HEAD;hp=a5517ff5d63ee6f88797a52432546bd285a4fe31;hpb=969bd23cab98a79ca9101af33334000879fb60c5;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 index a5517ff5d..5ca1591ca 100644 --- 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 @@ -1,84 +1,89 @@ -/******************************************************************************* - * 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; - } - -} +/******************************************************************************* + * 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; +import org.simantics.simulation.ui.preferences.SimulationPreferences.StepMode; + + +/** + * @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); + double stepEndTime = node.getDouble(SimulationPreferences.P_SIMULATION_STEP_END_TIME, SimulationPreferences.DEFAULT_SIMULATION_STEP_END_TIME); + int stepMode = node.getInt(SimulationPreferences.P_SIMULATION_STEP_MODE, SimulationPreferences.DEFAULT_SIMULATION_STEP_MODE.ordinal()); + + return new SimulationPreferences(node, stepDuration, stepEndTime, StepMode.fromInt(stepMode)); + } + + /** + * @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); + node.putDouble(SimulationPreferences.P_SIMULATION_STEP_END_TIME, prefs.stepEndTime); + node.putInt(SimulationPreferences.P_SIMULATION_STEP_MODE, prefs.stepMode.ordinal()); + return node; + } + +}