1 11 package org.eclipse.ant.internal.ui.editor.actions; 12 13 14 import org.eclipse.ant.internal.ui.AntUIImages; 15 import org.eclipse.ant.internal.ui.AntUIPlugin; 16 import org.eclipse.ant.internal.ui.IAntUIConstants; 17 import org.eclipse.ant.internal.ui.editor.AntEditor; 18 import org.eclipse.ant.internal.ui.preferences.AntEditorPreferenceConstants; 19 import org.eclipse.jface.action.IAction; 20 import org.eclipse.jface.preference.IPreferenceStore; 21 import org.eclipse.jface.util.IPropertyChangeListener; 22 import org.eclipse.jface.util.PropertyChangeEvent; 23 import org.eclipse.ui.texteditor.ITextEditor; 24 import org.eclipse.ui.texteditor.TextEditorAction; 25 26 27 32 public class ToggleMarkOccurrencesAction extends TextEditorAction implements IPropertyChangeListener { 33 34 private IPreferenceStore fStore; 35 36 39 public ToggleMarkOccurrencesAction() { 40 super(AntEditorActionMessages.getResourceBundle(), "ToggleMarkOccurrencesAction.", null, IAction.AS_CHECK_BOX); setImageDescriptor(AntUIImages.getImageDescriptor(IAntUIConstants.IMG_MARK_OCCURRENCES)); 42 setToolTipText(AntEditorActionMessages.getString("ToggleMarkOccurrencesAction.tooltip")); update(); 44 } 45 46 49 public void run() { 50 fStore.setValue(AntEditorPreferenceConstants.EDITOR_MARK_OCCURRENCES, isChecked()); 51 } 52 53 56 public void update() { 57 ITextEditor editor= getTextEditor(); 58 59 boolean checked= false; 60 boolean enabled= false; 61 if (editor instanceof AntEditor) { 62 checked= ((AntEditor)editor).isMarkingOccurrences(); 63 enabled= ((AntEditor)editor).getAntModel() != null; 64 } 65 66 setChecked(checked); 67 setEnabled(enabled); 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= AntUIPlugin.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(AntEditorPreferenceConstants.EDITOR_MARK_OCCURRENCES)) 97 setChecked(Boolean.valueOf(event.getNewValue().toString()).booleanValue()); 98 } 99 } | Popular Tags |