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 java.util.Map;
013:
014: import org.eclipse.core.resources.IResource;
015: import org.eclipse.core.runtime.CoreException;
016: import org.eclipse.core.runtime.IAdaptable;
017: import org.eclipse.core.runtime.IProgressMonitor;
018: import org.eclipse.core.runtime.IStatus;
019: import org.eclipse.core.runtime.NullProgressMonitor;
020: import org.eclipse.ui.internal.ide.undo.MarkerDescription;
021: import org.eclipse.ui.internal.ide.undo.UndoMessages;
022:
023: /**
024: * A CreateMarkersOperation represents an undoable operation for creating one or
025: * more markers on one or more resources in the workspace. Clients may call the
026: * public API from a background thread.
027: *
028: * This class is intended to be instantiated and used by clients. It is not
029: * intended to be subclassed by clients.
030: *
031: * @since 3.3
032: *
033: */
034: public class CreateMarkersOperation extends AbstractMarkersOperation {
035:
036: /**
037: * Create an undoable operation that can create a marker of a specific type
038: * on a resource.
039: *
040: * @param type
041: * the type of marker to be created
042: * @param attributes
043: * the map of attributes that should be assigned to the marker
044: * @param resource
045: * the resource on which the marker should be created
046: * @param name
047: * the name used to describe the operation that creates the
048: * marker
049: *
050: * @see org.eclipse.core.resources.IMarker
051: */
052: public CreateMarkersOperation(String type, Map attributes,
053: IResource resource, String name) {
054: super (null, new MarkerDescription[] { new MarkerDescription(
055: type, attributes, resource) }, null, name);
056: }
057:
058: /**
059: * Create an undoable operation that can create multiple markers of various
060: * types on multiple resources.
061: *
062: * @param types
063: * an array describing the types of markers to be created
064: * @param attributes
065: * an array of maps of attributes that should be assigned to each
066: * created marker, corresponding to each marker type described
067: * @param resources
068: * an array of resources describing the resource on which the
069: * corresponding marker type should be created
070: * @param name
071: * the name used to describe the operation that creates the
072: * markers
073: */
074: public CreateMarkersOperation(String[] types, Map[] attributes,
075: IResource[] resources, String name) {
076: super (null, null, null, name);
077: MarkerDescription[] markersToCreate = new MarkerDescription[attributes.length];
078: for (int i = 0; i < markersToCreate.length; i++) {
079: markersToCreate[i] = new MarkerDescription(types[i],
080: attributes[i], resources[i]);
081: }
082: setMarkerDescriptions(markersToCreate);
083: }
084:
085: /**
086: * Create an undoable operation that can create multiple markers of a single
087: * type on multiple resources.
088: *
089: * @param type
090: * the type of markers to be created
091: * @param attributes
092: * an array of maps of attributes that should be assigned to each
093: * created marker
094: * @param resources
095: * an array of resources describing the resource on which the
096: * marker with the corresponding attributes should be created
097: * @param name
098: * the name used to describe the operation that creates the
099: * markers
100: */
101: public CreateMarkersOperation(String type, Map[] attributes,
102: IResource[] resources, String name) {
103: super (null, null, null, name);
104: MarkerDescription[] markersToCreate = new MarkerDescription[attributes.length];
105: for (int i = 0; i < markersToCreate.length; i++) {
106: markersToCreate[i] = new MarkerDescription(type,
107: attributes[i], resources[i]);
108: }
109: setMarkerDescriptions(markersToCreate);
110: }
111:
112: /*
113: * (non-Javadoc)
114: *
115: * This implementation creates markers
116: *
117: * @see org.eclipse.ui.ide.undo.AbstractWorkspaceOperation#doExecute(org.eclipse.core.runtime.IProgressMonitor,
118: * org.eclipse.core.runtime.IAdaptable)
119: */
120: protected void doExecute(IProgressMonitor monitor, IAdaptable info)
121: throws CoreException {
122: if (monitor == null) {
123: monitor = new NullProgressMonitor();
124: }
125: monitor.beginTask("", 100); //$NON-NLS-1$
126: monitor
127: .setTaskName(UndoMessages.MarkerOperation_CreateProgress);
128: createMarkers(100, monitor);
129: monitor.done();
130: }
131:
132: /*
133: * (non-Javadoc)
134: *
135: * This implementation deletes markers
136: *
137: * @see org.eclipse.ui.ide.undo.AbstractWorkspaceOperation#doUndo(org.eclipse.core.runtime.IProgressMonitor,
138: * org.eclipse.core.runtime.IAdaptable)
139: */
140: protected void doUndo(IProgressMonitor monitor, IAdaptable info)
141: throws CoreException {
142: if (monitor == null) {
143: monitor = new NullProgressMonitor();
144: }
145: monitor.beginTask("", 100); //$NON-NLS-1$
146: monitor
147: .setTaskName(UndoMessages.MarkerOperation_DeleteProgress);
148: deleteMarkers(100, monitor);
149: monitor.done();
150: }
151:
152: /*
153: * (non-Javadoc)
154: *
155: * This implementation maps the undo status to the deletion status.
156: *
157: * @see org.eclipse.ui.ide.undo.AbstractMarkersOperation#getBasicUndoStatus()
158: */
159: protected IStatus getBasicUndoStatus() {
160: return getMarkerDeletionStatus();
161: }
162:
163: /*
164: * (non-Javadoc)
165: *
166: * This implementation maps the redo status to the creation status.
167: *
168: * @see org.eclipse.ui.ide.undo.AbstractMarkersOperation#getBasicRedoStatus()
169: */
170: protected IStatus getBasicRedoStatus() {
171: return getMarkerCreationStatus();
172: }
173: }
|