1 11 12 package org.eclipse.jface.commands; 13 14 import org.eclipse.jface.menus.IMenuStateIds; 15 import org.eclipse.jface.preference.IPreferenceStore; 16 17 32 public class ToggleState extends PersistentState { 33 34 38 public ToggleState() { 39 setValue(Boolean.FALSE); 40 } 41 42 public final void load(final IPreferenceStore store, 43 final String preferenceKey) { 44 final boolean currentValue = ((Boolean ) getValue()).booleanValue(); 45 store.setDefault(preferenceKey, currentValue); 46 if (shouldPersist() && (store.contains(preferenceKey))) { 47 final boolean value = store.getBoolean(preferenceKey); 48 setValue(value ? Boolean.TRUE : Boolean.FALSE); 49 } 50 } 51 52 public final void save(final IPreferenceStore store, 53 final String preferenceKey) { 54 if (shouldPersist()) { 55 final Object value = getValue(); 56 if (value instanceof Boolean ) { 57 store.setValue(preferenceKey, ((Boolean ) value).booleanValue()); 58 } 59 } 60 } 61 62 public void setValue(final Object value) { 63 if (!(value instanceof Boolean )) { 64 throw new IllegalArgumentException ( 65 "ToggleState takes a Boolean as a value"); } 67 68 super.setValue(value); 69 } 70 } 71 | Popular Tags |