KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > commands > actions > ToggleStepFiltersAction


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 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.debug.internal.ui.commands.actions;
12
13 import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
14 import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
15 import org.eclipse.debug.core.DebugPlugin;
16 import org.eclipse.debug.core.commands.IStepFiltersHandler;
17 import org.eclipse.debug.internal.core.StepFilterManager;
18 import org.eclipse.debug.internal.ui.DebugPluginImages;
19 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
20 import org.eclipse.debug.internal.ui.actions.ActionMessages;
21 import org.eclipse.debug.ui.DebugUITools;
22 import org.eclipse.debug.ui.contexts.DebugContextEvent;
23 import org.eclipse.jface.resource.ImageDescriptor;
24 import org.eclipse.jface.viewers.ISelection;
25 import org.eclipse.ui.IWorkbenchPart;
26 import org.eclipse.ui.IWorkbenchWindow;
27
28 /**
29  * This class provides the action for toggling step filters on or off for the debug view
30  */

31 public class ToggleStepFiltersAction extends DebugCommandAction implements IPropertyChangeListener {
32     
33     private boolean fInitialized = !DebugUITools.isUseStepFilters();
34     
35     /**
36      * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#getDisabledImageDescriptor()
37      */

38     public ImageDescriptor getDisabledImageDescriptor() {
39         return DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_TOGGLE_STEP_FILTERS);
40     }
41
42     /**
43      * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#getHelpContextId()
44      */

45     public String JavaDoc getHelpContextId() {
46         return "org.eclipse.debug.ui.step_with_filters_action_context"; //$NON-NLS-1$
47
}
48
49     /**
50      * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#getHoverImageDescriptor()
51      */

52     public ImageDescriptor getHoverImageDescriptor() {
53         return DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_TOGGLE_STEP_FILTERS);
54     }
55
56     /**
57      * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#getId()
58      */

59     public String JavaDoc getId() {
60         return "org.eclipse.debug.ui.actions.ToggleStepFilters"; //$NON-NLS-1$
61
}
62
63     /**
64      * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#getImageDescriptor()
65      */

66     public ImageDescriptor getImageDescriptor() {
67         return DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_TOGGLE_STEP_FILTERS);
68     }
69
70     /**
71      * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#getText()
72      */

73     public String JavaDoc getText() {
74         return ActionMessages.ToggleStepFiltersAction_1;
75     }
76
77     /**
78      * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#getToolTipText()
79      */

80     public String JavaDoc getToolTipText() {
81         return ActionMessages.ToggleStepFiltersAction_0;
82     }
83
84     /**
85      * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#getInitialEnablement()
86      */

87     protected boolean getInitialEnablement() {
88         return true;
89     }
90
91     /**
92      * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#getCommandType()
93      */

94     protected Class JavaDoc getCommandType() {
95         return IStepFiltersHandler.class;
96     }
97
98     /**
99      * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#run()
100      */

101     public void run() {
102         // ignore initial call to run from abstract debug view
103
// that runs the action to initialize it's state when
104
// the workbench persisted the action as "on"
105
if (fInitialized) {
106             DebugUITools.setUseStepFilters(!DebugUITools.isUseStepFilters());
107         } else {
108             fInitialized = true;
109         }
110     }
111     
112     /**
113      * @see org.eclipse.jface.action.Action#getStyle()
114      */

115     public int getStyle() {
116         return AS_CHECK_BOX;
117     }
118
119     /**
120      * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#debugContextChanged(org.eclipse.debug.ui.contexts.DebugContextEvent)
121      */

122     public void debugContextChanged(DebugContextEvent event) {
123         ISelection context = event.getContext();
124         if (context.isEmpty()) {
125             setEnabled(true);
126         } else {
127             super.debugContextChanged(event);
128         }
129     }
130
131     /**
132      * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#init(org.eclipse.ui.IWorkbenchPart)
133      */

134     public void init(IWorkbenchPart part) {
135         super.init(part);
136         initState();
137     }
138
139     /**
140      * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#init(org.eclipse.ui.IWorkbenchWindow)
141      */

142     public void init(IWorkbenchWindow window) {
143         super.init(window);
144         initState();
145     }
146     
147     /**
148      * Initializes the state, by adding this action as a property listener
149      */

150     protected void initState() {
151         DebugPlugin.getDefault().getPluginPreferences().addPropertyChangeListener(this);
152     }
153
154     /**
155      * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction#dispose()
156      */

157     public void dispose() {
158         super.dispose();
159         DebugPlugin.getDefault().getPluginPreferences().removePropertyChangeListener(this);
160     }
161
162     /**
163      * @see org.eclipse.core.runtime.Preferences$IPropertyChangeListener#propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent)
164      */

165     public void propertyChange(PropertyChangeEvent event) {
166         if (event.getProperty().equals(StepFilterManager.PREF_USE_STEP_FILTERS)) {
167             boolean checked = DebugUITools.isUseStepFilters();
168             setChecked(checked);
169             DebugCommandActionDelegate delegate = getDelegate();
170             if (delegate != null) {
171                 delegate.setChecked(checked);
172             }
173         }
174     }
175     
176     
177 }
178
Popular Tags