KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > actions > FindVariableAction


1 /*******************************************************************************
2  * Copyright (c) 2004, 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 implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.actions;
12
13 import org.eclipse.debug.core.DebugEvent;
14 import org.eclipse.debug.core.model.IStackFrame;
15 import org.eclipse.debug.internal.ui.DebugUIPlugin;
16 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
17 import org.eclipse.debug.internal.ui.views.variables.VariablesView;
18 import org.eclipse.jface.action.Action;
19 import org.eclipse.jface.action.IAction;
20 import org.eclipse.jface.viewers.ISelection;
21 import org.eclipse.jface.viewers.Viewer;
22 import org.eclipse.swt.widgets.Shell;
23 import org.eclipse.ui.PlatformUI;
24 import org.eclipse.ui.texteditor.IUpdate;
25 import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
26
27 /**
28  * Action which prompts the user to help them find a variable in
29  * the variables view.
30  */

31 public class FindVariableAction extends Action implements IUpdate {
32     
33     private class FindVariableDelegate extends AbstractListenerActionDelegate {
34
35         protected void doAction(Object JavaDoc element) {
36             VariablesView view= (VariablesView) getView();
37             Shell shell = view.getSite().getShell();
38             FindVariableDialog dialog= new FindVariableDialog(shell, view);
39             dialog.open();
40         }
41
42         protected void update(IAction action, ISelection s) {
43             if (action != null) {
44                 ((IUpdate) action).update();
45             }
46         }
47
48         protected void doHandleDebugEvent(DebugEvent event) {
49             update(getAction(), null);
50         }
51
52         public void run(IAction action) {
53             doAction(null);
54         }
55     }
56     
57     private AbstractListenerActionDelegate fDelegate;
58
59     public FindVariableAction(VariablesView view) {
60         setText(ActionMessages.FindVariableAction_0); //$NON-NLS-1$
61
setId(DebugUIPlugin.getUniqueIdentifier() + ".FindVariableAction"); //$NON-NLS-1$
62
PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.FIND_VARIABLE_ACTION);
63         setActionDefinitionId(IWorkbenchActionDefinitionIds.FIND_REPLACE);
64         fDelegate= new FindVariableDelegate();
65         fDelegate.init(view);
66         fDelegate.setAction(this);
67     }
68     
69     public void run() {
70         fDelegate.run(this);
71     }
72
73     public void update() {
74         VariablesView view= (VariablesView) fDelegate.getView();
75         if (view != null) {
76             Viewer viewer = view.getViewer();
77             if (viewer != null) {
78                 setEnabled(viewer.getInput() instanceof IStackFrame);
79                 return;
80             }
81         }
82         setEnabled(false);
83     }
84
85     public void dispose() {
86         fDelegate.dispose();
87     }
88 }
89
Popular Tags