1 11 12 package org.eclipse.ltk.internal.ui.refactoring; 13 14 import org.eclipse.core.runtime.Assert; 15 16 import org.eclipse.ltk.core.refactoring.Change; 17 import org.eclipse.ltk.core.refactoring.CreateChangeOperation; 18 import org.eclipse.ltk.core.refactoring.PerformChangeOperation; 19 import org.eclipse.ltk.core.refactoring.RefactoringStatus; 20 21 import org.eclipse.swt.SWT; 22 import org.eclipse.swt.widgets.Composite; 23 24 import org.eclipse.jface.action.LegacyActionTools; 25 import org.eclipse.jface.dialogs.Dialog; 26 import org.eclipse.jface.dialogs.IDialogConstants; 27 import org.eclipse.jface.dialogs.MessageDialog; 28 import org.eclipse.jface.wizard.IWizardPage; 29 30 import org.eclipse.ui.PlatformUI; 31 32 import org.eclipse.ltk.ui.refactoring.RefactoringWizard; 33 import org.eclipse.ltk.ui.refactoring.RefactoringWizardPage; 34 35 38 public class ErrorWizardPage extends RefactoringWizardPage implements IErrorWizardPage { 39 40 protected RefactoringStatus fStatus; 41 protected RefactoringStatusViewer fViewer; 42 43 46 public ErrorWizardPage() { 47 super(PAGE_NAME); 48 } 49 50 57 public ErrorWizardPage(boolean wizard) { 58 super(PAGE_NAME, wizard); 59 } 60 61 64 public void setStatus(RefactoringStatus status) { 65 fStatus= status; 66 if (fStatus != null) { 67 final int severity= fStatus.getSeverity(); 68 setPageComplete(severity < RefactoringStatus.FATAL); 69 if (severity >= RefactoringStatus.FATAL) { 70 setDescription(RefactoringUIMessages.ErrorWizardPage_cannot_proceed); 71 } else if (severity >= RefactoringStatus.INFO) { 72 setDescription(Messages.format(RefactoringUIMessages.ErrorWizardPage_confirm, new String [] {getLabelAsText(IDialogConstants.NEXT_LABEL), getLabelAsText(IDialogConstants.FINISH_LABEL)})); 73 } else { 74 setDescription(""); } 76 } else { 77 setPageComplete(true); 78 setDescription(""); } 80 } 81 82 protected String getLabelAsText(String label) { 83 Assert.isNotNull(label); 84 return LegacyActionTools.removeMnemonics(label); 85 } 86 87 90 public RefactoringStatus getStatus() { 91 return fStatus; 92 } 93 94 96 99 public void createControl(Composite parent) { 100 initializeDialogUnits(parent); 101 setControl(fViewer= new RefactoringStatusViewer(parent, SWT.NONE)); 102 Dialog.applyDialogFont(fViewer); 103 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IRefactoringHelpContextIds.REFACTORING_ERROR_WIZARD_PAGE); 104 } 105 106 108 111 public void setVisible(boolean visible) { 112 if (visible) { 113 fViewer.setStatus(fStatus); 114 } else { 115 if (!isPageComplete() && fStatus.hasFatalError()) 119 setPageComplete(true); 120 } 121 super.setVisible(visible); 122 } 123 124 127 public boolean canFlipToNextPage() { 128 return fStatus != null && fStatus.getSeverity() < RefactoringStatus.FATAL && 131 isPageComplete() && super.getNextPage() != null; 132 } 133 134 137 public IWizardPage getNextPage() { 138 RefactoringWizard wizard= getRefactoringWizard(); 139 Change change= wizard.getChange(); 140 if (change == null) { 141 change= wizard.internalCreateChange(InternalAPI.INSTANCE, new CreateChangeOperation(getRefactoring()), false); 142 wizard.internalSetChange(InternalAPI.INSTANCE, change); 143 } 144 if (change == null) 145 return this; 146 147 return super.getNextPage(); 148 } 149 150 153 protected boolean performFinish() { 154 RefactoringWizard wizard= getRefactoringWizard(); 155 Change change= wizard.getChange(); 156 PerformChangeOperation operation= null; 157 if (change != null) { 158 operation= new UIPerformChangeOperation(getShell().getDisplay(), change, getContainer()); 159 } else { 160 CreateChangeOperation ccop= new CreateChangeOperation(getRefactoring()); 161 operation= new UIPerformChangeOperation(getShell().getDisplay(), ccop, getContainer()); 162 } 163 FinishResult result= wizard.internalPerformFinish(InternalAPI.INSTANCE, operation); 164 if (result.isException()) 165 return true; 166 if (result.isInterrupted()) 167 return false; 168 RefactoringStatus fValidationStatus= operation.getValidationStatus(); 169 if (fValidationStatus != null && fValidationStatus.hasFatalError()) { 170 MessageDialog.openError(wizard.getShell(), wizard.getWindowTitle(), 171 Messages.format( 172 RefactoringUIMessages.RefactoringUI_cannot_execute, 173 fValidationStatus.getMessageMatchingSeverity(RefactoringStatus.FATAL))); 174 return true; 175 } 176 return true; 177 } 178 } 179 | Popular Tags |