1 package org.simantics.modeling.ui.typicals;
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;
18 * @author Tuukka Lehtonen
21 public class ToggleTypicalRealtimeSync extends AbstractHandler implements IElementUpdater {
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);
28 prefs.putBoolean(TypicalPreferences.P_REALTIME_TYPICAL_SYNC_ENABLED, value);
31 } catch (BackingStoreException e) {
32 ErrorLogger.defaultLogError(e);
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 );