KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > ide > undo > CreateMarkersOperation


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 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.ide.undo;
13
14 import java.util.Map JavaDoc;
15
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IAdaptable;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.core.runtime.IStatus;
21 import org.eclipse.core.runtime.NullProgressMonitor;
22 import org.eclipse.ui.internal.ide.undo.MarkerDescription;
23 import org.eclipse.ui.internal.ide.undo.UndoMessages;
24
25 /**
26  * A CreateMarkersOperation represents an undoable operation for creating one or
27  * more markers on one or more resources in the workspace. Clients may call the
28  * public API from a background thread.
29  *
30  * This class is intended to be instantiated and used by clients. It is not
31  * intended to be subclassed by clients.
32  *
33  * @since 3.3
34  *
35  */

36 public class CreateMarkersOperation extends AbstractMarkersOperation {
37
38     /**
39      * Create an undoable operation that can create a marker of a specific type
40      * on a resource.
41      *
42      * @param type
43      * the type of marker to be created
44      * @param attributes
45      * the map of attributes that should be assigned to the marker
46      * @param resource
47      * the resource on which the marker should be created
48      * @param name
49      * the name used to describe the operation that creates the
50      * marker
51      *
52      * @see org.eclipse.core.resources.IMarker
53      */

54     public CreateMarkersOperation(String JavaDoc type, Map JavaDoc attributes,
55             IResource resource, String JavaDoc name) {
56         super(null, new MarkerDescription[] { new MarkerDescription(type,
57                 attributes, resource) }, null, name);
58     }
59
60     /**
61      * Create an undoable operation that can create multiple markers of various
62      * types on multiple resources.
63      *
64      * @param types
65      * an array describing the types of markers to be created
66      * @param attributes
67      * an array of maps of attributes that should be assigned to each
68      * created marker, corresponding to each marker type described
69      * @param resources
70      * an array of resources describing the resource on which the
71      * corresponding marker type should be created
72      * @param name
73      * the name used to describe the operation that creates the
74      * markers
75      */

76     public CreateMarkersOperation(String JavaDoc[] types, Map JavaDoc[] attributes,
77             IResource[] resources, String JavaDoc name) {
78         super(null, null, null, name);
79         MarkerDescription[] markersToCreate = new MarkerDescription[attributes.length];
80         for (int i = 0; i < markersToCreate.length; i++) {
81             markersToCreate[i] = new MarkerDescription(types[i], attributes[i],
82                     resources[i]);
83         }
84         setMarkerDescriptions(markersToCreate);
85     }
86
87     /**
88      * Create an undoable operation that can create multiple markers of a single
89      * type on multiple resources.
90      *
91      * @param type
92      * the type of markers to be created
93      * @param attributes
94      * an array of maps of attributes that should be assigned to each
95      * created marker
96      * @param resources
97      * an array of resources describing the resource on which the
98      * marker with the corresponding attributes should be created
99      * @param name
100      * the name used to describe the operation that creates the
101      * markers
102      */

103     public CreateMarkersOperation(String JavaDoc type, Map JavaDoc[] attributes,
104             IResource[] resources, String JavaDoc name) {
105         super(null, null, null, name);
106         MarkerDescription[] markersToCreate = new MarkerDescription[attributes.length];
107         for (int i = 0; i < markersToCreate.length; i++) {
108             markersToCreate[i] = new MarkerDescription(type, attributes[i],
109                     resources[i]);
110         }
111         setMarkerDescriptions(markersToCreate);
112     }
113
114     /*
115      * (non-Javadoc)
116      *
117      * This implementation creates markers
118      *
119      * @see org.eclipse.ui.ide.undo.AbstractWorkspaceOperation#doExecute(org.eclipse.core.runtime.IProgressMonitor,
120      * org.eclipse.core.runtime.IAdaptable)
121      */

122     protected void doExecute(IProgressMonitor monitor, IAdaptable info)
123             throws CoreException {
124         if (monitor == null) {
125             monitor = new NullProgressMonitor();
126         }
127         monitor.beginTask("", 100); //$NON-NLS-1$
128
monitor.setTaskName(UndoMessages.MarkerOperation_CreateProgress);
129         createMarkers(100, monitor);
130         monitor.done();
131     }
132
133     /*
134      * (non-Javadoc)
135      *
136      * This implementation deletes markers
137      *
138      * @see org.eclipse.ui.ide.undo.AbstractWorkspaceOperation#doUndo(org.eclipse.core.runtime.IProgressMonitor,
139      * org.eclipse.core.runtime.IAdaptable)
140      */

141     protected void doUndo(IProgressMonitor monitor, IAdaptable info)
142             throws CoreException {
143         if (monitor == null) {
144             monitor = new NullProgressMonitor();
145         }
146         monitor.beginTask("", 100); //$NON-NLS-1$
147
monitor.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 }
174
Popular Tags