]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/typicals/ToggleTypicalRealtimeSync.java
Red background color & tooltip for invalid derived property expression
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / typicals / ToggleTypicalRealtimeSync.java
1 package org.simantics.modeling.ui.typicals;
2
3 import java.util.Map;
4
5 import org.eclipse.core.commands.AbstractHandler;
6 import org.eclipse.core.commands.ExecutionEvent;
7 import org.eclipse.core.commands.ExecutionException;
8 import org.eclipse.core.runtime.preferences.InstanceScope;
9 import org.eclipse.ui.commands.IElementUpdater;
10 import org.eclipse.ui.menus.UIElement;
11 import org.osgi.service.prefs.BackingStoreException;
12 import org.osgi.service.prefs.Preferences;
13 import org.simantics.modeling.typicals.TypicalPreferences;
14 import org.simantics.utils.ui.ErrorLogger;
15
16
17 /**
18  * @author Tuukka Lehtonen
19  *
20  */
21 public class ToggleTypicalRealtimeSync extends AbstractHandler implements IElementUpdater {
22
23         @Override
24     public Object execute(ExecutionEvent event) throws ExecutionException {
25         Preferences prefs = InstanceScope.INSTANCE.getNode(TypicalPreferences.P_NODE);
26         boolean value = prefs.getBoolean(TypicalPreferences.P_REALTIME_TYPICAL_SYNC_ENABLED, TypicalPreferences.DEFAULT_REALTIME_TYPICAL_SYNC_ENABLED);
27         value = !value;
28         prefs.putBoolean(TypicalPreferences.P_REALTIME_TYPICAL_SYNC_ENABLED, value);
29         try {
30             prefs.flush();
31         } catch (BackingStoreException e) {
32             ErrorLogger.defaultLogError(e);
33         }
34
35         return null;
36     }
37
38     @Override
39     public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) {
40         Preferences prefs = InstanceScope.INSTANCE.getNode(TypicalPreferences.P_NODE);
41         boolean value = prefs.getBoolean(TypicalPreferences.P_REALTIME_TYPICAL_SYNC_ENABLED, TypicalPreferences.DEFAULT_REALTIME_TYPICAL_SYNC_ENABLED);
42         element.setChecked( value );
43     }
44
45 }