### Eclipse Workspace Patch 1.0
#P org.eclipse.jdt.debug.ui
Index: ui/org/eclipse/jdt/internal/debug/ui/launcher/JavaLaunchShortcut.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/launcher/JavaLaunchShortcut.java,v
retrieving revision 1.1
diff -u -r1.1 JavaLaunchShortcut.java
--- ui/org/eclipse/jdt/internal/debug/ui/launcher/JavaLaunchShortcut.java 4 Nov 2005 20:53:57 -0000 1.1
+++ ui/org/eclipse/jdt/internal/debug/ui/launcher/JavaLaunchShortcut.java 13 Dec 2006 22:40:40 -0000
@@ -25,12 +25,8 @@
import org.eclipse.debug.ui.ILaunchShortcut;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
-import org.eclipse.jdt.ui.IJavaElementSearchConstants;
-import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.viewers.ISelection;
@@ -41,7 +37,6 @@
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
-import org.eclipse.ui.dialogs.SelectionDialog;
/**
* Common behavior for Java launch shortcuts
@@ -59,23 +54,20 @@
IType[] types = null;
try {
types = findTypes(search, PlatformUI.getWorkbench().getProgressService());
- } catch (InterruptedException e) {
- return;
- } catch (CoreException e) {
+ }
+ catch (InterruptedException e) {return;}
+ catch (CoreException e) {
MessageDialog.openError(getShell(), LauncherMessages.JavaLaunchShortcut_0, e.getMessage());
return;
}
IType type = null;
if (types.length == 0) {
MessageDialog.openError(getShell(), LauncherMessages.JavaLaunchShortcut_1, emptyMessage);
- } else if (types.length > 1) {
- try {
- type = chooseType(types, selectMessage);
- } catch (JavaModelException e) {
- reportErorr(e);
- return;
- }
- } else {
+ }
+ else if (types.length > 1) {
+ type = chooseType(types, selectMessage);
+ }
+ else {
type = types[0];
}
if (type != null) {
@@ -102,17 +94,10 @@
*
* @return the selected type or null
if none.
*/
- protected IType chooseType(IType[] types, String title) throws JavaModelException {
- SelectionDialog dialog = JavaUI.createTypeDialog(
- getShell(),
- PlatformUI.getWorkbench().getProgressService(),
- SearchEngine.createJavaSearchScope(types),
- IJavaElementSearchConstants.CONSIDER_CLASSES,
- false, "**"); //$NON-NLS-1$
- dialog.setMessage(LauncherMessages.JavaMainTab_Choose_a_main__type_to_launch__12);
- dialog.setTitle(title);
- if (dialog.open() == Window.OK) {
- return (IType)dialog.getResult()[0];
+ protected IType chooseType(IType[] types, String title) {
+ MainMethodSelectionDialog mmsd = new MainMethodSelectionDialog(types, new MainMethodLabelProvider(), title, LauncherMessages.JavaMainTab_Choose_a_main__type_to_launch__12);
+ if (mmsd.open() == Window.OK) {
+ return (IType)mmsd.getResult()[0];
}
return null;
}
Index: ui/org/eclipse/jdt/internal/debug/ui/launcher/MainMethodSearchEngine.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/launcher/MainMethodSearchEngine.java,v
retrieving revision 1.12
diff -u -r1.12 MainMethodSearchEngine.java
--- ui/org/eclipse/jdt/internal/debug/ui/launcher/MainMethodSearchEngine.java 5 Aug 2005 15:57:56 -0000 1.12
+++ ui/org/eclipse/jdt/internal/debug/ui/launcher/MainMethodSearchEngine.java 13 Dec 2006 22:40:40 -0000
@@ -104,25 +104,32 @@
return (IType[]) result.toArray(new IType[result.size()]);
}
+ /**
+ * Adds subtypes and enclosed types to the listing of 'found' types
+ * @param types the list of found types thus far
+ * @param monitor progress monitor
+ * @param scope the scope of elements
+ * @return as set of all types to consider
+ */
private Set addSubtypes(List types, IProgressMonitor monitor, IJavaSearchScope scope) {
Iterator iterator = types.iterator();
Set result = new HashSet(types.size());
+ IType type = null;
+ ITypeHierarchy hierarchy = null;
+ IType[] subtypes = null;
while (iterator.hasNext()) {
- IType type = (IType) iterator.next();
+ type = (IType) iterator.next();
if (result.add(type)) {
- ITypeHierarchy hierarchy = null;
try {
hierarchy = type.newTypeHierarchy(monitor);
- IType[] subtypes = hierarchy.getAllSubtypes(type);
+ subtypes = hierarchy.getAllSubtypes(type);
for (int i = 0; i < subtypes.length; i++) {
- IType t = subtypes[i];
- if (scope.encloses(t)) {
- result.add(t);
+ if (scope.encloses(subtypes[i])) {
+ result.add(subtypes[i]);
}
}
- } catch (JavaModelException e) {
- JDIDebugUIPlugin.log(e);
- }
+ }
+ catch (JavaModelException e) {JDIDebugUIPlugin.log(e);}
}
monitor.worked(1);
}
Index: ui/org/eclipse/jdt/debug/ui/launchConfigurations/JavaMainTab.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/debug/ui/launchConfigurations/JavaMainTab.java,v
retrieving revision 1.43
diff -u -r1.43 JavaMainTab.java
--- ui/org/eclipse/jdt/debug/ui/launchConfigurations/JavaMainTab.java 28 Oct 2006 19:59:37 -0000 1.43
+++ ui/org/eclipse/jdt/debug/ui/launchConfigurations/JavaMainTab.java 13 Dec 2006 22:40:40 -0000
@@ -33,10 +33,11 @@
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
import org.eclipse.jdt.internal.debug.ui.SWTUtil;
import org.eclipse.jdt.internal.debug.ui.launcher.LauncherMessages;
+import org.eclipse.jdt.internal.debug.ui.launcher.MainMethodLabelProvider;
import org.eclipse.jdt.internal.debug.ui.launcher.MainMethodSearchEngine;
+import org.eclipse.jdt.internal.debug.ui.launcher.MainMethodSelectionDialog;
import org.eclipse.jdt.internal.debug.ui.launcher.SharedJavaMainTab;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
-import org.eclipse.jdt.ui.IJavaElementSearchConstants;
import org.eclipse.jdt.ui.ISharedImages;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jface.window.Window;
@@ -46,7 +47,6 @@
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.dialogs.SelectionDialog;
import com.ibm.icu.text.MessageFormat;
@@ -167,25 +167,11 @@
setErrorMessage(e.getMessage());
return;
}
- SelectionDialog dialog = null;
- try {
- dialog = JavaUI.createTypeDialog(
- getShell(),
- getLaunchConfigurationDialog(),
- SearchEngine.createJavaSearchScope(types),
- IJavaElementSearchConstants.CONSIDER_CLASSES,
- false,
- "**"); //$NON-NLS-1$
- } catch (JavaModelException e) {
- setErrorMessage(e.getMessage());
- return;
- }
- dialog.setTitle(LauncherMessages.JavaMainTab_Choose_Main_Type_11);
- dialog.setMessage(LauncherMessages.JavaMainTab_Choose_a_main__type_to_launch__12);
- if (dialog.open() == Window.CANCEL) {
+ MainMethodSelectionDialog mmsd = new MainMethodSelectionDialog(types, new MainMethodLabelProvider(), LauncherMessages.JavaMainTab_Choose_Main_Type_11, LauncherMessages.JavaMainTab_Choose_a_main__type_to_launch__12);
+ if (mmsd.open() == Window.CANCEL) {
return;
}
- Object[] results = dialog.getResult();
+ Object[] results = mmsd.getResult();
IType type = (IType)results[0];
if (type != null) {
fMainText.setText(type.getFullyQualifiedName());
Index: ui/org/eclipse/jdt/internal/debug/ui/launcher/MainMethodSelectionDialog.java
===================================================================
RCS file: ui/org/eclipse/jdt/internal/debug/ui/launcher/MainMethodSelectionDialog.java
diff -N ui/org/eclipse/jdt/internal/debug/ui/launcher/MainMethodSelectionDialog.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ui/org/eclipse/jdt/internal/debug/ui/launcher/MainMethodSelectionDialog.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.internal.debug.ui.launcher;
+
+import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.ui.dialogs.ElementListSelectionDialog;
+
+/**
+ * This is a specialixation of ElementListSelectionDialog
used to present
+ * users with a listing of IType
s that contain main methods
+ *
+ * @since 3.3
+ *
+ * EXPERIMENTAL
+ */
+public class MainMethodSelectionDialog extends ElementListSelectionDialog {
+
+ /**
+ * Constructor
+ * @param elements the types to display in the dialog
+ * @param title the title for the dialog
+ * @param message the message for the dialog
+ */
+ public MainMethodSelectionDialog(Object[] elements, ILabelProvider lprovider, String title, String message) {
+ super(JDIDebugUIPlugin.getShell(), lprovider);
+ setElements(elements);
+ setMessage(message);
+ setTitle(title);
+ }
+}
Index: ui/org/eclipse/jdt/internal/debug/ui/launcher/MainMethodLabelProvider.java
===================================================================
RCS file: ui/org/eclipse/jdt/internal/debug/ui/launcher/MainMethodLabelProvider.java
diff -N ui/org/eclipse/jdt/internal/debug/ui/launcher/MainMethodLabelProvider.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ui/org/eclipse/jdt/internal/debug/ui/launcher/MainMethodLabelProvider.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.internal.debug.ui.launcher;
+
+import java.util.HashMap;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.model.IWorkbenchAdapter;
+
+/**
+ * Class that provides the labels and images for the MainMethodSelectionDialog
+ *
+ * @since 3.3
+ *
+ * EXPERIMENTAL
+ */
+public class MainMethodLabelProvider implements ILabelProvider {
+
+ HashMap fImageMap = new HashMap();
+
+ /**
+ * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
+ */
+ public Image getImage(Object element) {
+ if(element instanceof IAdaptable) {
+ IWorkbenchAdapter adapter = (IWorkbenchAdapter) ((IAdaptable)element).getAdapter(IWorkbenchAdapter.class);
+ if(adapter != null) {
+ ImageDescriptor descriptor = adapter.getImageDescriptor(element);
+ Image image = (Image) fImageMap.get(descriptor);
+ if(image == null) {
+ image = descriptor.createImage();
+ fImageMap.put(descriptor, image);
+ }
+ return image;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
+ */
+ public String getText(Object element) {
+ if(element instanceof IType) {
+ IType type = (IType) element;
+ String label = type.getElementName();
+ String container = getDeclaringContainerName(type);
+ if(container != null && !"".equals(container)) { //$NON-NLS-1$
+ label += " - "+container; //$NON-NLS-1$
+ }
+ return label;
+ }
+ return null;
+ }
+
+ /**
+ * Returns the name of the declaring container name
+ * @param type the type to find the container name for
+ * @return the container name for the specified type
+ */
+ private String getDeclaringContainerName(IType type) {
+ IType outer = type.getDeclaringType();
+ if(outer != null) {
+ return outer.getFullyQualifiedName('.');
+ }
+ else {
+ return type.getPackageFragment().getElementName();
+ }
+ }
+
+ /**
+ * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
+ */
+ public void dispose() {
+ fImageMap.clear();
+ fImageMap = null;
+ }
+
+ /**
+ * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
+ */
+ public void addListener(ILabelProviderListener listener) {}
+
+ /**
+ * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
+ */
+ public boolean isLabelProperty(Object element, String property) {return false;}
+
+ /**
+ * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
+ */
+ public void removeListener(ILabelProviderListener listener) {}
+}