1 11 12 package org.eclipse.ltk.ui.refactoring; 13 14 import org.eclipse.core.runtime.IStatus; 15 16 import org.eclipse.jface.wizard.IWizardPage; 17 18 import org.eclipse.ltk.core.refactoring.CheckConditionsOperation; 19 import org.eclipse.ltk.core.refactoring.CreateChangeOperation; 20 import org.eclipse.ltk.core.refactoring.PerformChangeOperation; 21 import org.eclipse.ltk.core.refactoring.Refactoring; 22 import org.eclipse.ltk.core.refactoring.RefactoringCore; 23 import org.eclipse.ltk.core.refactoring.RefactoringStatus; 24 25 import org.eclipse.ltk.internal.ui.refactoring.FinishResult; 26 import org.eclipse.ltk.internal.ui.refactoring.IErrorWizardPage; 27 import org.eclipse.ltk.internal.ui.refactoring.InternalAPI; 28 import org.eclipse.ltk.internal.ui.refactoring.UIPerformChangeOperation; 29 30 41 public abstract class UserInputWizardPage extends RefactoringWizardPage { 42 43 private boolean fIsLastUserInputPage; 44 45 49 public UserInputWizardPage(String name) { 50 super(name); 51 } 52 53 62 public boolean isLastUserInputPage() { 63 return fIsLastUserInputPage; 64 } 65 66 74 protected final IWizardPage computeSuccessorPage() { 75 return getRefactoringWizard().computeUserInputSuccessorPage(this, getContainer()); 76 } 77 78 84 public void setPageComplete(RefactoringStatus status) { 85 getRefactoringWizard().setConditionCheckingStatus(status); 86 87 int severity= status.getSeverity(); 88 if (severity == RefactoringStatus.FATAL){ 89 setPageComplete(false); 90 setErrorMessage(status.getMessageMatchingSeverity(severity)); 91 } else { 92 setPageComplete(true); 93 setErrorMessage(null); 94 if (severity == RefactoringStatus.OK) 95 setMessage(null, NONE); 96 else 97 setMessage(status.getMessageMatchingSeverity(severity), getCorrespondingIStatusSeverity(severity)); 98 } 99 } 100 101 104 public void setVisible(boolean visible) { 105 if (visible) 106 getRefactoringWizard().internalSetChange(InternalAPI.INSTANCE, null); 107 super.setVisible(visible); 108 } 109 110 113 public IWizardPage getNextPage() { 114 if (fIsLastUserInputPage) 115 return computeSuccessorPage(); 116 else 117 return super.getNextPage(); 118 } 119 120 123 public boolean canFlipToNextPage() { 124 if (fIsLastUserInputPage) { 125 return isPageComplete(); 129 } else { 130 return super.canFlipToNextPage(); 131 } 132 } 133 134 137 protected boolean performFinish() { 138 RefactoringWizard wizard= getRefactoringWizard(); 139 int threshold= RefactoringCore.getConditionCheckingFailedSeverity(); 140 RefactoringStatus activationStatus= wizard.getInitialConditionCheckingStatus(); 141 RefactoringStatus inputStatus= null; 142 RefactoringStatus status= new RefactoringStatus(); 143 Refactoring refactoring= getRefactoring(); 144 145 if (activationStatus != null && activationStatus.getSeverity() >= threshold) { 146 if (!activationStatus.hasFatalError()) 147 inputStatus= wizard.checkFinalConditions(); 148 } else { 149 CreateChangeOperation create= new CreateChangeOperation( 150 new CheckConditionsOperation(refactoring, CheckConditionsOperation.FINAL_CONDITIONS), 151 threshold); 152 PerformChangeOperation perform= new UIPerformChangeOperation(getShell().getDisplay(), create, getContainer()); 153 154 FinishResult result= wizard.internalPerformFinish(InternalAPI.INSTANCE, perform); 155 wizard.internalSetChange(InternalAPI.INSTANCE, create.getChange()); 156 if (result.isException()) 157 return true; 158 if (result.isInterrupted()) 159 return false; 160 inputStatus= new RefactoringStatus(); 161 inputStatus.merge(create.getConditionCheckingStatus()); 162 RefactoringStatus validationStatus= perform.getValidationStatus(); 163 if (validationStatus != null && validationStatus.hasFatalError()) 166 inputStatus.merge(perform.getValidationStatus()); 167 } 168 169 status.merge(activationStatus); 170 status.merge(inputStatus); 171 172 if (status.getSeverity() >= threshold) { 173 wizard.setConditionCheckingStatus(status); 174 IWizardPage nextPage= wizard.getPage(IErrorWizardPage.PAGE_NAME); 175 wizard.getContainer().showPage(nextPage); 176 return false; 177 } 178 179 return true; 180 } 181 182 void markAsLastUserInputPage() { 183 fIsLastUserInputPage= true; 184 } 185 186 private static int getCorrespondingIStatusSeverity(int severity) { 187 if (severity == RefactoringStatus.FATAL) 188 return IStatus.ERROR; 189 if (severity == RefactoringStatus.ERROR) 190 return IStatus.WARNING; 191 if (severity == RefactoringStatus.WARNING) 192 return IStatus.WARNING; 193 if (severity == RefactoringStatus.INFO) 194 return IStatus.INFO; 195 return IStatus.OK; 196 } 197 } 198 | Popular Tags |