1 11 package org.eclipse.jdt.internal.core; 12 13 import org.eclipse.core.resources.ResourcesPlugin; 14 import org.eclipse.core.runtime.jobs.ISchedulingRule; 15 import org.eclipse.jdt.core.IJavaElement; 16 import org.eclipse.jdt.core.JavaModelException; 17 18 21 public abstract class ChangeClasspathOperation extends JavaModelOperation { 22 23 protected boolean canChangeResources; 24 25 public ChangeClasspathOperation(IJavaElement[] elements, boolean canChangeResources) { 26 super(elements); 27 this.canChangeResources = canChangeResources; 28 } 29 30 protected boolean canModifyRoots() { 31 return true; 33 } 34 35 42 protected void classpathChanged(JavaProject project) throws JavaModelException { 43 DeltaProcessingState state = JavaModelManager.getJavaModelManager().deltaState; 44 DeltaProcessor deltaProcessor = state.getDeltaProcessor(); 45 ClasspathChange change = (ClasspathChange) deltaProcessor.classpathChanges.get(project.getProject()); 46 if (this.canChangeResources) { 47 if (isTopLevelOperation() && !ResourcesPlugin.getWorkspace().isTreeLocked()) { 49 new ClasspathValidation(project).validate(); 50 } 51 52 55 new ProjectReferenceChange(project, change.oldResolvedClasspath).updateProjectReferencesIfNecessary(); 58 } else { 59 JavaElementDelta delta = new JavaElementDelta(getJavaModel()); 60 int result = change.generateDelta(delta); 61 if ((result & ClasspathChange.HAS_DELTA) != 0) { 62 addDelta(delta); 64 65 change.requestIndexing(); 67 68 state.addClasspathValidation(project); 70 } 71 if ((result & ClasspathChange.HAS_PROJECT_CHANGE) != 0) { 72 state.addProjectReferenceChange(project, change.oldResolvedClasspath); 74 } 75 } 76 } 77 78 protected ISchedulingRule getSchedulingRule() { 79 return null; } 81 82 public boolean isReadOnly() { 83 return !this.canChangeResources; 84 } 85 86 } 87 | Popular Tags |