KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ide > undo > FolderDescription


1 /*******************************************************************************
2  * Copyright (c) 2006 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.internal.ide.undo;
13
14 import java.net.URI JavaDoc;
15
16 import org.eclipse.core.resources.IFolder;
17 import org.eclipse.core.resources.IResource;
18 import org.eclipse.core.resources.IWorkspaceRoot;
19 import org.eclipse.core.runtime.Assert;
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.core.runtime.IPath;
22 import org.eclipse.core.runtime.IProgressMonitor;
23 import org.eclipse.core.runtime.OperationCanceledException;
24 import org.eclipse.core.runtime.SubProgressMonitor;
25
26 /**
27  * FolderDescription is a lightweight description that describes a folder to be
28  * created.
29  *
30  * This class is not intended to be instantiated or used by clients.
31  *
32  * @since 3.3
33  *
34  */

35 public class FolderDescription extends ContainerDescription {
36
37     /**
38      * Create a FolderDescription from the specified folder handle. Typically
39      * used when the folder handle represents a resource that actually exists,
40      * although it will not fail if the resource is non-existent.
41      *
42      * @param folder
43      * the folder to be described
44      */

45     public FolderDescription(IFolder folder) {
46         super(folder);
47     }
48
49     /**
50      * Create a FolderDescription from the specified folder handle. If the
51      * folder to be created should be linked to a different location, specify
52      * the location.
53      *
54      * @param folder
55      * the folder to be described
56      * @param linkLocation
57      * the location to which the folder is linked, or
58      * <code>null</code> if it is not linked
59      */

60     public FolderDescription(IFolder folder, URI JavaDoc linkLocation) {
61         super(folder);
62         this.name = folder.getName();
63         this.location = linkLocation;
64     }
65
66     /*
67      * (non-Javadoc)
68      *
69      * @see org.eclipse.ui.internal.ide.undo.ContainerDescription#createResourceHandle()
70      */

71     public IResource createResourceHandle() {
72         IWorkspaceRoot workspaceRoot = getWorkspace().getRoot();
73         IPath folderPath = parent.getFullPath().append(name);
74         return workspaceRoot.getFolder(folderPath);
75     }
76
77     /*
78      * (non-Javadoc)
79      *
80      * @see org.eclipse.ui.internal.ide.undo.ResourceDescription#createExistentResourceFromHandle(org.eclipse.core.resources.IResource,
81      * org.eclipse.core.runtime.IProgressMonitor)
82      */

83     public void createExistentResourceFromHandle(IResource resource,
84             IProgressMonitor monitor) throws CoreException {
85
86         Assert.isLegal(resource instanceof IFolder);
87         if (resource.exists()) {
88             return;
89         }
90         IFolder folderHandle = (IFolder) resource;
91         try {
92             monitor.beginTask("", 200); //$NON-NLS-1$
93
monitor.setTaskName(UndoMessages.FolderDescription_NewFolderProgress);
94             if (monitor.isCanceled()) {
95                 throw new OperationCanceledException();
96             }
97             if (location != null) {
98                 folderHandle.createLink(location,
99                         IResource.ALLOW_MISSING_LOCAL, new SubProgressMonitor(
100                                 monitor, 100));
101             } else {
102                 folderHandle.create(false, true, new SubProgressMonitor(
103                         monitor, 100));
104             }
105             if (monitor.isCanceled()) {
106                 throw new OperationCanceledException();
107             }
108             createChildResources(folderHandle, monitor, 100);
109
110         } finally {
111             monitor.done();
112         }
113     }
114 }
Popular Tags