1 11 package org.eclipse.jdt.internal.ui.javaeditor; 12 13 14 import org.eclipse.jface.action.IAction; 15 import org.eclipse.jface.preference.IPreferenceStore; 16 import org.eclipse.jface.util.IPropertyChangeListener; 17 import org.eclipse.jface.util.PropertyChangeEvent; 18 19 import org.eclipse.ui.PlatformUI; 20 import org.eclipse.ui.texteditor.ITextEditor; 21 import org.eclipse.ui.texteditor.TextEditorAction; 22 23 import org.eclipse.jdt.ui.PreferenceConstants; 24 25 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 26 import org.eclipse.jdt.internal.ui.JavaPlugin; 27 import org.eclipse.jdt.internal.ui.JavaPluginImages; 28 29 30 35 public class ToggleMarkOccurrencesAction extends TextEditorAction implements IPropertyChangeListener { 36 37 private IPreferenceStore fStore; 38 39 42 public ToggleMarkOccurrencesAction() { 43 super(JavaEditorMessages.getBundleForConstructedKeys(), "ToggleMarkOccurrencesAction.", null, IAction.AS_CHECK_BOX); JavaPluginImages.setToolImageDescriptors(this, "mark_occurrences.gif"); PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.TOGGLE_MARK_OCCURRENCES_ACTION); 46 update(); 47 } 48 49 52 public void run() { 53 fStore.setValue(PreferenceConstants.EDITOR_MARK_OCCURRENCES, isChecked()); 54 } 55 56 59 public void update() { 60 ITextEditor editor= getTextEditor(); 61 62 boolean checked= false; 63 if (editor instanceof JavaEditor) 64 checked= ((JavaEditor)editor).isMarkingOccurrences(); 65 66 setChecked(checked); 67 setEnabled(editor != null); 68 } 69 70 73 public void setEditor(ITextEditor editor) { 74 75 super.setEditor(editor); 76 77 if (editor != null) { 78 79 if (fStore == null) { 80 fStore= JavaPlugin.getDefault().getPreferenceStore(); 81 fStore.addPropertyChangeListener(this); 82 } 83 84 } else if (fStore != null) { 85 fStore.removePropertyChangeListener(this); 86 fStore= null; 87 } 88 89 update(); 90 } 91 92 95 public void propertyChange(PropertyChangeEvent event) { 96 if (event.getProperty().equals(PreferenceConstants.EDITOR_MARK_OCCURRENCES)) 97 setChecked(Boolean.valueOf(event.getNewValue().toString()).booleanValue()); 98 } 99 } 100 | Popular Tags |