X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Ftypicals%2FToggleTypicalRealtimeSync.java;fp=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Ftypicals%2FToggleTypicalRealtimeSync.java;h=bb5063655785ac14d3f2b8dea4374c877b8204e1;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/typicals/ToggleTypicalRealtimeSync.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/typicals/ToggleTypicalRealtimeSync.java new file mode 100644 index 000000000..bb5063655 --- /dev/null +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/typicals/ToggleTypicalRealtimeSync.java @@ -0,0 +1,45 @@ +package org.simantics.modeling.ui.typicals; + +import java.util.Map; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.ui.commands.IElementUpdater; +import org.eclipse.ui.menus.UIElement; +import org.osgi.service.prefs.BackingStoreException; +import org.osgi.service.prefs.Preferences; +import org.simantics.modeling.typicals.TypicalPreferences; +import org.simantics.utils.ui.ErrorLogger; + + +/** + * @author Tuukka Lehtonen + * + */ +public class ToggleTypicalRealtimeSync extends AbstractHandler implements IElementUpdater { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + Preferences prefs = InstanceScope.INSTANCE.getNode(TypicalPreferences.P_NODE); + boolean value = prefs.getBoolean(TypicalPreferences.P_REALTIME_TYPICAL_SYNC_ENABLED, TypicalPreferences.DEFAULT_REALTIME_TYPICAL_SYNC_ENABLED); + value = !value; + prefs.putBoolean(TypicalPreferences.P_REALTIME_TYPICAL_SYNC_ENABLED, value); + try { + prefs.flush(); + } catch (BackingStoreException e) { + ErrorLogger.defaultLogError(e); + } + + return null; + } + + @Override + public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) { + Preferences prefs = InstanceScope.INSTANCE.getNode(TypicalPreferences.P_NODE); + boolean value = prefs.getBoolean(TypicalPreferences.P_REALTIME_TYPICAL_SYNC_ENABLED, TypicalPreferences.DEFAULT_REALTIME_TYPICAL_SYNC_ENABLED); + element.setChecked( value ); + } + +}