1 11 12 package org.eclipse.jface.preference; 13 14 import org.eclipse.jface.action.Action; 15 import org.eclipse.jface.util.IPropertyChangeListener; 16 import org.eclipse.jface.util.PropertyChangeEvent; 17 18 22 23 public class BooleanPropertyAction extends Action { 24 25 private IPreferenceStore preferenceStore; 26 27 private String property; 28 29 37 public BooleanPropertyAction(String title, 38 IPreferenceStore preferenceStore, String property) 39 throws IllegalArgumentException { 40 super(title, AS_CHECK_BOX); 41 42 if (preferenceStore == null || property == null) { 43 throw new IllegalArgumentException (); 44 } 45 46 this.preferenceStore = preferenceStore; 47 this.property = property; 48 final String finalProprety = property; 49 50 preferenceStore 51 .addPropertyChangeListener(new IPropertyChangeListener() { 52 public void propertyChange(PropertyChangeEvent event) { 53 if (finalProprety.equals(event.getProperty())) { 54 setChecked(Boolean.TRUE.equals(event.getNewValue())); 55 } 56 } 57 }); 58 59 setChecked(preferenceStore.getBoolean(property)); 60 } 61 62 66 public void run() { 67 preferenceStore.setValue(property, isChecked()); 68 } 69 } 70 | Popular Tags |