1 11 package org.eclipse.jdt.debug.ui.launchConfigurations; 12 13 14 import org.eclipse.core.resources.IProject; 15 import org.eclipse.core.resources.IResource; 16 import org.eclipse.debug.core.ILaunchConfiguration; 17 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 18 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; 19 import org.eclipse.jdt.core.IJavaElement; 20 import org.eclipse.jdt.core.IJavaProject; 21 import org.eclipse.jdt.core.JavaCore; 22 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 23 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; 24 import org.eclipse.jface.viewers.ISelection; 25 import org.eclipse.jface.viewers.IStructuredSelection; 26 import org.eclipse.ui.IEditorInput; 27 import org.eclipse.ui.IEditorPart; 28 import org.eclipse.ui.IWorkbenchPage; 29 30 37 public abstract class JavaLaunchTab extends AbstractLaunchConfigurationTab { 38 39 42 private ILaunchConfiguration fLaunchConfig; 43 44 50 protected IJavaElement getContext() { 51 IWorkbenchPage page = JDIDebugUIPlugin.getActivePage(); 52 if (page != null) { 53 ISelection selection = page.getSelection(); 54 if (selection instanceof IStructuredSelection) { 55 IStructuredSelection ss = (IStructuredSelection)selection; 56 if (!ss.isEmpty()) { 57 Object obj = ss.getFirstElement(); 58 if (obj instanceof IJavaElement) { 59 return (IJavaElement)obj; 60 } 61 if (obj instanceof IResource) { 62 IJavaElement je = JavaCore.create((IResource)obj); 63 if (je == null) { 64 IProject pro = ((IResource)obj).getProject(); 65 je = JavaCore.create(pro); 66 } 67 if (je != null) { 68 return je; 69 } 70 } 71 } 72 } 73 IEditorPart part = page.getActiveEditor(); 74 if (part != null) { 75 IEditorInput input = part.getEditorInput(); 76 return (IJavaElement) input.getAdapter(IJavaElement.class); 77 } 78 } 79 return null; 80 } 81 82 87 protected ILaunchConfiguration getCurrentLaunchConfiguration() { 88 return fLaunchConfig; 89 } 90 91 96 private void setCurrentLaunchConfiguration(ILaunchConfiguration config) { 97 fLaunchConfig = config; 98 } 99 100 107 protected void initializeJavaProject(IJavaElement javaElement, ILaunchConfigurationWorkingCopy config) { 108 IJavaProject javaProject = javaElement.getJavaProject(); 109 String name = null; 110 if (javaProject != null && javaProject.exists()) { 111 name = javaProject.getElementName(); 112 } 113 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, name); 114 } 115 116 121 public void initializeFrom(ILaunchConfiguration config) { 122 setCurrentLaunchConfiguration(config); 123 } 124 125 } 126 127 | Popular Tags |