1 /*******************************************************************************
2 * Copyright (c) 2005, 2008 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
9 * IBM - Initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.cdt.internal.ui.util;
13 import java.util.ArrayList;
14 import java.util.Iterator;
15 import java.util.List;
17 import org.eclipse.core.resources.IMarker;
18 import org.eclipse.core.resources.ResourcesPlugin;
19 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.jface.action.IAction;
21 import org.eclipse.jface.viewers.ISelection;
22 import org.eclipse.jface.viewers.IStructuredSelection;
23 import org.eclipse.ui.IObjectActionDelegate;
24 import org.eclipse.ui.IWorkbenchPart;
25 import org.eclipse.ui.actions.ActionDelegate;
27 import org.eclipse.cdt.core.model.ICModelMarker;
30 * @author Bogdan Gheorghe
32 public class DeleteIProblemMarkerAction extends ActionDelegate implements IObjectActionDelegate {
34 private IStructuredSelection selection;
37 * @see ActionDelegate#run(IAction)
40 public void run(IAction action) {
42 if (selection != null) {
43 if (selection.isEmpty()) {
47 List<?> list = selection.toList();
48 List<IMarker> listMarkers = new ArrayList<IMarker>();
49 Iterator<?> iterator = list.iterator();
50 while (iterator.hasNext()) {
51 IMarker marker = (IMarker)iterator.next();
52 if (marker.isSubtypeOf(ICModelMarker.INDEXER_MARKER)) {
53 listMarkers.add(marker);
57 if (listMarkers.isEmpty()) {
60 IMarker[] markers = new IMarker[listMarkers.size()];
61 listMarkers.toArray(markers);
62 // be sure to only invoke one workspace operation
63 ResourcesPlugin.getWorkspace().deleteMarkers(markers);
65 } catch (CoreException e) {
71 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
73 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
77 public void selectionChanged(IAction action, ISelection selection) {
78 boolean enable = false;
79 if (selection instanceof IStructuredSelection) {
80 Object object = ((IStructuredSelection) selection).getFirstElement();
81 if (object instanceof IMarker) {
83 IMarker marker = (IMarker) object;
84 if (marker.isSubtypeOf(ICModelMarker.INDEXER_MARKER)) {
87 this.selection = (IStructuredSelection)selection;
88 action.setEnabled(enable);
89 } catch (CoreException e) {