1 package org.simantics.modeling.ui.typicals;
\r
3 import java.util.Map;
\r
5 import org.eclipse.core.commands.AbstractHandler;
\r
6 import org.eclipse.core.commands.ExecutionEvent;
\r
7 import org.eclipse.core.commands.ExecutionException;
\r
8 import org.eclipse.core.runtime.preferences.InstanceScope;
\r
9 import org.eclipse.ui.commands.IElementUpdater;
\r
10 import org.eclipse.ui.menus.UIElement;
\r
11 import org.osgi.service.prefs.BackingStoreException;
\r
12 import org.osgi.service.prefs.Preferences;
\r
13 import org.simantics.modeling.typicals.TypicalPreferences;
\r
14 import org.simantics.utils.ui.ErrorLogger;
\r
18 * @author Tuukka Lehtonen
\r
21 public class ToggleTypicalRealtimeSync extends AbstractHandler implements IElementUpdater {
\r
24 public Object execute(ExecutionEvent event) throws ExecutionException {
\r
25 Preferences prefs = InstanceScope.INSTANCE.getNode(TypicalPreferences.P_NODE);
\r
26 boolean value = prefs.getBoolean(TypicalPreferences.P_REALTIME_TYPICAL_SYNC_ENABLED, TypicalPreferences.DEFAULT_REALTIME_TYPICAL_SYNC_ENABLED);
\r
28 prefs.putBoolean(TypicalPreferences.P_REALTIME_TYPICAL_SYNC_ENABLED, value);
\r
31 } catch (BackingStoreException e) {
\r
32 ErrorLogger.defaultLogError(e);
\r
39 public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) {
\r
40 Preferences prefs = InstanceScope.INSTANCE.getNode(TypicalPreferences.P_NODE);
\r
41 boolean value = prefs.getBoolean(TypicalPreferences.P_REALTIME_TYPICAL_SYNC_ENABLED, TypicalPreferences.DEFAULT_REALTIME_TYPICAL_SYNC_ENABLED);
\r
42 element.setChecked( value );
\r