1 /*******************************************************************************2 * Copyright (c) 2000, 2006 IBM Corporation and others.3 * All rights reserved. This program and the accompanying materials4 * are made available under the terms of the Eclipse Public License v1.05 * which accompanies this distribution, and is available at6 * http://www.eclipse.org/legal/epl-v10.html7 *8 * Contributors:9 * IBM Corporation - initial API and implementation10 *******************************************************************************/11 package org.eclipse.debug.internal.ui.actions.expressions;12 13 14 import java.util.ArrayList ;15 import java.util.List ;16 17 import org.eclipse.core.runtime.IProgressMonitor;18 import org.eclipse.core.runtime.IStatus;19 import org.eclipse.core.runtime.Status;20 import org.eclipse.debug.core.DebugPlugin;21 import org.eclipse.debug.core.IExpressionManager;22 import org.eclipse.debug.core.model.IExpression;23 import org.eclipse.debug.internal.ui.actions.AbstractRemoveActionDelegate;24 import org.eclipse.jface.action.IAction;25 import org.eclipse.jface.viewers.TreePath;26 import org.eclipse.jface.viewers.TreeSelection;27 import org.eclipse.ui.progress.WorkbenchJob;28 29 public class RemoveExpressionAction extends AbstractRemoveActionDelegate {30 31 protected IExpression[] getExpressions() {32 TreeSelection selection = (TreeSelection) getSelection();33 TreePath[] paths = selection.getPaths();34 List expressions = new ArrayList ();35 for (int i = paths.length-1; i >=0; i--) {36 TreePath path = paths[i];37 Object segment = path.getFirstSegment();38 if (segment instanceof IExpression) {39 expressions.add(segment);40 }41 }42 return (IExpression[]) expressions.toArray(new IExpression[expressions.size()]);43 }44 45 /* (non-Javadoc)46 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)47 */48 public void run(IAction action) {49 WorkbenchJob job = new WorkbenchJob("remove expression") { //$NON-NLS-1$50 public IStatus runInUIThread(IProgressMonitor monitor) {51 IExpressionManager expManager = DebugPlugin.getDefault().getExpressionManager();52 IExpression[] exp = getExpressions();53 if (exp != null) {54 expManager.removeExpressions(exp);55 }56 return Status.OK_STATUS;57 }58 };59 job.setSystem(true);60 schedule(job);61 }62 }63 64