1 11 package org.eclipse.jdt.internal.junit.launcher; 12 13 14 import org.eclipse.core.resources.IProject; 15 import org.eclipse.core.resources.IResource; 16 17 import org.eclipse.swt.layout.GridData; 18 import org.eclipse.swt.widgets.Button; 19 20 import org.eclipse.jface.viewers.ISelection; 21 import org.eclipse.jface.viewers.IStructuredSelection; 22 23 import org.eclipse.ui.IEditorInput; 24 import org.eclipse.ui.IEditorPart; 25 import org.eclipse.ui.IWorkbenchPage; 26 import org.eclipse.ui.IWorkbenchWindow; 27 import org.eclipse.ui.PlatformUI; 28 29 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 30 31 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; 32 33 import org.eclipse.jdt.core.IJavaElement; 34 import org.eclipse.jdt.core.IJavaProject; 35 import org.eclipse.jdt.core.JavaCore; 36 37 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; 38 39 import org.eclipse.jdt.internal.junit.util.LayoutUtil; 40 41 44 public abstract class JUnitLaunchConfigurationTab extends AbstractLaunchConfigurationTab { 45 46 52 protected IJavaElement getContext() { 53 IWorkbenchWindow activeWorkbenchWindow= PlatformUI.getWorkbench().getActiveWorkbenchWindow(); 54 if (activeWorkbenchWindow == null) { 55 return null; 56 } 57 IWorkbenchPage page = activeWorkbenchWindow.getActivePage(); 58 if (page != null) { 59 ISelection selection = page.getSelection(); 60 if (selection instanceof IStructuredSelection) { 61 IStructuredSelection ss = (IStructuredSelection)selection; 62 if (!ss.isEmpty()) { 63 Object obj = ss.getFirstElement(); 64 if (obj instanceof IJavaElement) { 65 return (IJavaElement)obj; 66 } 67 if (obj instanceof IResource) { 68 IJavaElement je = JavaCore.create((IResource)obj); 69 if (je == null) { 70 IProject pro = ((IResource)obj).getProject(); 71 je = JavaCore.create(pro); 72 } 73 if (je != null) { 74 return je; 75 } 76 } 77 } 78 } 79 IEditorPart part = page.getActiveEditor(); 80 if (part != null) { 81 IEditorInput input = part.getEditorInput(); 82 return (IJavaElement) input.getAdapter(IJavaElement.class); 83 } 84 } 85 return null; 86 } 87 88 93 protected void initializeJavaProject(IJavaElement javaElement, ILaunchConfigurationWorkingCopy config) { 94 IJavaProject javaProject = javaElement.getJavaProject(); 95 String name = null; 96 if (javaProject != null && javaProject.exists()) { 97 name = javaProject.getElementName(); 98 } 99 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, name); 100 } 101 102 protected void setButtonGridData(Button button) { 103 GridData gridData= new GridData(); 104 button.setLayoutData(gridData); 105 LayoutUtil.setButtonDimensionHint(button); 106 } 107 108 } 109 | Popular Tags |