KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > launcher > JavaLaunchConfigurationTab


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
30  * Common function for Java launch configuration tabs.
31  */

32 public abstract class JavaLaunchConfigurationTab extends AbstractLaunchConfigurationTab implements IEntriesChangedListener {
33         
34     /**
35      * Returns the current Java element context from which to initialize
36      * default settings, or <code>null</code> if none.
37      *
38      * @return Java element context.
39      */

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 JavaDoc 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     /**
73      * Set the java project attribute based on the IJavaElement.
74      */

75     protected void initializeJavaProject(IJavaElement javaElement, ILaunchConfigurationWorkingCopy config) {
76         IJavaProject javaProject = javaElement.getJavaProject();
77         String JavaDoc name = null;
78         if (javaProject != null && javaProject.exists()) {
79             name = javaProject.getElementName();
80         }
81         config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, name);
82     }
83     
84     /**
85      * @see IEntriesChangedListener#entriesChanged(RuntimeClasspathViewer)
86      */

87     public void entriesChanged(IClasspathViewer viewer) {
88         setDirty(true);
89         updateLaunchConfigurationDialog();
90     }
91 }
92
93
Popular Tags