1 /*******************************************************************************
2  * Copyright (c) 2000, 2012 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.jdt.internal.debug.ui.actions;
15 
16 
17 import java.util.List;
18 
19 import org.eclipse.jdt.internal.debug.ui.launcher.IClasspathViewer;
20 import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
21 import org.eclipse.jface.action.IAction;
22 import org.eclipse.jface.viewers.IStructuredSelection;
23 import org.eclipse.ui.actions.SelectionListenerAction;
24 
25 /**
26  * Removes selected entries in a runtime classpath viewer.
27  */
28 public class RemoveAction extends RuntimeClasspathAction {
29 
RemoveAction(IClasspathViewer viewer)30 	public RemoveAction(IClasspathViewer viewer) {
31 		super(ActionMessages.RemoveAction__Remove_1, viewer);
32 	}
33 	/**
34 	 * Removes all selected entries.
35 	 *
36 	 * @see IAction#run()
37 	 */
38 	@Override
run()39 	public void run() {
40 		List<IRuntimeClasspathEntry> targets = getOrderedSelection();
41 		List<IRuntimeClasspathEntry> list = getEntriesAsList();
42 		list.removeAll(targets);
43 		setEntries(list);
44 	}
45 
46 	/**
47 	 * @see SelectionListenerAction#updateSelection(IStructuredSelection)
48 	 */
49 	@Override
updateSelection(IStructuredSelection selection)50 	protected boolean updateSelection(IStructuredSelection selection) {
51 		if (selection.isEmpty()) {
52 			return false;
53 		}
54 		return getViewer().updateSelection(getActionType(), selection);
55 	}
56 
57 	@Override
getActionType()58 	protected int getActionType() {
59 		return REMOVE;
60 	}
61 }
62