KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > javaeditor > ToggleTextHoverAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
32  * A toolbar action which toggles the enabling state of the
33  * editor's text hover.
34  */

35 public class ToggleTextHoverAction extends TextEditorAction implements IPropertyChangeListener {
36
37
38     private IPreferenceStore fStore;
39
40     /**
41      * Constructs and updates the action.
42      */

43     public ToggleTextHoverAction() {
44         super(JavaEditorMessages.getBundleForConstructedKeys(), "ToggleTextHover.", null); //$NON-NLS-1$
45
JavaPluginImages.setToolImageDescriptors(this, "jdoc_hover_edit.gif"); //$NON-NLS-1$
46
setActionDefinitionId(IJavaEditorActionDefinitionIds.TOGGLE_TEXT_HOVER);
47         PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.TOGGLE_TEXTHOVER_ACTION);
48         update();
49     }
50
51     /*
52      * @see IAction#actionPerformed
53      */

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     /*
68      * @see TextEditorAction#update
69      */

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     /*
77      * @see TextEditorAction#setEditor(ITextEditor)
78      */

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     /*
94      * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
95      */

96     public void propertyChange(PropertyChangeEvent event) {
97         if (event.getProperty().equals(PreferenceConstants.EDITOR_SHOW_HOVER))
98             update();
99     }
100 }
101
Popular Tags