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 37 public class PerformRefactoringOperation implements IWorkspaceRunnable { 38 39 private int fStyle; 40 private Refactoring fRefactoring; 41 42 private RefactoringStatus fPreconditionStatus; 43 private RefactoringStatus fValidationStatus; 44 private Change fUndo; 45 46 55 public PerformRefactoringOperation(Refactoring refactoring, int style) { 56 Assert.isNotNull(refactoring); 57 fRefactoring= refactoring; 58 fStyle= style; 59 } 60 61 67 public RefactoringStatus getConditionStatus() { 68 return fPreconditionStatus; 69 } 70 71 78 public RefactoringStatus getValidationStatus() { 79 return fValidationStatus; 80 } 81 82 88 public Change getUndoChange() { 89 return fUndo; 90 } 91 92 95 public void run(IProgressMonitor monitor) throws CoreException { 96 if (monitor == null) 97 monitor= new NullProgressMonitor(); 98 monitor.beginTask("", 10); final CreateChangeOperation create= new CreateChangeOperation(new CheckConditionsOperation(fRefactoring, fStyle), RefactoringStatus.FATAL); 100 create.run(new SubProgressMonitor(monitor, 6)); 101 fPreconditionStatus= create.getConditionCheckingStatus(); 102 if (fPreconditionStatus.hasFatalError()) { 103 monitor.done(); 104 return; 105 } 106 final Change change= create.getChange(); 107 if (change != null) { 108 final PerformChangeOperation perform= new PerformChangeOperation(change); 109 perform.setUndoManager(RefactoringCore.getUndoManager(), fRefactoring.getName()); 110 perform.run(new SubProgressMonitor(monitor, 2)); 111 fValidationStatus= perform.getValidationStatus(); 112 fUndo= perform.getUndoChange(); 113 } 114 } 115 } 116 | Popular Tags |