001: /*******************************************************************************
002: * Copyright (c) 2006, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.ide.undo;
011:
012: import org.eclipse.core.resources.IMarker;
013: import org.eclipse.core.runtime.CoreException;
014: import org.eclipse.core.runtime.IAdaptable;
015: import org.eclipse.core.runtime.IProgressMonitor;
016: import org.eclipse.core.runtime.IStatus;
017: import org.eclipse.core.runtime.NullProgressMonitor;
018: import org.eclipse.ui.internal.ide.undo.UndoMessages;
019:
020: /**
021: * A DeleteMarkersOperation represents an undoable operation for deleting one or
022: * more markers in the workspace. Clients may call the public API from a
023: * background thread.
024: *
025: * This class is intended to be instantiated and used by clients. It is not
026: * intended to be subclassed by clients.
027: *
028: * @since 3.3
029: *
030: */
031: public class DeleteMarkersOperation extends AbstractMarkersOperation {
032:
033: /**
034: * Create an undoable operation that can delete the specified markers.
035: *
036: * @param markers
037: * the markers to be deleted
038: * @param name
039: * the name used to describe the operation that deletes the
040: * markers
041: */
042: public DeleteMarkersOperation(IMarker[] markers, String name) {
043: super (markers, null, null, name);
044: }
045:
046: /*
047: * (non-Javadoc)
048: *
049: * Map execution to marker deletion.
050: *
051: * @see org.eclipse.ui.ide.undo.AbstractWorkspaceOperation#doExecute(org.eclipse.core.runtime.IProgressMonitor,
052: * org.eclipse.core.runtime.IAdaptable)
053: */
054: protected void doExecute(IProgressMonitor monitor, IAdaptable info)
055: throws CoreException {
056: if (monitor == null) {
057: monitor = new NullProgressMonitor();
058: }
059: monitor.beginTask("", 100); //$NON-NLS-1$
060: monitor
061: .setTaskName(UndoMessages.MarkerOperation_DeleteProgress);
062: deleteMarkers(100, monitor);
063: monitor.done();
064: }
065:
066: /*
067: * (non-Javadoc)
068: *
069: * Map undo to marker creation.
070: *
071: * @see org.eclipse.ui.ide.undo.AbstractWorkspaceOperation#doUndo(org.eclipse.core.runtime.IProgressMonitor,
072: * org.eclipse.core.runtime.IAdaptable)
073: */
074: protected void doUndo(IProgressMonitor monitor, IAdaptable info)
075: throws CoreException {
076: if (monitor == null) {
077: monitor = new NullProgressMonitor();
078: }
079: monitor.beginTask("", 100); //$NON-NLS-1$
080: monitor
081: .setTaskName(UndoMessages.MarkerOperation_CreateProgress);
082: createMarkers(100, monitor);
083: monitor.done();
084: }
085:
086: /*
087: * (non-Javadoc)
088: *
089: * Map the undo status to marker creation status.
090: *
091: * @see org.eclipse.ui.ide.undo.AbstractMarkersOperation#getBasicUndoStatus()
092: */
093: protected IStatus getBasicUndoStatus() {
094: return getMarkerCreationStatus();
095: }
096:
097: /*
098: * (non-Javadoc)
099: *
100: * Map the redo status to marker deletion status.
101: *
102: * @see org.eclipse.ui.ide.undo.AbstractMarkersOperation#getBasicRedoStatus()
103: */
104: protected IStatus getBasicRedoStatus() {
105: return getMarkerDeletionStatus();
106: }
107: }
|