KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > heapwalking > AllReferencesInViewActionDelegate


1 /*******************************************************************************
2  * Copyright (c) 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.jdt.internal.debug.ui.heapwalking;
12
13 import org.eclipse.core.runtime.IStatus;
14 import org.eclipse.core.runtime.Status;
15 import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
16 import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
17 import org.eclipse.debug.ui.IDebugView;
18 import org.eclipse.jdt.debug.core.IJavaStackFrame;
19 import org.eclipse.jdt.internal.debug.core.HeapWalkingManager;
20 import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin;
21 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
22 import org.eclipse.jface.action.IAction;
23 import org.eclipse.jface.viewers.ISelection;
24 import org.eclipse.swt.widgets.Event;
25 import org.eclipse.ui.IActionDelegate2;
26 import org.eclipse.ui.IViewActionDelegate;
27 import org.eclipse.ui.IViewPart;
28
29 /**
30  * Action delegate that turns on/off references being displayed as variables in the view.
31  *
32  * @since 3.3
33  */

34 public class AllReferencesInViewActionDelegate implements IPropertyChangeListener, IActionDelegate2, IViewActionDelegate {
35
36     private IAction fAction;
37     private IDebugView fView;
38     
39     /* (non-Javadoc)
40      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
41      */

42     public void run(IAction action) {
43         HeapWalkingManager.getDefault().setShowReferenceInVarView(action.isChecked());
44         // If the current target doesn't support instance retrieval, warn the user that turning the option on will not do anything.
45
if (action.isChecked() && fView.getViewer() != null){
46             if (fView.getViewer().getInput() instanceof IJavaStackFrame){
47                 if (!HeapWalkingManager.supportsHeapWalking(fView.getViewer().getInput())){
48                     JDIDebugUIPlugin.statusDialog(Messages.AllReferencesInViewActionDelegate_0,new Status(IStatus.WARNING,JDIDebugUIPlugin.getUniqueIdentifier(),Messages.AllReferencesInViewActionDelegate_1));
49                 }
50             }
51         }
52     }
53     
54     /* (non-Javadoc)
55      * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
56      */

57     public void init(IAction action) {
58         fAction = action;
59         action.setChecked(HeapWalkingManager.getDefault().isShowReferenceInVarView());
60         JDIDebugPlugin.getDefault().getPluginPreferences().addPropertyChangeListener(this);
61     }
62
63     /* (non-Javadoc)
64      * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
65      */

66     public void init(IViewPart view) {
67         if (view instanceof IDebugView){
68             fView = (IDebugView)view;
69         }
70     }
71
72     /* (non-Javadoc)
73      * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
74      */

75     public void selectionChanged(IAction action, ISelection selection) {
76     }
77
78     /* (non-Javadoc)
79      * @see org.eclipse.ui.IActionDelegate2#dispose()
80      */

81     public void dispose() {
82         JDIDebugPlugin.getDefault().getPluginPreferences().removePropertyChangeListener(this);
83     }
84
85     /* (non-Javadoc)
86      * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
87      */

88     public void runWithEvent(IAction action, Event event) {
89         run(action);
90     }
91
92     /* (non-Javadoc)
93      * @see org.eclipse.core.runtime.Preferences$IPropertyChangeListener#propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent)
94      */

95     public void propertyChange(PropertyChangeEvent event) {
96         if (JDIDebugPlugin.PREF_SHOW_REFERENCES_IN_VAR_VIEW.equals(event.getProperty()) || JDIDebugPlugin.PREF_ALL_REFERENCES_MAX_COUNT.equals(event.getProperty())){
97             if (fAction != null){
98                 fAction.setChecked(HeapWalkingManager.getDefault().isShowReferenceInVarView());
99                 fView.getViewer().refresh();
100             }
101         }
102     }
103 }
104
Popular Tags