View | Details | Raw Unified | Return to bug 167638
Collapse All | Expand All

(-)ui/org/eclipse/jdt/internal/debug/ui/launcher/JavaLaunchShortcut.java (-27 / +12 lines)
Lines 25-36 Link Here
25
import org.eclipse.debug.ui.ILaunchShortcut;
25
import org.eclipse.debug.ui.ILaunchShortcut;
26
import org.eclipse.jdt.core.IJavaElement;
26
import org.eclipse.jdt.core.IJavaElement;
27
import org.eclipse.jdt.core.IType;
27
import org.eclipse.jdt.core.IType;
28
import org.eclipse.jdt.core.JavaModelException;
29
import org.eclipse.jdt.core.search.SearchEngine;
30
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
28
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
31
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
29
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
32
import org.eclipse.jdt.ui.IJavaElementSearchConstants;
33
import org.eclipse.jdt.ui.JavaUI;
34
import org.eclipse.jface.dialogs.MessageDialog;
30
import org.eclipse.jface.dialogs.MessageDialog;
35
import org.eclipse.jface.operation.IRunnableContext;
31
import org.eclipse.jface.operation.IRunnableContext;
36
import org.eclipse.jface.viewers.ISelection;
32
import org.eclipse.jface.viewers.ISelection;
Lines 41-47 Link Here
41
import org.eclipse.ui.IEditorPart;
37
import org.eclipse.ui.IEditorPart;
42
import org.eclipse.ui.PlatformUI;
38
import org.eclipse.ui.PlatformUI;
43
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
39
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
44
import org.eclipse.ui.dialogs.SelectionDialog;
45
40
46
/**
41
/**
47
 * Common behavior for Java launch shortcuts
42
 * Common behavior for Java launch shortcuts
Lines 59-81 Link Here
59
		IType[] types = null;
54
		IType[] types = null;
60
		try {
55
		try {
61
			types = findTypes(search, PlatformUI.getWorkbench().getProgressService());
56
			types = findTypes(search, PlatformUI.getWorkbench().getProgressService());
62
		} catch (InterruptedException e) {
57
		} 
63
			return;
58
		catch (InterruptedException e) {return;} 
64
		} catch (CoreException e) {
59
		catch (CoreException e) {
65
			MessageDialog.openError(getShell(), LauncherMessages.JavaLaunchShortcut_0, e.getMessage()); 
60
			MessageDialog.openError(getShell(), LauncherMessages.JavaLaunchShortcut_0, e.getMessage()); 
66
			return;
61
			return;
67
		}
62
		}
68
		IType type = null;
63
		IType type = null;
69
		if (types.length == 0) {
64
		if (types.length == 0) {
70
			MessageDialog.openError(getShell(), LauncherMessages.JavaLaunchShortcut_1, emptyMessage); 
65
			MessageDialog.openError(getShell(), LauncherMessages.JavaLaunchShortcut_1, emptyMessage); 
71
		} else if (types.length > 1) {
66
		} 
72
			try {
67
		else if (types.length > 1) {
73
				type = chooseType(types, selectMessage);
68
			type = chooseType(types, selectMessage);
74
			} catch (JavaModelException e) {
69
		} 
75
				reportErorr(e); 
70
		else {
76
				return;
77
			}
78
		} else {
79
			type = types[0];
71
			type = types[0];
80
		}
72
		}
81
		if (type != null) {
73
		if (type != null) {
Lines 102-118 Link Here
102
	 * 
94
	 * 
103
	 * @return the selected type or <code>null</code> if none.
95
	 * @return the selected type or <code>null</code> if none.
104
	 */
96
	 */
105
	protected IType chooseType(IType[] types, String title) throws JavaModelException {
97
	protected IType chooseType(IType[] types, String title) {
106
		SelectionDialog dialog = JavaUI.createTypeDialog(
98
		MainMethodSelectionDialog mmsd = new MainMethodSelectionDialog(types, new MainMethodLabelProvider(), title, LauncherMessages.JavaMainTab_Choose_a_main__type_to_launch__12);
107
				getShell(),
99
		if (mmsd.open() == Window.OK) {
108
				PlatformUI.getWorkbench().getProgressService(), 
100
			return (IType)mmsd.getResult()[0];
109
				SearchEngine.createJavaSearchScope(types), 
110
				IJavaElementSearchConstants.CONSIDER_CLASSES, 
111
				false, "**"); //$NON-NLS-1$
112
		dialog.setMessage(LauncherMessages.JavaMainTab_Choose_a_main__type_to_launch__12);
113
		dialog.setTitle(title);
114
		if (dialog.open() == Window.OK) {
115
			return (IType)dialog.getResult()[0];
116
		}
101
		}
117
		return null;
102
		return null;
118
	}
103
	}
(-)ui/org/eclipse/jdt/internal/debug/ui/launcher/MainMethodSearchEngine.java (-9 / +16 lines)
Lines 104-128 Link Here
104
		return (IType[]) result.toArray(new IType[result.size()]);
104
		return (IType[]) result.toArray(new IType[result.size()]);
105
	}
105
	}
106
106
107
	/**
108
	 * Adds subtypes and enclosed types to the listing of 'found' types 
109
	 * @param types the list of found types thus far
110
	 * @param monitor progress monitor
111
	 * @param scope the scope of elements
112
	 * @return as set of all types to consider
113
	 */
107
	private Set addSubtypes(List types, IProgressMonitor monitor, IJavaSearchScope scope) {
114
	private Set addSubtypes(List types, IProgressMonitor monitor, IJavaSearchScope scope) {
108
		Iterator iterator = types.iterator();
115
		Iterator iterator = types.iterator();
109
		Set result = new HashSet(types.size());
116
		Set result = new HashSet(types.size());
117
		IType type = null;
118
		ITypeHierarchy hierarchy = null;
119
		IType[] subtypes = null;
110
		while (iterator.hasNext()) {
120
		while (iterator.hasNext()) {
111
			IType type = (IType) iterator.next();
121
			type = (IType) iterator.next();
112
			if (result.add(type)) {
122
			if (result.add(type)) {
113
				ITypeHierarchy hierarchy = null;
114
				try {
123
				try {
115
					hierarchy = type.newTypeHierarchy(monitor);
124
					hierarchy = type.newTypeHierarchy(monitor);
116
					IType[] subtypes = hierarchy.getAllSubtypes(type);
125
					subtypes = hierarchy.getAllSubtypes(type);
117
					for (int i = 0; i < subtypes.length; i++) {
126
					for (int i = 0; i < subtypes.length; i++) {
118
						IType t = subtypes[i];
127
						if (scope.encloses(subtypes[i])) {
119
						if (scope.encloses(t)) {
128
							result.add(subtypes[i]);
120
							result.add(t);
121
						}
129
						}
122
					}				
130
					}				
123
				} catch (JavaModelException e) {
131
				} 
124
					JDIDebugUIPlugin.log(e);
132
				catch (JavaModelException e) {JDIDebugUIPlugin.log(e);}
125
				}
126
			}
133
			}
127
			monitor.worked(1);
134
			monitor.worked(1);
128
		}
135
		}
(-)ui/org/eclipse/jdt/debug/ui/launchConfigurations/JavaMainTab.java (-19 / +5 lines)
Lines 33-42 Link Here
33
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
33
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
34
import org.eclipse.jdt.internal.debug.ui.SWTUtil;
34
import org.eclipse.jdt.internal.debug.ui.SWTUtil;
35
import org.eclipse.jdt.internal.debug.ui.launcher.LauncherMessages;
35
import org.eclipse.jdt.internal.debug.ui.launcher.LauncherMessages;
36
import org.eclipse.jdt.internal.debug.ui.launcher.MainMethodLabelProvider;
36
import org.eclipse.jdt.internal.debug.ui.launcher.MainMethodSearchEngine;
37
import org.eclipse.jdt.internal.debug.ui.launcher.MainMethodSearchEngine;
38
import org.eclipse.jdt.internal.debug.ui.launcher.MainMethodSelectionDialog;
37
import org.eclipse.jdt.internal.debug.ui.launcher.SharedJavaMainTab;
39
import org.eclipse.jdt.internal.debug.ui.launcher.SharedJavaMainTab;
38
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
40
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
39
import org.eclipse.jdt.ui.IJavaElementSearchConstants;
40
import org.eclipse.jdt.ui.ISharedImages;
41
import org.eclipse.jdt.ui.ISharedImages;
41
import org.eclipse.jdt.ui.JavaUI;
42
import org.eclipse.jdt.ui.JavaUI;
42
import org.eclipse.jface.window.Window;
43
import org.eclipse.jface.window.Window;
Lines 46-52 Link Here
46
import org.eclipse.swt.widgets.Button;
47
import org.eclipse.swt.widgets.Button;
47
import org.eclipse.swt.widgets.Composite;
48
import org.eclipse.swt.widgets.Composite;
48
import org.eclipse.ui.PlatformUI;
49
import org.eclipse.ui.PlatformUI;
49
import org.eclipse.ui.dialogs.SelectionDialog;
50
50
51
import com.ibm.icu.text.MessageFormat;
51
import com.ibm.icu.text.MessageFormat;
52
52
Lines 167-191 Link Here
167
			setErrorMessage(e.getMessage());
167
			setErrorMessage(e.getMessage());
168
			return;
168
			return;
169
		}
169
		}
170
		SelectionDialog dialog = null;
170
		MainMethodSelectionDialog mmsd = new MainMethodSelectionDialog(types, new MainMethodLabelProvider(), LauncherMessages.JavaMainTab_Choose_Main_Type_11, LauncherMessages.JavaMainTab_Choose_a_main__type_to_launch__12);
171
		try {
171
		if (mmsd.open() == Window.CANCEL) {
172
			dialog = JavaUI.createTypeDialog(
173
						getShell(),
174
						getLaunchConfigurationDialog(),
175
						SearchEngine.createJavaSearchScope(types),
176
						IJavaElementSearchConstants.CONSIDER_CLASSES, 
177
						false,
178
						"**"); //$NON-NLS-1$
179
		} catch (JavaModelException e) {
180
			setErrorMessage(e.getMessage());
181
			return;
182
			}
183
		dialog.setTitle(LauncherMessages.JavaMainTab_Choose_Main_Type_11); 
184
		dialog.setMessage(LauncherMessages.JavaMainTab_Choose_a_main__type_to_launch__12); 
185
		if (dialog.open() == Window.CANCEL) {
186
			return;
172
			return;
187
		}
173
		}
188
		Object[] results = dialog.getResult();	
174
		Object[] results = mmsd.getResult();	
189
		IType type = (IType)results[0];
175
		IType type = (IType)results[0];
190
		if (type != null) {
176
		if (type != null) {
191
			fMainText.setText(type.getFullyQualifiedName());
177
			fMainText.setText(type.getFullyQualifiedName());
(-)ui/org/eclipse/jdt/internal/debug/ui/launcher/MainMethodSelectionDialog.java (+39 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
14
import org.eclipse.jface.viewers.ILabelProvider;
15
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
16
17
/**
18
 * This is a specialixation of <code>ElementListSelectionDialog</code> used to present
19
 * users with a listing of <code>IType</code>s that contain main methods
20
 * 
21
 * @since 3.3
22
 * 
23
 * EXPERIMENTAL
24
 */
25
public class MainMethodSelectionDialog extends ElementListSelectionDialog {
26
	
27
	/**
28
	 * Constructor
29
	 * @param elements the types to display in the dialog
30
	 * @param title the title for the dialog
31
	 * @param message the message for the dialog
32
	 */
33
	public MainMethodSelectionDialog(Object[] elements, ILabelProvider lprovider, String title, String message) {
34
		super(JDIDebugUIPlugin.getShell(), lprovider);
35
		setElements(elements);
36
		setMessage(message);
37
		setTitle(title);
38
	}
39
}
(-)ui/org/eclipse/jdt/internal/debug/ui/launcher/MainMethodLabelProvider.java (+106 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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
import java.util.HashMap;
14
15
import org.eclipse.core.runtime.IAdaptable;
16
import org.eclipse.jdt.core.IType;
17
import org.eclipse.jface.resource.ImageDescriptor;
18
import org.eclipse.jface.viewers.ILabelProvider;
19
import org.eclipse.jface.viewers.ILabelProviderListener;
20
import org.eclipse.swt.graphics.Image;
21
import org.eclipse.ui.model.IWorkbenchAdapter;
22
23
/**
24
 * Class that provides the labels and images for the <code>MainMethodSelectionDialog</code>
25
 * 
26
 * @since 3.3
27
 * 
28
 * EXPERIMENTAL
29
 */
30
public class MainMethodLabelProvider implements ILabelProvider {
31
	
32
	HashMap fImageMap = new HashMap();
33
	
34
	/**
35
	 * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
36
	 */
37
	public Image getImage(Object element) {
38
		if(element instanceof IAdaptable) {
39
			IWorkbenchAdapter adapter = (IWorkbenchAdapter) ((IAdaptable)element).getAdapter(IWorkbenchAdapter.class);
40
			if(adapter != null) {
41
				ImageDescriptor descriptor = adapter.getImageDescriptor(element);
42
				Image image = (Image) fImageMap.get(descriptor);
43
				if(image == null) {
44
					image = descriptor.createImage();
45
					fImageMap.put(descriptor, image);
46
				}
47
				return image;
48
			}
49
		}
50
		return null;
51
	}
52
53
	/**
54
	 * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
55
	 */
56
	public String getText(Object element) {
57
		if(element instanceof IType) {
58
			IType type = (IType) element;
59
			String label = type.getElementName();
60
			String container = getDeclaringContainerName(type);
61
			if(container != null && !"".equals(container)) { //$NON-NLS-1$
62
				label += " - "+container; //$NON-NLS-1$
63
			}
64
			return label;
65
		}
66
		return null;
67
	}
68
	
69
	/**
70
	 * Returns the name of the declaring container name
71
	 * @param type the type to find the container name for
72
	 * @return the container name for the specified type
73
	 */
74
	private String getDeclaringContainerName(IType type) {
75
		IType outer = type.getDeclaringType();
76
		if(outer != null) {
77
			return outer.getFullyQualifiedName('.');
78
		}
79
		else {
80
			return type.getPackageFragment().getElementName();
81
		}
82
	}
83
	
84
	/**
85
	 * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
86
	 */
87
	public void dispose() {
88
		fImageMap.clear();
89
		fImageMap = null;
90
	}
91
	
92
	/**
93
	 * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
94
	 */
95
	public void addListener(ILabelProviderListener listener) {}
96
	
97
	/**
98
	 * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
99
	 */
100
	public boolean isLabelProperty(Object element, String property) {return false;}
101
	
102
	/**
103
	 * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
104
	 */
105
	public void removeListener(ILabelProviderListener listener) {}
106
}

Return to bug 167638