1 11 package org.eclipse.debug.internal.ui.views.console; 12 13 import org.eclipse.debug.internal.ui.DebugUIPlugin; 14 import org.eclipse.jface.action.Action; 15 import org.eclipse.jface.action.IAction; 16 import org.eclipse.jface.preference.IPreferenceStore; 17 import org.eclipse.jface.util.IPropertyChangeListener; 18 import org.eclipse.jface.util.PropertyChangeEvent; 19 20 26 public abstract class ShowWhenContentChangesAction extends Action implements IPropertyChangeListener{ 27 28 31 public ShowWhenContentChangesAction(String name) { 32 super(name, IAction.AS_CHECK_BOX); 33 setToolTipText(name); 34 getPreferenceStore().addPropertyChangeListener(this); 35 update(); 36 } 37 38 41 public void propertyChange(PropertyChangeEvent event) { 42 String property = event.getProperty(); 43 if (property.equals(getKey())) { 44 update(); 45 } 46 } 47 48 protected abstract String getKey(); 49 50 private void update() { 51 IPreferenceStore store = getPreferenceStore(); 52 if (store.getBoolean(getKey())) { 53 setChecked(true); 55 } else { 56 setChecked(false); 58 } 59 } 60 61 64 private IPreferenceStore getPreferenceStore() { 65 return DebugUIPlugin.getDefault().getPreferenceStore(); 66 } 67 68 71 public void run() { 72 IPreferenceStore store = getPreferenceStore(); 73 boolean show = isChecked(); 74 store.removePropertyChangeListener(this); 75 store.setValue(getKey(), show); 76 store.addPropertyChangeListener(this); 77 } 78 79 82 public void dispose() { 83 getPreferenceStore().removePropertyChangeListener(this); 84 } 85 86 } 87 | Popular Tags |