1 11 12 package org.eclipse.ui.views.markers.internal; 13 14 import java.util.Iterator ; 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 28 public class ActionRemoveMarker extends MarkerSelectionProviderAction { 29 30 private IWorkbenchPart part; 31 32 private String markerName; 33 34 42 public ActionRemoveMarker(IWorkbenchPart part, ISelectionProvider provider, 43 String 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 58 public void run() { 59 String 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 iterator = selection.iterator(); iterator.hasNext();) { 73 Object 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 |