1 11 package org.eclipse.ant.internal.ui.editor.actions; 12 13 import org.eclipse.ant.internal.ui.AntUIImages; 14 import org.eclipse.ant.internal.ui.AntUIPlugin; 15 import org.eclipse.ant.internal.ui.IAntUIConstants; 16 import org.eclipse.ant.internal.ui.editor.AntEditor; 17 import org.eclipse.ant.internal.ui.model.AntModel; 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 31 public class ToggleAutoReconcileAction extends TextEditorAction implements IPropertyChangeListener { 32 33 private IPreferenceStore fStore; 34 35 38 public ToggleAutoReconcileAction() { 39 super(AntEditorActionMessages.getResourceBundle(), "ToggleAutoReconcileAction.", null, IAction.AS_CHECK_BOX); setImageDescriptor(AntUIImages.getImageDescriptor(IAntUIConstants.IMG_REFRESH)); 41 setToolTipText(AntEditorActionMessages.getString("ToggleAutoReconcileAction.tooltip")); update(); 43 } 44 45 48 public void run() { 49 ITextEditor editor= getTextEditor(); 50 if (editor instanceof AntEditor) { 51 AntModel model= ((AntEditor) editor).getAntModel(); 52 model.setShouldReconcile(isChecked()); 53 fStore.setValue(AntEditorPreferenceConstants.EDITOR_RECONCILE, isChecked()); 54 } 55 } 56 57 60 public void update() { 61 ITextEditor editor= getTextEditor(); 62 63 boolean checked= false; 64 boolean enabled= false; 65 if (editor instanceof AntEditor) { 66 AntModel model= ((AntEditor)editor).getAntModel(); 67 enabled= model != null; 68 checked= enabled && fStore.getBoolean(AntEditorPreferenceConstants.EDITOR_RECONCILE); 69 if (model != null) { 70 model.setShouldReconcile(checked); 71 } 72 } 73 74 setChecked(checked); 75 setEnabled(enabled); 76 } 77 78 81 public void setEditor(ITextEditor editor) { 82 83 super.setEditor(editor); 84 85 if (editor != null) { 86 if (fStore == null) { 87 fStore= AntUIPlugin.getDefault().getPreferenceStore(); 88 fStore.addPropertyChangeListener(this); 89 } 90 } else if (fStore != null) { 91 fStore.removePropertyChangeListener(this); 92 fStore= null; 93 } 94 95 update(); 96 } 97 98 101 public void propertyChange(PropertyChangeEvent event) { 102 if (event.getProperty().equals(AntEditorPreferenceConstants.EDITOR_RECONCILE)) { 103 setChecked(Boolean.valueOf(event.getNewValue().toString()).booleanValue()); 104 } 105 } 106 } | Popular Tags |