1 11 12 package org.eclipse.ui.internal.ide.undo; 13 14 import java.net.URI ; 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 35 public class FolderDescription extends ContainerDescription { 36 37 45 public FolderDescription(IFolder folder) { 46 super(folder); 47 } 48 49 60 public FolderDescription(IFolder folder, URI linkLocation) { 61 super(folder); 62 this.name = folder.getName(); 63 this.location = linkLocation; 64 } 65 66 71 public IResource createResourceHandle() { 72 IWorkspaceRoot workspaceRoot = getWorkspace().getRoot(); 73 IPath folderPath = parent.getFullPath().append(name); 74 return workspaceRoot.getFolder(folderPath); 75 } 76 77 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); 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 |