]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/typicals/ToggleTypicalRealtimeSync.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / typicals / ToggleTypicalRealtimeSync.java
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 (file)
index 0000000..bb50636
--- /dev/null
@@ -0,0 +1,45 @@
+package org.simantics.modeling.ui.typicals;\r
+\r
+import java.util.Map;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.core.runtime.preferences.InstanceScope;\r
+import org.eclipse.ui.commands.IElementUpdater;\r
+import org.eclipse.ui.menus.UIElement;\r
+import org.osgi.service.prefs.BackingStoreException;\r
+import org.osgi.service.prefs.Preferences;\r
+import org.simantics.modeling.typicals.TypicalPreferences;\r
+import org.simantics.utils.ui.ErrorLogger;\r
+\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ *\r
+ */\r
+public class ToggleTypicalRealtimeSync extends AbstractHandler implements IElementUpdater {\r
+\r
+       @Override\r
+    public Object execute(ExecutionEvent event) throws ExecutionException {\r
+        Preferences prefs = InstanceScope.INSTANCE.getNode(TypicalPreferences.P_NODE);\r
+        boolean value = prefs.getBoolean(TypicalPreferences.P_REALTIME_TYPICAL_SYNC_ENABLED, TypicalPreferences.DEFAULT_REALTIME_TYPICAL_SYNC_ENABLED);\r
+        value = !value;\r
+        prefs.putBoolean(TypicalPreferences.P_REALTIME_TYPICAL_SYNC_ENABLED, value);\r
+        try {\r
+            prefs.flush();\r
+        } catch (BackingStoreException e) {\r
+            ErrorLogger.defaultLogError(e);\r
+        }\r
+\r
+        return null;\r
+    }\r
+\r
+    @Override\r
+    public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) {\r
+        Preferences prefs = InstanceScope.INSTANCE.getNode(TypicalPreferences.P_NODE);\r
+        boolean value = prefs.getBoolean(TypicalPreferences.P_REALTIME_TYPICAL_SYNC_ENABLED, TypicalPreferences.DEFAULT_REALTIME_TYPICAL_SYNC_ENABLED);\r
+        element.setChecked( value );\r
+    }\r
+\r
+}\r