1 11 package org.eclipse.jdt.internal.ui.javaeditor; 12 13 14 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 import org.eclipse.jdt.ui.actions.IJavaEditorActionDefinitionIds; 25 26 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 27 import org.eclipse.jdt.internal.ui.JavaPlugin; 28 import org.eclipse.jdt.internal.ui.JavaPluginImages; 29 30 31 35 public class ToggleTextHoverAction extends TextEditorAction implements IPropertyChangeListener { 36 37 38 private IPreferenceStore fStore; 39 40 43 public ToggleTextHoverAction() { 44 super(JavaEditorMessages.getBundleForConstructedKeys(), "ToggleTextHover.", null); JavaPluginImages.setToolImageDescriptors(this, "jdoc_hover_edit.gif"); setActionDefinitionId(IJavaEditorActionDefinitionIds.TOGGLE_TEXT_HOVER); 47 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.TOGGLE_TEXTHOVER_ACTION); 48 update(); 49 } 50 51 54 public void run() { 55 ITextEditor editor= getTextEditor(); 56 if (editor == null) 57 return; 58 59 boolean showHover= !fStore.getBoolean(PreferenceConstants.EDITOR_SHOW_HOVER); 60 setChecked(showHover); 61 62 fStore.removePropertyChangeListener(this); 63 fStore.setValue(PreferenceConstants.EDITOR_SHOW_HOVER, showHover); 64 fStore.addPropertyChangeListener(this); 65 } 66 67 70 public void update() { 71 boolean showHover= fStore != null && fStore.getBoolean(PreferenceConstants.EDITOR_SHOW_HOVER); 72 setChecked(showHover); 73 setEnabled(getTextEditor() != null); 74 } 75 76 79 public void setEditor(ITextEditor editor) { 80 super.setEditor(editor); 81 if (editor != null) { 82 if (fStore == null) { 83 fStore= JavaPlugin.getDefault().getPreferenceStore(); 84 fStore.addPropertyChangeListener(this); 85 } 86 } else if (fStore != null) { 87 fStore.removePropertyChangeListener(this); 88 fStore= null; 89 } 90 update(); 91 } 92 93 96 public void propertyChange(PropertyChangeEvent event) { 97 if (event.getProperty().equals(PreferenceConstants.EDITOR_SHOW_HOVER)) 98 update(); 99 } 100 } 101 | Popular Tags |