001: /*******************************************************************************
002: * Copyright (c) 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.IFile;
013: import org.eclipse.core.resources.IFolder;
014: import org.eclipse.core.resources.IProject;
015: import org.eclipse.core.resources.IResource;
016: import org.eclipse.core.runtime.CoreException;
017: import org.eclipse.core.runtime.IProgressMonitor;
018: import org.eclipse.ui.internal.ide.undo.FileDescription;
019: import org.eclipse.ui.internal.ide.undo.FolderDescription;
020: import org.eclipse.ui.internal.ide.undo.ProjectDescription;
021:
022: /**
023: * ResourceDescription is a lightweight description that describes the common
024: * attributes of a resource to be created.
025: *
026: * This class is not intended to be extended by clients.
027: *
028: * @since 3.3
029: *
030: */
031: public abstract class ResourceDescription {
032:
033: /**
034: * Create a resource description given the specified resource. The resource
035: * is assumed to exist.
036: *
037: * @param resource
038: * the resource from which a description should be created
039: * @return the resource description
040: */
041: public static ResourceDescription fromResource(IResource resource) {
042: if (resource.getType() == IResource.PROJECT) {
043: return new ProjectDescription((IProject) resource);
044: } else if (resource.getType() == IResource.FOLDER) {
045: return new FolderDescription((IFolder) resource);
046: } else if (resource.getType() == IResource.FILE) {
047: return new FileDescription((IFile) resource);
048: } else {
049: throw new IllegalArgumentException();
050: }
051: }
052:
053: /**
054: * Create a resource handle that can be used to create a resource from this
055: * resource description. This handle can be used to create the actual
056: * resource, or to describe the creation to a resource delta factory.
057: *
058: * @return the resource handle that can be used to create a resource from
059: * this description
060: */
061: public abstract IResource createResourceHandle();
062:
063: /**
064: * Get the name of this resource.
065: *
066: * @return the name of the Resource
067: */
068: public abstract String getName();
069:
070: /**
071: * Create an existent resource from this resource description.
072: *
073: * @param monitor
074: * the progress monitor to use
075: * @return a resource that has the attributes of this resource description
076: * @throws CoreException
077: */
078: public abstract IResource createResource(IProgressMonitor monitor)
079: throws CoreException;
080:
081: /**
082: * Given a resource handle, create an actual resource with the attributes of
083: * the receiver resource description.
084: *
085: * @param resource
086: * the resource handle
087: * @param monitor
088: * the progress monitor to be used when creating the resource
089: * @throws CoreException
090: */
091: public abstract void createExistentResourceFromHandle(
092: IResource resource, IProgressMonitor monitor)
093: throws CoreException;
094:
095: /**
096: * Return a boolean indicating whether this resource description has enough
097: * information to create a resource.
098: *
099: * @return <code>true</code> if the resource can be created, and
100: * <code>false</code> if it does not have enough information
101: */
102: public abstract boolean isValid();
103:
104: /**
105: * Record the appropriate state of this resource description using
106: * any available resource history.
107: *
108: * @param resource
109: * the resource whose state is to be recorded.
110: * @param monitor
111: * the progress monitor to be used
112: * @throws CoreException
113: */
114: public abstract void recordStateFromHistory(IResource resource,
115: IProgressMonitor monitor) throws CoreException;
116:
117: /**
118: * Return a boolean indicating whether this description represents an
119: * existent resource.
120: *
121: * @param checkMembers
122: * Use <code>true</code> if members should also exist in order
123: * for this description to be considered existent. A value of
124: * <code>false</code> indicates that the existence of members
125: * does not matter.
126: *
127: * @return a boolean indicating whether this description represents an
128: * existent resource.
129: */
130: public abstract boolean verifyExistence(boolean checkMembers);
131: }
|