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.IResource;
013: import org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory;
014: import org.eclipse.core.runtime.CoreException;
015: import org.eclipse.core.runtime.IAdaptable;
016: import org.eclipse.core.runtime.IProgressMonitor;
017: import org.eclipse.core.runtime.IStatus;
018: import org.eclipse.core.runtime.jobs.ISchedulingRule;
019:
020: /**
021: * A CreateResourcesOperation represents an undoable operation for creating
022: * resources in the workspace. Clients may call the public API from a background
023: * thread.
024: *
025: * This class is not intended to be subclassed by clients.
026: *
027: * @since 3.3
028: *
029: */
030: abstract class AbstractCreateResourcesOperation extends
031: AbstractResourcesOperation {
032:
033: /**
034: * Create an AbstractCreateResourcesOperation.
035: *
036: * @param resourceDescriptions
037: * the resourceDescriptions describing resources to be created
038: * @param label
039: * the label of the operation
040: */
041: AbstractCreateResourcesOperation(
042: ResourceDescription[] resourceDescriptions, String label) {
043: super (resourceDescriptions, label);
044: }
045:
046: /*
047: * (non-Javadoc)
048: *
049: * This implementation creates resources from the known resource
050: * descriptions.
051: *
052: * @see org.eclipse.ui.ide.undo.AbstractWorkspaceOperation#doExecute(org.eclipse.core.runtime.IProgressMonitor,
053: * org.eclipse.core.runtime.IAdaptable)
054: */
055: protected void doExecute(IProgressMonitor monitor, IAdaptable uiInfo)
056: throws CoreException {
057: recreate(monitor, uiInfo);
058: }
059:
060: /*
061: * (non-Javadoc)
062: *
063: * This implementation deletes resources.
064: *
065: * @see org.eclipse.ui.ide.undo.AbstractWorkspaceOperation#doUndo(org.eclipse.core.runtime.IProgressMonitor,
066: * org.eclipse.core.runtime.IAdaptable)
067: */
068: protected void doUndo(IProgressMonitor monitor, IAdaptable uiInfo)
069: throws CoreException {
070: delete(monitor, uiInfo, false); // never delete content
071: }
072:
073: /*
074: * (non-Javadoc)
075: *
076: * This implementation documents the impending create or delete.
077: *
078: * @see org.eclipse.ui.ide.undo.AbstractWorkspaceOperation#updateResourceChangeDescriptionFactory(org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory,
079: * int)
080: */
081: protected boolean updateResourceChangeDescriptionFactory(
082: IResourceChangeDescriptionFactory factory, int operation) {
083: boolean modified = false;
084: if (operation == UNDO) {
085: for (int i = 0; i < resources.length; i++) {
086: IResource resource = resources[i];
087: factory.delete(resource);
088: modified = true;
089: }
090: } else {
091: for (int i = 0; i < resourceDescriptions.length; i++) {
092: IResource resource = resourceDescriptions[i]
093: .createResourceHandle();
094: factory.create(resource);
095: modified = true;
096: }
097: }
098: return modified;
099: }
100:
101: /*
102: * (non-Javadoc)
103: *
104: * @see org.eclipse.ui.ide.undo.AbstractWorkspaceOperation#getExecuteSchedulingRule()
105: */
106: protected ISchedulingRule getExecuteSchedulingRule() {
107: return super .computeCreateSchedulingRule();
108: }
109:
110: /*
111: * (non-Javadoc)
112: *
113: * @see org.eclipse.ui.ide.undo.AbstractWorkspaceOperation#getUndoSchedulingRule()
114: */
115: protected ISchedulingRule getUndoSchedulingRule() {
116: return super .computeDeleteSchedulingRule();
117: }
118:
119: /*
120: * (non-Javadoc)
121: *
122: * This implementation computes the status for creating resources.
123: *
124: * @see org.eclipse.ui.ide.undo.AbstractWorkspaceOperation#computeExecutionStatus(org.eclipse.core.runtime.IProgressMonitor)
125: */
126: public IStatus computeExecutionStatus(IProgressMonitor monitor) {
127: IStatus status = super .computeExecutionStatus(monitor);
128: if (status.isOK()) {
129: status = computeCreateStatus(true);
130: }
131: return status;
132: }
133:
134: /*
135: * (non-Javadoc)
136: *
137: * This implementation computes the status for deleting resources.
138: *
139: * @see org.eclipse.ui.ide.undo.AbstractWorkspaceOperation#computeUndoableStatus(org.eclipse.core.runtime.IProgressMonitor)
140: */
141: public IStatus computeUndoableStatus(IProgressMonitor monitor) {
142: IStatus status = super .computeUndoableStatus(monitor);
143: if (status.isOK()) {
144: status = computeDeleteStatus();
145: }
146: return status;
147: }
148:
149: /*
150: * (non-Javadoc)
151: *
152: * This implementation computes the status for creating resources.
153: *
154: * @see org.eclipse.ui.ide.undo.AbstractWorkspaceOperation#computeRedoableStatus(org.eclipse.core.runtime.IProgressMonitor)
155: */
156: public IStatus computeRedoableStatus(IProgressMonitor monitor) {
157: IStatus status = super .computeRedoableStatus(monitor);
158: if (status.isOK()) {
159: status = computeCreateStatus(true);
160: }
161: return status;
162: }
163: }
|