1 11 12 package org.eclipse.ui.internal.ide.undo; 13 14 import org.eclipse.core.resources.IProject; 15 import org.eclipse.core.resources.IProjectDescription; 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.resources.ResourcesPlugin; 18 import org.eclipse.core.runtime.Assert; 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.core.runtime.IProgressMonitor; 21 import org.eclipse.core.runtime.OperationCanceledException; 22 import org.eclipse.core.runtime.SubProgressMonitor; 23 24 33 public class ProjectDescription extends ContainerDescription { 34 35 private IProjectDescription projectDescription; 36 private boolean openOnCreate = true; 37 38 44 public ProjectDescription(IProject project) { 45 super(project); 46 Assert.isLegal(project.exists()); 47 if (project.isOpen()) { 48 try { 49 this.projectDescription = project.getDescription(); 50 } catch (CoreException e) { 51 } 57 } else { 58 openOnCreate = false; 59 } 60 } 61 62 69 public ProjectDescription(IProjectDescription projectDescription) { 70 super(); 71 this.projectDescription = projectDescription; 72 } 73 74 79 public IResource createResourceHandle() { 80 return ResourcesPlugin.getWorkspace().getRoot().getProject(getName()); 81 } 82 83 89 public void createExistentResourceFromHandle(IResource resource, 90 IProgressMonitor monitor) throws CoreException { 91 Assert.isLegal(resource instanceof IProject); 92 if (resource.exists()) { 93 return; 94 } 95 IProject projectHandle = (IProject) resource; 96 monitor.beginTask("", 200); monitor.setTaskName(UndoMessages.FolderDescription_NewFolderProgress); 98 if (projectDescription == null) { 99 projectHandle.create(new SubProgressMonitor(monitor, 100)); 100 } else { 101 projectHandle.create(projectDescription, new SubProgressMonitor( 102 monitor, 100)); 103 } 104 105 if (monitor.isCanceled()) { 106 throw new OperationCanceledException(); 107 } 108 if (openOnCreate) { 109 projectHandle.open(IResource.BACKGROUND_REFRESH, 110 new SubProgressMonitor(monitor, 100)); 111 } 112 monitor.done(); 113 } 114 115 120 public String getName() { 121 if (projectDescription != null) { 122 return projectDescription.getName(); 123 } 124 return super.getName(); 125 } 126 127 132 public boolean verifyExistence(boolean checkMembers) { 133 IProject projectHandle = (IProject) createResourceHandle(); 135 if (projectHandle.isAccessible()) { 136 return super.verifyExistence(checkMembers); 137 } 138 return super.verifyExistence(false); 139 } 140 } | Popular Tags |