KickJava   Java API By Example, From Geeks To Geeks.

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


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.IMarker;
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.UndoMessages;
23
24 /**
25  * An UpdateMarkersOperation represents an undoable operation for updating one
26  * or more markers in the workspace with one or more sets of attributes. Clients
27  * may call the public API from a background thread.
28  *
29  * This class is intended to be instantiated and used by clients. It is not
30  * intended to be subclassed by clients.
31  *
32  * @since 3.3
33  *
34  */

35 public class UpdateMarkersOperation extends AbstractMarkersOperation {
36
37     // Whether attributes should be merged with existing attributes when
38
// updated, or considered to be complete replacements.
39
private boolean mergeAttributes;
40
41     /**
42      * Create an undoable operation that can update the specified marker with
43      * the specified attributes.
44      *
45      * @param marker
46      * the marker to be updated
47      * @param attributes
48      * the map of attributes to be assigned to the marker. This map
49      * does not replace the attribute map of the marker, but instead,
50      * each attribute in the map is added or updated with the current
51      * value in the map. In other words
52      * @param name
53      * the name used to describe this operation
54      * @param mergeAttributes
55      * <code>true</code> if the specified map of attributes for the
56      * marker is to be merged with the attributes already specified
57      * for the marker, or <code>false</code> if the specified map
58      * of attributes is to be considered a complete replacement of
59      * all attributes of the marker
60      */

61     public UpdateMarkersOperation(IMarker marker, Map JavaDoc attributes, String JavaDoc name,
62             boolean mergeAttributes) {
63         super(new IMarker[] { marker }, null, attributes, name);
64         this.mergeAttributes = mergeAttributes;
65     }
66
67     /**
68      * Create an undoable operation that updates many markers to have the same
69      * set of attributes.
70      *
71      * @param markers
72      * the markers to be updated
73      * @param attributes
74      * the map of attributes to be assigned to each marker
75      * @param name
76      * the name used to describe this operation
77      * @param mergeAttributes
78      * <code>true</code> if the specified map of attributes for
79      * each marker is to be merged with the attributes already
80      * specified for that marker, or <code>false</code> if the
81      * specified map of attributes is to be considered a complete
82      * replacement of all attributes for each marker
83      */

84     public UpdateMarkersOperation(IMarker[] markers, Map JavaDoc attributes,
85             String JavaDoc name, boolean mergeAttributes) {
86         super(markers, null, attributes, name);
87         this.mergeAttributes = mergeAttributes;
88     }
89
90     /*
91      * (non-Javadoc)
92      *
93      * Map execution to updating the markers.
94      *
95      * @see org.eclipse.ui.ide.undo.AbstractWorkspaceOperation#doExecute(org.eclipse.core.runtime.IProgressMonitor,
96      * org.eclipse.core.runtime.IAdaptable)
97      */

98     protected void doExecute(IProgressMonitor monitor, IAdaptable info)
99             throws CoreException {
100         if (monitor == null) {
101             monitor = new NullProgressMonitor();
102         }
103         monitor.beginTask("", 100); //$NON-NLS-1$
104
monitor.setTaskName(UndoMessages.MarkerOperation_UpdateProgress);
105         updateMarkers(100, monitor, mergeAttributes);
106         monitor.done();
107     }
108
109     /*
110      * (non-Javadoc)
111      *
112      * Map undo to execute (since both operations update the markers).
113      *
114      * @see org.eclipse.ui.ide.undo.AbstractWorkspaceOperation#doUndo(org.eclipse.core.runtime.IProgressMonitor,
115      * org.eclipse.core.runtime.IAdaptable)
116      */

117     protected void doUndo(IProgressMonitor monitor, IAdaptable info)
118             throws CoreException {
119         // doExecute simply swaps the current and remembered attributes,
120
// so it can also be used for undo
121
doExecute(monitor, info);
122     }
123
124     /*
125      * (non-Javadoc)
126      *
127      * Map undo status to marker update status.
128      *
129      * @see org.eclipse.ui.ide.undo.AbstractMarkersOperation#getBasicUndoStatus()
130      */

131     protected IStatus getBasicUndoStatus() {
132         return getMarkerUpdateStatus();
133     }
134
135     /*
136      * (non-Javadoc)
137      *
138      * Map redo status to marker update status.
139      *
140      * @see org.eclipse.ui.ide.undo.AbstractMarkersOperation#getBasicRedoStatus()
141      */

142     protected IStatus getBasicRedoStatus() {
143         return getMarkerUpdateStatus();
144     }
145 }
146
Popular Tags