KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.core.resources.IResource;
15 import org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IAdaptable;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.core.runtime.IStatus;
20 import org.eclipse.core.runtime.jobs.ISchedulingRule;
21
22 /**
23  * A CreateResourcesOperation represents an undoable operation for creating
24  * resources in the workspace. Clients may call the public API from a background
25  * thread.
26  *
27  * This class is not intended to be subclassed by clients.
28  *
29  * @since 3.3
30  *
31  */

32 abstract class AbstractCreateResourcesOperation extends
33         AbstractResourcesOperation {
34
35     /**
36      * Create an AbstractCreateResourcesOperation.
37      *
38      * @param resourceDescriptions
39      * the resourceDescriptions describing resources to be created
40      * @param label
41      * the label of the operation
42      */

43     AbstractCreateResourcesOperation(
44             ResourceDescription[] resourceDescriptions, String JavaDoc label) {
45         super(resourceDescriptions, label);
46     }
47
48     /*
49      * (non-Javadoc)
50      *
51      * This implementation creates resources from the known resource
52      * descriptions.
53      *
54      * @see org.eclipse.ui.ide.undo.AbstractWorkspaceOperation#doExecute(org.eclipse.core.runtime.IProgressMonitor,
55      * org.eclipse.core.runtime.IAdaptable)
56      */

57     protected void doExecute(IProgressMonitor monitor, IAdaptable uiInfo)
58             throws CoreException {
59         recreate(monitor, uiInfo);
60     }
61
62     /*
63      * (non-Javadoc)
64      *
65      * This implementation deletes resources.
66      *
67      * @see org.eclipse.ui.ide.undo.AbstractWorkspaceOperation#doUndo(org.eclipse.core.runtime.IProgressMonitor,
68      * org.eclipse.core.runtime.IAdaptable)
69      */

70     protected void doUndo(IProgressMonitor monitor, IAdaptable uiInfo)
71             throws CoreException {
72         delete(monitor, uiInfo, false); // never delete content
73
}
74
75     /*
76      * (non-Javadoc)
77      *
78      * This implementation documents the impending create or delete.
79      *
80      * @see org.eclipse.ui.ide.undo.AbstractWorkspaceOperation#updateResourceChangeDescriptionFactory(org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory,
81      * int)
82      */

83     protected boolean updateResourceChangeDescriptionFactory(
84             IResourceChangeDescriptionFactory factory, int operation) {
85         boolean modified = false;
86         if (operation == UNDO) {
87             for (int i = 0; i < resources.length; i++) {
88                 IResource resource = resources[i];
89                 factory.delete(resource);
90                 modified = true;
91             }
92         } else {
93             for (int i = 0; i < resourceDescriptions.length; i++) {
94                 IResource resource = resourceDescriptions[i]
95                         .createResourceHandle();
96                 factory.create(resource);
97                 modified = true;
98             }
99         }
100         return modified;
101     }
102
103     /*
104      * (non-Javadoc)
105      *
106      * @see org.eclipse.ui.ide.undo.AbstractWorkspaceOperation#getExecuteSchedulingRule()
107      */

108     protected ISchedulingRule getExecuteSchedulingRule() {
109         return super.computeCreateSchedulingRule();
110     }
111
112     /*
113      * (non-Javadoc)
114      *
115      * @see org.eclipse.ui.ide.undo.AbstractWorkspaceOperation#getUndoSchedulingRule()
116      */

117     protected ISchedulingRule getUndoSchedulingRule() {
118         return super.computeDeleteSchedulingRule();
119     }
120
121     /*
122      * (non-Javadoc)
123      *
124      * This implementation computes the status for creating resources.
125      *
126      * @see org.eclipse.ui.ide.undo.AbstractWorkspaceOperation#computeExecutionStatus(org.eclipse.core.runtime.IProgressMonitor)
127      */

128     public IStatus computeExecutionStatus(IProgressMonitor monitor) {
129         IStatus status = super.computeExecutionStatus(monitor);
130         if (status.isOK()) {
131             status = computeCreateStatus(true);
132         }
133         return status;
134     }
135
136     /*
137      * (non-Javadoc)
138      *
139      * This implementation computes the status for deleting resources.
140      *
141      * @see org.eclipse.ui.ide.undo.AbstractWorkspaceOperation#computeUndoableStatus(org.eclipse.core.runtime.IProgressMonitor)
142      */

143     public IStatus computeUndoableStatus(IProgressMonitor monitor) {
144         IStatus status = super.computeUndoableStatus(monitor);
145         if (status.isOK()) {
146             status = computeDeleteStatus();
147         }
148         return status;
149     }
150
151     /*
152      * (non-Javadoc)
153      *
154      * This implementation computes the status for creating resources.
155      *
156      * @see org.eclipse.ui.ide.undo.AbstractWorkspaceOperation#computeRedoableStatus(org.eclipse.core.runtime.IProgressMonitor)
157      */

158     public IStatus computeRedoableStatus(IProgressMonitor monitor) {
159         IStatus status = super.computeRedoableStatus(monitor);
160         if (status.isOK()) {
161             status = computeCreateStatus(true);
162         }
163         return status;
164     }
165 }
166
Popular Tags