KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > actions > expressions > WatchExpressionAction


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.debug.internal.ui.actions.expressions;
12
13 import org.eclipse.core.runtime.IAdaptable;
14 import org.eclipse.debug.core.ILaunch;
15 import org.eclipse.debug.core.model.IDebugElement;
16 import org.eclipse.debug.internal.ui.DebugUIPlugin;
17 import org.eclipse.debug.ui.DebugUITools;
18 import org.eclipse.jface.action.IAction;
19 import org.eclipse.jface.action.IStatusLineManager;
20 import org.eclipse.jface.viewers.ISelection;
21 import org.eclipse.jface.viewers.IStructuredSelection;
22 import org.eclipse.swt.widgets.Display;
23 import org.eclipse.swt.widgets.Event;
24 import org.eclipse.ui.IActionDelegate2;
25 import org.eclipse.ui.IObjectActionDelegate;
26 import org.eclipse.ui.IViewPart;
27 import org.eclipse.ui.IViewSite;
28 import org.eclipse.ui.IWorkbenchPage;
29 import org.eclipse.ui.IWorkbenchPart;
30
31 /**
32  * Generic abstract class for the actions associated to the java watch
33  * expressions.
34  */

35 public abstract class WatchExpressionAction implements IObjectActionDelegate, IActionDelegate2 {
36     IWorkbenchPart fPart = null;
37     /**
38      * Finds the currently selected context in the UI.
39      */

40     protected IDebugElement getContext() {
41         IAdaptable object = DebugUITools.getDebugContext();
42         IDebugElement context = null;
43         if (object instanceof IDebugElement) {
44             context = (IDebugElement) object;
45         } else if (object instanceof ILaunch) {
46             context = ((ILaunch) object).getDebugTarget();
47         }
48         return context;
49     }
50     /**
51      * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
52      */

53     public void setActivePart(IAction action, IWorkbenchPart targetPart) {
54         fPart = targetPart;
55     }
56
57     /**
58         * @see IActionDelegate#selectionChanged(IAction, ISelection)
59         */

60     public void selectionChanged(IAction action, ISelection sel) {
61     }
62
63     protected IStructuredSelection getCurrentSelection() {
64         IWorkbenchPage page = DebugUIPlugin.getActiveWorkbenchWindow().getActivePage();
65         if (page != null) {
66             ISelection selection = page.getSelection();
67             if (selection instanceof IStructuredSelection) {
68                 return (IStructuredSelection) selection;
69             }
70         }
71         return null;
72     }
73
74     /**
75         * Displays the given error message in the status line.
76         *
77         * @param message
78         */

79     protected void showErrorMessage(String JavaDoc message) {
80         if (fPart instanceof IViewPart) {
81             IViewSite viewSite = ((IViewPart) fPart).getViewSite();
82             IStatusLineManager manager = viewSite.getActionBars().getStatusLineManager();
83             manager.setErrorMessage(message);
84             Display.getCurrent().beep();
85         }
86     }
87
88     /* (non-Javadoc)
89         * @see org.eclipse.ui.IActionDelegate2#dispose()
90         */

91     public void dispose() {
92         fPart = null;
93     }
94
95     /* (non-Javadoc)
96         * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
97         */

98     public void init(IAction action) {
99     }
100
101     /* (non-Javadoc)
102         * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
103         */

104     public void runWithEvent(IAction action, Event event) {
105         run(action);
106     }
107 }
108
Popular Tags