KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 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.IFile;
15 import org.eclipse.core.resources.IFolder;
16 import org.eclipse.core.resources.IProject;
17 import org.eclipse.core.resources.IResource;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.ui.internal.ide.undo.FileDescription;
21 import org.eclipse.ui.internal.ide.undo.FolderDescription;
22 import org.eclipse.ui.internal.ide.undo.ProjectDescription;
23
24 /**
25  * ResourceDescription is a lightweight description that describes the common
26  * attributes of a resource to be created.
27  *
28  * This class is not intended to be extended by clients.
29  *
30  * @since 3.3
31  *
32  */

33 public abstract class ResourceDescription {
34
35     /**
36      * Create a resource description given the specified resource. The resource
37      * is assumed to exist.
38      *
39      * @param resource
40      * the resource from which a description should be created
41      * @return the resource description
42      */

43     public static ResourceDescription fromResource(IResource resource) {
44         if (resource.getType() == IResource.PROJECT) {
45             return new ProjectDescription((IProject) resource);
46         } else if (resource.getType() == IResource.FOLDER) {
47             return new FolderDescription((IFolder) resource);
48         } else if (resource.getType() == IResource.FILE) {
49             return new FileDescription((IFile) resource);
50         } else {
51             throw new IllegalArgumentException JavaDoc();
52         }
53     }
54     
55     /**
56      * Create a resource handle that can be used to create a resource from this
57      * resource description. This handle can be used to create the actual
58      * resource, or to describe the creation to a resource delta factory.
59      *
60      * @return the resource handle that can be used to create a resource from
61      * this description
62      */

63     public abstract IResource createResourceHandle();
64
65     /**
66      * Get the name of this resource.
67      *
68      * @return the name of the Resource
69      */

70     public abstract String JavaDoc getName();
71     
72     /**
73      * Create an existent resource from this resource description.
74      *
75      * @param monitor
76      * the progress monitor to use
77      * @return a resource that has the attributes of this resource description
78      * @throws CoreException
79      */

80     public abstract IResource createResource(IProgressMonitor monitor) throws CoreException;
81     
82     /**
83      * Given a resource handle, create an actual resource with the attributes of
84      * the receiver resource description.
85      *
86      * @param resource
87      * the resource handle
88      * @param monitor
89      * the progress monitor to be used when creating the resource
90      * @throws CoreException
91      */

92     public abstract void createExistentResourceFromHandle(IResource resource,
93             IProgressMonitor monitor) throws CoreException;
94     
95     /**
96      * Return a boolean indicating whether this resource description has enough
97      * information to create a resource.
98      *
99      * @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 }
132
Popular Tags