1 11 package org.eclipse.ltk.core.refactoring; 12 13 import org.eclipse.core.runtime.Assert; 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.core.runtime.IProgressMonitor; 16 import org.eclipse.core.runtime.NullProgressMonitor; 17 import org.eclipse.core.runtime.SubProgressMonitor; 18 19 import org.eclipse.core.resources.IWorkspaceRunnable; 20 21 import org.eclipse.ltk.internal.core.refactoring.NotCancelableProgressMonitor; 22 import org.eclipse.ltk.internal.core.refactoring.history.UnknownRefactoringDescriptor; 23 24 47 public class CreateChangeOperation implements IWorkspaceRunnable { 48 49 private Refactoring fRefactoring; 50 51 private CheckConditionsOperation fCheckConditionOperation; 52 private int fConditionCheckingFailedSeverity; 53 54 private Change fChange; 55 56 65 public CreateChangeOperation(Refactoring refactoring) { 66 Assert.isNotNull(refactoring); 67 fRefactoring= refactoring; 68 } 69 70 84 public CreateChangeOperation(CheckConditionsOperation operation, int checkFailedSeverity) { 85 Assert.isNotNull(operation); 86 fCheckConditionOperation= operation; 87 fRefactoring= operation.getRefactoring(); 88 Assert.isTrue (checkFailedSeverity > RefactoringStatus.OK && checkFailedSeverity <= RefactoringStatus.FATAL); 89 fConditionCheckingFailedSeverity= checkFailedSeverity; 90 } 91 92 99 public int getConditionCheckingFailedSeverity() { 100 return fConditionCheckingFailedSeverity; 101 } 102 103 106 public void run(IProgressMonitor pm) throws CoreException { 107 if (pm == null) 108 pm= new NullProgressMonitor(); 109 fChange= null; 110 try { 111 fChange= null; 112 RefactoringTickProvider rtp= fRefactoring.getRefactoringTickProvider(); 113 if (fCheckConditionOperation != null) { 114 int conditionTicks= fCheckConditionOperation.getTicks(rtp); 115 int allTicks= conditionTicks + rtp.getCreateChangeTicks() + rtp.getInitializeChangeTicks(); 116 pm.beginTask("", allTicks); pm.subTask(""); fCheckConditionOperation.run(new SubProgressMonitor(pm, conditionTicks)); 119 RefactoringStatus status= fCheckConditionOperation.getStatus(); 120 if (status != null && status.getSeverity() < fConditionCheckingFailedSeverity) { 121 fChange= fRefactoring.createChange(new SubProgressMonitor(pm, rtp.getCreateChangeTicks())); 122 fChange.initializeValidationData(new NotCancelableProgressMonitor( 123 new SubProgressMonitor(pm, rtp.getInitializeChangeTicks()))); 124 } else { 125 pm.worked(rtp.getCreateChangeTicks() + rtp.getInitializeChangeTicks()); 126 } 127 } else { 128 pm.beginTask("", rtp.getCreateChangeTicks() + rtp.getInitializeChangeTicks()); fChange= fRefactoring.createChange(new SubProgressMonitor(pm, rtp.getCreateChangeTicks())); 130 fChange.initializeValidationData(new NotCancelableProgressMonitor( 131 new SubProgressMonitor(pm, rtp.getInitializeChangeTicks()))); 132 } 133 } finally { 134 pm.done(); 135 } 136 } 137 138 145 public Change getChange() { 146 if (fChange != null) { 147 final ChangeDescriptor descriptor= fChange.getDescriptor(); 148 if (descriptor == null) { 149 final CompositeChange composite= new CompositeChange(fChange.getName()) { 150 151 public final ChangeDescriptor getDescriptor() { 152 return new RefactoringChangeDescriptor(new UnknownRefactoringDescriptor(fChange.getName())); 153 } 154 }; 155 composite.markAsSynthetic(); 156 composite.add(fChange); 157 fChange= composite; 158 } 159 } 160 return fChange; 161 } 162 163 169 public RefactoringStatus getConditionCheckingStatus() { 170 if (fCheckConditionOperation != null) 171 return fCheckConditionOperation.getStatus(); 172 return null; 173 } 174 175 183 public int getConditionCheckingStyle() { 184 if (fCheckConditionOperation != null) 185 return fCheckConditionOperation.getStyle(); 186 return CheckConditionsOperation.NONE; 187 } 188 } 189 | Popular Tags |