KickJava   Java API By Example, From Geeks To Geeks.

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


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;
12
13
14 import org.eclipse.debug.core.DebugPlugin;
15 import org.eclipse.debug.core.IExpressionManager;
16 import org.eclipse.debug.core.model.IExpression;
17 import org.eclipse.debug.ui.IDebugView;
18 import org.eclipse.jface.viewers.ITreeContentProvider;
19 import org.eclipse.jface.viewers.TreeViewer;
20 import org.eclipse.jface.viewers.Viewer;
21
22 public class RemoveExpressionAction extends AbstractRemoveActionDelegate {
23
24     protected void doAction(Object JavaDoc element) {
25         IExpressionManager manager = DebugPlugin.getDefault().getExpressionManager();
26         IExpression exp = getExpression(element);
27         if (exp != null) {
28             manager.removeExpression(exp);
29         }
30     }
31     
32     /**
33      * Returns the expression associated with the given
34      * element.
35      *
36      * @param element an expression of child of an expression in
37      * the expression view.
38      * @return associated expression
39      */

40     protected IExpression getExpression(Object JavaDoc obj) {
41         if (getView() == null) {
42             return null;
43         }
44         IDebugView adapter= (IDebugView)getView().getAdapter(IDebugView.class);
45         if (adapter != null) {
46             Viewer v= adapter.getViewer();
47             if (v instanceof TreeViewer) {
48                 ITreeContentProvider cp = (ITreeContentProvider)((TreeViewer)v).getContentProvider();
49                 while (!(obj instanceof IExpression) && obj != null) {
50                     obj = cp.getParent(obj);
51                 }
52                 return (IExpression)obj;
53             }
54         }
55         return null;
56     }
57 }
58
59
Popular Tags