1 11 12 package org.eclipse.jdt.internal.debug.ui.launcher; 13 14 import java.lang.reflect.InvocationTargetException ; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.debug.core.ILaunchConfiguration; 18 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 19 import org.eclipse.jdt.core.IClassFile; 20 import org.eclipse.jdt.core.ICompilationUnit; 21 import org.eclipse.jdt.core.IJavaElement; 22 import org.eclipse.jdt.core.IMember; 23 import org.eclipse.jdt.core.IType; 24 import org.eclipse.jdt.core.search.IJavaSearchScope; 25 import org.eclipse.jdt.core.search.SearchEngine; 26 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 27 import org.eclipse.jdt.internal.debug.ui.SWTFactory; 28 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; 29 import org.eclipse.swt.events.ModifyEvent; 30 import org.eclipse.swt.events.ModifyListener; 31 import org.eclipse.swt.events.SelectionEvent; 32 import org.eclipse.swt.events.SelectionListener; 33 import org.eclipse.swt.graphics.Font; 34 import org.eclipse.swt.layout.GridData; 35 import org.eclipse.swt.widgets.Button; 36 import org.eclipse.swt.widgets.Composite; 37 import org.eclipse.swt.widgets.Group; 38 import org.eclipse.swt.widgets.Text; 39 40 48 public abstract class SharedJavaMainTab extends AbstractJavaMainTab { 49 50 protected Text fMainText; 51 private Button fSearchButton; 52 53 58 protected void createMainTypeEditor(Composite parent, String text) { 59 Font font= parent.getFont(); 60 Group mainGroup = SWTFactory.createGroup(parent, text, 2, 1, GridData.FILL_HORIZONTAL); 61 Composite comp = SWTFactory.createComposite(mainGroup, font, 2, 2, GridData.FILL_BOTH, 0, 0); 62 fMainText = SWTFactory.createSingleText(comp, 1); 63 fMainText.addModifyListener(new ModifyListener() { 64 public void modifyText(ModifyEvent e) { 65 updateLaunchConfigurationDialog(); 66 } 67 }); 68 fSearchButton = createPushButton(comp, LauncherMessages.AbstractJavaMainTab_2, null); 69 fSearchButton.addSelectionListener(new SelectionListener() { 70 public void widgetDefaultSelected(SelectionEvent e) { 71 } 72 public void widgetSelected(SelectionEvent e) { 73 handleSearchButtonSelected(); 74 } 75 }); 76 createMainTypeExtensions(comp); 77 } 78 79 87 protected void createMainTypeExtensions(Composite parent) { 88 } 90 91 94 protected abstract void handleSearchButtonSelected(); 95 96 99 protected void initializeMainTypeAndName(IJavaElement javaElement, ILaunchConfigurationWorkingCopy config) { 100 String name = null; 101 if (javaElement instanceof IMember) { 102 IMember member = (IMember)javaElement; 103 if (member.isBinary()) { 104 javaElement = member.getClassFile(); 105 } 106 else { 107 javaElement = member.getCompilationUnit(); 108 } 109 } 110 if (javaElement instanceof ICompilationUnit || javaElement instanceof IClassFile) { 111 try { 112 IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[]{javaElement}, false); 113 MainMethodSearchEngine engine = new MainMethodSearchEngine(); 114 IType[] types = engine.searchMainMethods(getLaunchConfigurationDialog(), scope, false); 115 if (types != null && (types.length > 0)) { 116 name = types[0].getFullyQualifiedName(); 118 } 119 } 120 catch (InterruptedException ie) {JDIDebugUIPlugin.log(ie);} 121 catch (InvocationTargetException ite) {JDIDebugUIPlugin.log(ite);} 122 } 123 if (name == null) { 124 name = EMPTY_STRING; 125 } 126 config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, name); 127 if (name.length() > 0) { 128 int index = name.lastIndexOf('.'); 129 if (index > 0) { 130 name = name.substring(index + 1); 131 } 132 name = getLaunchConfigurationDialog().generateName(name); 133 config.rename(name); 134 } 135 } 136 137 141 protected void updateMainTypeFromConfig(ILaunchConfiguration config) { 142 String mainTypeName = EMPTY_STRING; 143 try { 144 mainTypeName = config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, EMPTY_STRING); 145 } 146 catch (CoreException ce) {JDIDebugUIPlugin.log(ce);} 147 fMainText.setText(mainTypeName); 148 } 149 } 150 | Popular Tags |