| package org.eclipse.jdt.internal.debug.ui.launcher; |
| |
| /* |
| * (c) Copyright IBM Corp. 2000, 2001. |
| * All Rights Reserved. |
| */ |
| |
| import org.eclipse.core.resources.IProject; |
| import org.eclipse.core.resources.IResource; |
| import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; |
| import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; |
| import org.eclipse.jdt.core.IJavaElement; |
| import org.eclipse.jdt.core.IJavaProject; |
| import org.eclipse.jdt.core.JavaCore; |
| import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; |
| import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; |
| import org.eclipse.jface.viewers.ISelection; |
| import org.eclipse.jface.viewers.IStructuredSelection; |
| import org.eclipse.ui.IEditorInput; |
| import org.eclipse.ui.IEditorPart; |
| import org.eclipse.ui.IWorkbenchPage; |
| |
| /** |
| * Common function for Java launch configuration tabs. |
| */ |
| public abstract class JavaLaunchConfigurationTab extends AbstractLaunchConfigurationTab implements IEntriesChangedListener { |
| |
| /** |
| * Returns the current Java element context from which to initialize |
| * default settings, or <code>null</code> if none. |
| * |
| * @return Java element context. |
| */ |
| protected IJavaElement getContext() { |
| IWorkbenchPage page = JDIDebugUIPlugin.getActivePage(); |
| if (page != null) { |
| ISelection selection = page.getSelection(); |
| if (selection instanceof IStructuredSelection) { |
| IStructuredSelection ss = (IStructuredSelection)selection; |
| if (!ss.isEmpty()) { |
| Object obj = ss.getFirstElement(); |
| if (obj instanceof IJavaElement) { |
| return (IJavaElement)obj; |
| } |
| if (obj instanceof IResource) { |
| IJavaElement je = JavaCore.create((IResource)obj); |
| if (je == null) { |
| IProject pro = ((IResource)obj).getProject(); |
| je = JavaCore.create(pro); |
| } |
| if (je != null) { |
| return je; |
| } |
| } |
| } |
| } |
| IEditorPart part = page.getActiveEditor(); |
| if (part != null) { |
| IEditorInput input = part.getEditorInput(); |
| return (IJavaElement) input.getAdapter(IJavaElement.class); |
| } |
| } |
| return null; |
| } |
| |
| /** |
| * Set the java project attribute based on the IJavaElement. |
| */ |
| protected void initializeJavaProject(IJavaElement javaElement, ILaunchConfigurationWorkingCopy config) { |
| IJavaProject javaProject = javaElement.getJavaProject(); |
| String name = null; |
| if (javaProject != null && javaProject.exists()) { |
| name = javaProject.getElementName(); |
| } |
| config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, name); |
| } |
| |
| /** |
| * @see IEntriesChangedListener#entriesChanged(RuntimeClasspathViewer) |
| */ |
| public void entriesChanged(RuntimeClasspathViewer viewer) { |
| updateLaunchConfigurationDialog(); |
| setDirty(true); |
| } |
| |
| } |
| |