KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > actions > variables > ShowTypesAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.actions.variables;
12
13
14 import org.eclipse.debug.internal.ui.DebugPluginImages;
15 import org.eclipse.debug.internal.ui.DebugUIPlugin;
16 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
17 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
18 import org.eclipse.debug.internal.ui.actions.ActionMessages;
19 import org.eclipse.debug.ui.IDebugModelPresentation;
20 import org.eclipse.debug.ui.IDebugUIConstants;
21 import org.eclipse.debug.ui.IDebugView;
22 import org.eclipse.jface.action.Action;
23 import org.eclipse.jface.action.IAction;
24 import org.eclipse.swt.custom.BusyIndicator;
25 import org.eclipse.ui.PlatformUI;
26
27 /**
28  * An action that toggles the state of a viewer to
29  * show/hide type names of variables.
30  * Only viewers that use a <code>VariableLabelProvider</code> to render its
31  * elements are effected.
32  */

33 public class ShowTypesAction extends Action {
34
35     private IDebugView fView;
36
37     public ShowTypesAction(IDebugView view) {
38         super(ActionMessages.ShowTypesAction_Show__Type_Names_1, IAction.AS_CHECK_BOX);
39         setView(view);
40         setToolTipText(ActionMessages.ShowTypesAction_Show_Type_Names);
41         setHoverImageDescriptor(DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_LCL_TYPE_NAMES));
42         setDisabledImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_TYPE_NAMES));
43         setImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_TYPE_NAMES));
44         setId(DebugUIPlugin.getUniqueIdentifier() + ".ShowTypesAction"); //$NON-NLS-1$
45
PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.SHOW_TYPES_ACTION);
46     }
47
48     /**
49      * @see Action#run()
50      */

51     public void run() {
52         valueChanged(isChecked());
53     }
54
55     private void valueChanged(boolean on) {
56         if (getView().getViewer().getControl().isDisposed()) {
57             return;
58         }
59         
60         IDebugModelPresentation debugLabelProvider= (IDebugModelPresentation)getView().getAdapter(IDebugModelPresentation.class);
61         if (debugLabelProvider != null) {
62             debugLabelProvider.setAttribute(IDebugModelPresentation.DISPLAY_VARIABLE_TYPE_NAMES, (on ? Boolean.TRUE : Boolean.FALSE));
63             BusyIndicator.showWhile(getView().getViewer().getControl().getDisplay(), new Runnable JavaDoc() {
64                 public void run() {
65                     getView().getViewer().refresh();
66                 }
67             });
68         }
69     }
70     
71     protected IDebugView getView() {
72         return fView;
73     }
74
75     protected void setView(IDebugView view) {
76         fView = view;
77     }
78
79     /* (non-Javadoc)
80      * @see org.eclipse.jface.action.Action#setEnabled(boolean)
81      */

82     public void setEnabled(boolean enabled) {
83         super.setEnabled(enabled);
84         if (enabled) {
85             setToolTipText(ActionMessages.ShowTypesAction_Show_Type_Names);
86         } else {
87             setToolTipText(ActionMessages.ShowTypesAction_0);
88         }
89     }
90     
91     
92 }
93
94
95
Popular Tags