1 11 package org.eclipse.ltk.internal.ui.refactoring; 12 13 import org.eclipse.core.runtime.Assert; 14 15 import org.eclipse.ltk.core.refactoring.Refactoring; 16 import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy; 17 import org.eclipse.ltk.core.refactoring.RefactoringStatus; 18 import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry; 19 20 import org.eclipse.ltk.internal.ui.refactoring.history.RefactoringHistoryErrorPage; 21 22 import org.eclipse.jface.wizard.IWizard; 23 import org.eclipse.jface.wizard.IWizardPage; 24 25 import org.eclipse.ltk.ui.refactoring.history.RefactoringHistoryWizard; 26 27 32 public final class RefactoringHistoryPreviewPage extends PreviewWizardPage { 33 34 35 private RefactoringPreviewChangeFilter fFilter= new RefactoringPreviewChangeFilter(); 36 37 38 private boolean fNextPageDisabled= false; 39 40 41 private Refactoring fRefactoring; 42 43 44 private RefactoringStatus fStatus= new RefactoringStatus(); 45 46 49 public RefactoringHistoryPreviewPage() { 50 super(true); 51 setTitle(RefactoringUIMessages.RefactoringHistoryOverviewPage_title); 52 setDescription(RefactoringUIMessages.RefactoringHistoryPreviewPage_description); 53 } 54 55 58 public boolean canFlipToNextPage() { 59 return !fNextPageDisabled; 60 } 61 62 65 public IWizardPage getNextPage() { 66 if (fChange != null && fRefactoring != null && !fStatus.hasFatalError()) { 67 final RefactoringHistoryWizard result= getRefactoringHistoryWizard(); 68 if (result != null) { 69 final RefactoringStatus status= result.performPreviewChange(fChange, fRefactoring); 70 if (!status.isOK()) { 71 final RefactoringStatusEntry entry= status.getEntryWithHighestSeverity(); 72 if (entry != null) { 73 if (entry.getSeverity() == RefactoringStatus.INFO && entry.getCode() == RefactoringHistoryWizard.STATUS_CODE_INTERRUPTED) 74 return this; 75 final IErrorWizardPage page= result.getErrorPage(); 76 if (page instanceof RefactoringHistoryErrorPage) { 77 final RefactoringHistoryErrorPage extended= (RefactoringHistoryErrorPage) page; 78 extended.setStatus(status); 79 extended.setNextPageDisabled(fNextPageDisabled); 80 extended.setTitle(RefactoringUIMessages.RefactoringHistoryPreviewPage_apply_error_title); 81 extended.setDescription(RefactoringUIMessages.RefactoringHistoryPreviewPage_apply_error); 82 return extended; 83 } 84 } 85 } 86 } 87 } 88 return getWizard().getNextPage(this); 89 } 90 91 94 public IWizardPage getPreviousPage() { 95 return getWizard().getPreviousPage(this); 96 } 97 98 103 public Refactoring getRefactoring() { 104 return fRefactoring; 105 } 106 107 112 protected RefactoringHistoryWizard getRefactoringHistoryWizard() { 113 final IWizard result= getWizard(); 114 if (result instanceof RefactoringHistoryWizard) 115 return (RefactoringHistoryWizard) result; 116 return null; 117 } 118 119 124 public boolean isNextPageDisabled() { 125 return fNextPageDisabled; 126 } 127 128 131 protected boolean performFinish() { 132 return true; 133 } 134 135 141 public void setFilter(final RefactoringPreviewChangeFilter filter) { 142 Assert.isNotNull(filter); 143 fFilter= filter; 144 } 145 146 152 public void setNextPageDisabled(final boolean disable) { 153 fNextPageDisabled= disable; 154 } 155 156 159 public void setPageComplete(final boolean complete) { 160 super.setPageComplete(!fNextPageDisabled); 161 } 162 163 169 public void setRefactoring(final Refactoring refactoring) { 170 fRefactoring= refactoring; 171 } 172 173 179 public void setStatus(final RefactoringStatus status) { 180 Assert.isNotNull(status); 181 fStatus= status; 182 } 183 184 194 public void setTitle(final RefactoringDescriptorProxy descriptor, final int current, final int total) { 195 final String message; 196 if (descriptor != null) 197 message= descriptor.getDescription(); 198 else 199 message= RefactoringUIMessages.RefactoringHistoryOverviewPage_title; 200 if (total > 1) 201 setTitle(Messages.format(RefactoringUIMessages.RefactoringHistoryPreviewPage_refactoring_pattern, new String [] { message, String.valueOf(current + 1), String.valueOf(total)})); 202 else 203 setTitle(message); 204 } 205 206 209 protected void setTreeViewerInput() { 210 if (fTreeViewer == null) 211 return; 212 PreviewNode input= null; 213 if (fTreeViewerInputChange != null) { 214 input= AbstractChangeNode.createNode(null, fFilter, fTreeViewerInputChange); 215 } 216 if (input instanceof CompositeChangeNode) { 217 final CompositeChangeNode node= (CompositeChangeNode) input; 218 final PreviewNode[] nodes= node.getChildren(); 219 if (nodes == null || nodes.length == 0) { 220 fTreeViewerPane.setText(RefactoringUIMessages.RefactoringHistoryPreviewPage_no_changes); 221 fNextAction.setEnabled(false); 222 fPreviousAction.setEnabled(false); 223 fFilterDropDownAction.setEnabled(false); 224 fTreeViewer.setInput(null); 225 return; 226 } 227 } 228 fTreeViewerPane.setText(RefactoringUIMessages.PreviewWizardPage_changes); 229 fNextAction.setEnabled(true); 230 fPreviousAction.setEnabled(true); 231 fFilterDropDownAction.setEnabled(true); 232 fTreeViewer.setInput(input); 233 } 234 235 238 public void setVisible(final boolean visible) { 239 super.setVisible(visible); 240 if (fTreeViewer.getInput() == null) 241 fFilterDropDownAction.setEnabled(false); 242 } 243 244 247 public void setWizard(final IWizard newWizard) { 248 Assert.isTrue(newWizard instanceof RefactoringHistoryWizard); 249 super.setWizard(newWizard); 250 } 251 } 252 | Popular Tags |