1 11 package org.eclipse.jdt.internal.junit.wizards; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.core.resources.IFile; 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.resources.ResourcesPlugin; 18 19 import org.eclipse.swt.widgets.Display; 20 import org.eclipse.swt.widgets.Shell; 21 22 import org.eclipse.jface.dialogs.DialogSettings; 23 import org.eclipse.jface.dialogs.IDialogSettings; 24 import org.eclipse.jface.operation.IRunnableWithProgress; 25 import org.eclipse.jface.viewers.IStructuredSelection; 26 import org.eclipse.jface.wizard.Wizard; 27 28 import org.eclipse.ui.INewWizard; 29 import org.eclipse.ui.IWorkbench; 30 import org.eclipse.ui.IWorkbenchPage; 31 import org.eclipse.ui.PartInitException; 32 import org.eclipse.ui.PlatformUI; 33 import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation; 34 import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard; 35 36 import org.eclipse.ui.ide.IDE; 37 38 import org.eclipse.jdt.internal.junit.ui.JUnitPlugin; 39 import org.eclipse.jdt.internal.junit.util.ExceptionHandler; 40 41 44 public abstract class JUnitWizard extends Wizard implements INewWizard { 45 46 private IWorkbench fWorkbench; 47 protected static final String DIALOG_SETTINGS_KEY= "JUnitWizards"; private IStructuredSelection fSelection; 49 50 public JUnitWizard() { 51 setNeedsProgressMonitor(true); 52 initializeDefaultPageImageDescriptor(); 53 } 54 55 58 public abstract boolean performFinish(); 59 60 63 protected boolean finishPage(IRunnableWithProgress runnable) { 64 IRunnableWithProgress op= new WorkspaceModifyDelegatingOperation(runnable); 65 try { 66 PlatformUI.getWorkbench().getProgressService().runInUI(getContainer(), op, ResourcesPlugin.getWorkspace().getRoot()); 67 68 } catch (InvocationTargetException e) { 69 Shell shell= getShell(); 70 String title= WizardMessages.NewJUnitWizard_op_error_title; 71 String message= WizardMessages.NewJUnitWizard_op_error_message; 72 ExceptionHandler.handle(e, shell, title, message); 73 return false; 74 } catch (InterruptedException e) { 75 return false; 76 } 77 return true; 78 } 79 80 protected void openResource(final IResource resource) { 81 if (resource.getType() == IResource.FILE) { 82 final IWorkbenchPage activePage= JUnitPlugin.getActivePage(); 83 if (activePage != null) { 84 final Display display= Display.getDefault(); 85 if (display != null) { 86 display.asyncExec(new Runnable () { 87 public void run() { 88 try { 89 IDE.openEditor(activePage, (IFile)resource, true); 90 } catch (PartInitException e) { 91 JUnitPlugin.log(e); 92 } 93 } 94 }); 95 } 96 } 97 } 98 } 99 100 103 public void init(IWorkbench workbench, IStructuredSelection currentSelection) { 104 fWorkbench= workbench; 105 fSelection= currentSelection; 106 } 107 108 public IStructuredSelection getSelection() { 109 return fSelection; 110 } 111 112 protected void selectAndReveal(IResource newResource) { 113 BasicNewResourceWizard.selectAndReveal(newResource, fWorkbench.getActiveWorkbenchWindow()); 114 } 115 116 protected void initDialogSettings() { 117 IDialogSettings pluginSettings= JUnitPlugin.getDefault().getDialogSettings(); 118 IDialogSettings wizardSettings= pluginSettings.getSection(DIALOG_SETTINGS_KEY); 119 if (wizardSettings == null) { 120 wizardSettings= new DialogSettings(DIALOG_SETTINGS_KEY); 121 pluginSettings.addSection(wizardSettings); 122 } 123 setDialogSettings(wizardSettings); 124 } 125 126 protected abstract void initializeDefaultPageImageDescriptor(); 127 } 128 | Popular Tags |