KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Iterator JavaDoc;
15
16 import org.eclipse.debug.core.DebugPlugin;
17 import org.eclipse.debug.core.IExpressionManager;
18 import org.eclipse.debug.core.model.IExpression;
19 import org.eclipse.debug.core.model.IWatchExpression;
20 import org.eclipse.jface.action.IAction;
21 import org.eclipse.jface.viewers.IStructuredSelection;
22
23 /**
24  * Convert one or more expressions to the equivalent watch expressions.
25  * Refresh and re-evaluate the expressions if possible.
26  */

27 public class ConvertToWatchExpressionAction extends WatchExpressionAction {
28
29     /**
30      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
31      */

32     public void run(IAction action) {
33         IStructuredSelection selection= getCurrentSelection();
34         IExpressionManager expressionManager= DebugPlugin.getDefault().getExpressionManager();
35         for (Iterator JavaDoc iter= selection.iterator(); iter.hasNext();) {
36             IExpression expression= (IExpression) iter.next();
37             // create the new watch expression
38
IWatchExpression watchExpression= expressionManager.newWatchExpression(expression.getExpressionText());
39             expressionManager.removeExpression(expression);
40             expressionManager.addExpression(watchExpression);
41             // refresh and re-evaluate
42
watchExpression.setExpressionContext(getContext());
43         }
44     }
45
46 }
47
Popular Tags