1 11 package org.eclipse.jdt.internal.debug.ui.launcher; 12 13 14 import org.eclipse.core.resources.IProject; 15 import org.eclipse.core.resources.IResource; 16 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 17 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; 18 import org.eclipse.jdt.core.IJavaElement; 19 import org.eclipse.jdt.core.IJavaProject; 20 import org.eclipse.jdt.core.JavaCore; 21 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 22 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; 23 import org.eclipse.jface.viewers.ISelection; 24 import org.eclipse.jface.viewers.IStructuredSelection; 25 import org.eclipse.ui.IEditorInput; 26 import org.eclipse.ui.IEditorPart; 27 import org.eclipse.ui.IWorkbenchPage; 28 29 32 public abstract class JavaLaunchConfigurationTab extends AbstractLaunchConfigurationTab implements IEntriesChangedListener { 33 34 40 protected IJavaElement getContext() { 41 IWorkbenchPage page = JDIDebugUIPlugin.getActivePage(); 42 if (page != null) { 43 ISelection selection = page.getSelection(); 44 if (selection instanceof IStructuredSelection) { 45 IStructuredSelection ss = (IStructuredSelection)selection; 46 if (!ss.isEmpty()) { 47 Object obj = ss.getFirstElement(); 48 if (obj instanceof IJavaElement) { 49 return (IJavaElement)obj; 50 } 51 if (obj instanceof IResource) { 52 IJavaElement je = JavaCore.create((IResource)obj); 53 if (je == null) { 54 IProject pro = ((IResource)obj).getProject(); 55 je = JavaCore.create(pro); 56 } 57 if (je != null) { 58 return je; 59 } 60 } 61 } 62 } 63 IEditorPart part = page.getActiveEditor(); 64 if (part != null) { 65 IEditorInput input = part.getEditorInput(); 66 return (IJavaElement) input.getAdapter(IJavaElement.class); 67 } 68 } 69 return null; 70 } 71 72 75 protected void initializeJavaProject(IJavaElement javaElement, ILaunchConfigurationWorkingCopy config) { 76 IJavaProject javaProject = javaElement.getJavaProject(); 77 String name = null; 78 if (javaProject != null && javaProject.exists()) { 79 name = javaProject.getElementName(); 80 } 81 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, name); 82 } 83 84 87 public void entriesChanged(IClasspathViewer viewer) { 88 setDirty(true); 89 updateLaunchConfigurationDialog(); 90 } 91 } 92 93 | Popular Tags |