01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.views.markers.internal;
11:
12: import java.util.Iterator;
13:
14: import org.eclipse.jface.viewers.ISelectionProvider;
15: import org.eclipse.jface.viewers.IStructuredSelection;
16: import org.eclipse.osgi.util.NLS;
17: import org.eclipse.ui.ISharedImages;
18: import org.eclipse.ui.IWorkbenchPart;
19: import org.eclipse.ui.PlatformUI;
20: import org.eclipse.ui.ide.undo.DeleteMarkersOperation;
21: import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
22:
23: /**
24: * Action to remove the selected bookmarks.
25: */
26: public class ActionRemoveMarker extends MarkerSelectionProviderAction {
27:
28: private IWorkbenchPart part;
29:
30: private String markerName;
31:
32: /**
33: * Creates the action.
34: *
35: * @param part
36: * @param provider
37: * @param markerName
38: * the name describing the specific kind of marker being removed
39: */
40: public ActionRemoveMarker(IWorkbenchPart part,
41: ISelectionProvider provider, String markerName) {
42: super (provider, MarkerMessages.deleteAction_title);
43: this .part = part;
44: this .markerName = markerName;
45: setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
46: .getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
47: setDisabledImageDescriptor(PlatformUI.getWorkbench()
48: .getSharedImages().getImageDescriptor(
49: ISharedImages.IMG_TOOL_DELETE_DISABLED));
50: setToolTipText(MarkerMessages.deleteAction_tooltip);
51: setEnabled(false);
52: }
53:
54: /**
55: * Delete the marker selection.
56: */
57: public void run() {
58: String operationTitle = NLS.bind(
59: 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()
65: .getShell()));
66: }
67:
68: public void selectionChanged(IStructuredSelection selection) {
69: setEnabled(false);
70: if (selection == null || selection.isEmpty()) {
71: return;
72: }
73: for (Iterator iterator = selection.iterator(); iterator
74: .hasNext();) {
75: Object obj = iterator.next();
76: if (!(obj instanceof ConcreteMarker)) {
77: return;
78: }
79:
80: if (!Util.isEditable(((ConcreteMarker) obj).getMarker())) {
81: return;
82: }
83: }
84: setEnabled(true);
85: }
86: }
|