1 11 package org.eclipse.ltk.ui.refactoring; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.core.runtime.Assert; 16 import org.eclipse.core.runtime.OperationCanceledException; 17 import org.eclipse.core.runtime.jobs.IJobManager; 18 import org.eclipse.core.runtime.jobs.Job; 19 20 import org.eclipse.core.resources.ResourcesPlugin; 21 22 import org.eclipse.ltk.core.refactoring.CheckConditionsOperation; 23 import org.eclipse.ltk.core.refactoring.Refactoring; 24 import org.eclipse.ltk.core.refactoring.RefactoringStatus; 25 26 import org.eclipse.ltk.internal.ui.refactoring.ExceptionHandler; 27 import org.eclipse.ltk.internal.ui.refactoring.RefactoringUIMessages; 28 import org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter; 29 30 import org.eclipse.swt.custom.BusyIndicator; 31 import org.eclipse.swt.widgets.Shell; 32 33 import org.eclipse.jface.dialogs.Dialog; 34 import org.eclipse.jface.dialogs.IDialogConstants; 35 import org.eclipse.jface.dialogs.MessageDialog; 36 import org.eclipse.jface.window.Window; 37 import org.eclipse.jface.wizard.IWizardContainer; 38 39 import org.eclipse.ui.PlatformUI; 40 import org.eclipse.ui.progress.IProgressService; 41 42 52 public class RefactoringWizardOpenOperation { 53 54 private RefactoringWizard fWizard; 55 private RefactoringStatus fInitialConditions; 56 57 63 public static final int INITIAL_CONDITION_CHECKING_FAILED= IDialogConstants.CLIENT_ID + 1; 64 65 70 public RefactoringWizardOpenOperation(RefactoringWizard wizard) { 71 Assert.isNotNull(wizard); 72 fWizard= wizard; 73 } 74 75 81 public RefactoringStatus getInitialConditionCheckingStatus() { 82 return fInitialConditions; 83 } 84 85 112 public int run(final Shell parent, final String dialogTitle) throws InterruptedException { 113 Assert.isNotNull(dialogTitle); 114 final Refactoring refactoring= fWizard.getRefactoring(); 115 final IJobManager manager= Job.getJobManager(); 116 final int[] result= new int[1]; 117 final InterruptedException [] canceled= new InterruptedException [1]; 118 Runnable r= new Runnable () { 119 public void run() { 120 try { 121 manager.beginRule(ResourcesPlugin.getWorkspace().getRoot(), null); 123 124 refactoring.setValidationContext(parent); 125 fInitialConditions= checkInitialConditions(refactoring, parent, dialogTitle); 126 if (fInitialConditions.hasFatalError()) { 127 String message= fInitialConditions.getMessageMatchingSeverity(RefactoringStatus.FATAL); 128 MessageDialog.openInformation(parent, dialogTitle, message); 129 result[0]= INITIAL_CONDITION_CHECKING_FAILED; 130 } else { 131 fWizard.setInitialConditionCheckingStatus(fInitialConditions); 132 Dialog dialog= RefactoringUI.createRefactoringWizardDialog(fWizard, parent); 133 dialog.create(); 134 IWizardContainer wizardContainer= (IWizardContainer) dialog; 135 if (wizardContainer.getCurrentPage() == null) 136 140 result[0]= Window.CANCEL; 141 else 142 result[0]= dialog.open(); 143 } 144 } catch (InterruptedException e) { 145 canceled[0]= e; 146 } catch (OperationCanceledException e) { 147 canceled[0]= new InterruptedException (e.getMessage()); 148 } finally { 149 manager.endRule(ResourcesPlugin.getWorkspace().getRoot()); 150 refactoring.setValidationContext(null); 151 } 152 } 153 }; 154 BusyIndicator.showWhile(parent.getDisplay(), r); 155 if (canceled[0] != null) 156 throw canceled[0]; 157 return result[0]; 158 } 159 160 162 private RefactoringStatus checkInitialConditions(Refactoring refactoring, Shell parent, String title) throws InterruptedException { 163 try { 164 CheckConditionsOperation cco= new CheckConditionsOperation(refactoring, CheckConditionsOperation.INITIAL_CONDITONS); 165 IProgressService service= PlatformUI.getWorkbench().getProgressService(); 166 service.busyCursorWhile(new WorkbenchRunnableAdapter(cco, ResourcesPlugin.getWorkspace().getRoot())); 167 return cco.getStatus(); 168 } catch (InvocationTargetException e) { 169 ExceptionHandler.handle(e, parent, title, 170 RefactoringUIMessages.RefactoringUI_open_unexpected_exception); 171 return RefactoringStatus.createFatalErrorStatus( 172 RefactoringUIMessages.RefactoringUI_open_unexpected_exception); 173 } 174 } 175 } 176 | Popular Tags |