KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > markers > internal > ActionRemoveMarker


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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
12 package org.eclipse.ui.views.markers.internal;
13
14 import java.util.Iterator JavaDoc;
15
16 import org.eclipse.jface.viewers.ISelectionProvider;
17 import org.eclipse.jface.viewers.IStructuredSelection;
18 import org.eclipse.osgi.util.NLS;
19 import org.eclipse.ui.ISharedImages;
20 import org.eclipse.ui.IWorkbenchPart;
21 import org.eclipse.ui.PlatformUI;
22 import org.eclipse.ui.ide.undo.DeleteMarkersOperation;
23 import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
24
25 /**
26  * Action to remove the selected bookmarks.
27  */

28 public class ActionRemoveMarker extends MarkerSelectionProviderAction {
29
30     private IWorkbenchPart part;
31     
32     private String JavaDoc markerName;
33
34     /**
35      * Creates the action.
36      *
37      * @param part
38      * @param provider
39      * @param markerName
40      * the name describing the specific kind of marker being removed
41      */

42     public ActionRemoveMarker(IWorkbenchPart part, ISelectionProvider provider,
43             String JavaDoc markerName) {
44         super(provider, MarkerMessages.deleteAction_title);
45         this.part = part;
46         this.markerName = markerName;
47         setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
48                 .getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
49         setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
50                 .getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED));
51         setToolTipText(MarkerMessages.deleteAction_tooltip);
52         setEnabled(false);
53     }
54
55     /**
56      * Delete the marker selection.
57      */

58     public void run() {
59         String JavaDoc operationTitle = NLS.bind(MarkerMessages.qualifiedMarkerCommand_title,
60                 MarkerMessages.deleteAction_title, markerName);
61         DeleteMarkersOperation op = new DeleteMarkersOperation(
62                 getSelectedMarkers(), operationTitle);
63         execute(op, MarkerMessages.RemoveMarker_errorTitle, null,
64                 WorkspaceUndoUtil.getUIInfoAdapter(part.getSite().getShell()));
65     }
66
67     public void selectionChanged(IStructuredSelection selection) {
68         setEnabled(false);
69         if (selection == null || selection.isEmpty()) {
70             return;
71         }
72         for (Iterator JavaDoc iterator = selection.iterator(); iterator.hasNext();) {
73             Object JavaDoc obj = iterator.next();
74             if (!(obj instanceof ConcreteMarker)) {
75                 return;
76             }
77
78             if (!Util.isEditable(((ConcreteMarker) obj).getMarker())) {
79                 return;
80             }
81         }
82         setEnabled(true);
83     }
84 }
85
Popular Tags