View | Details | Raw Unified | Return to bug 111501 | Differences between
and this patch

Collapse All | Expand All

(-)ui/org/eclipse/jdt/ui/JavaUI.java (-20 / +54 lines)
Lines 13-19 Link Here
13
import java.net.URL;
13
import java.net.URL;
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.Arrays;
15
import java.util.Arrays;
16
import java.util.Iterator;
17
import java.util.List;
16
import java.util.List;
18
17
19
import org.eclipse.core.runtime.IPath;
18
import org.eclipse.core.runtime.IPath;
Lines 28-34 Link Here
28
27
29
import org.eclipse.ui.IEditorPart;
28
import org.eclipse.ui.IEditorPart;
30
import org.eclipse.ui.PartInitException;
29
import org.eclipse.ui.PartInitException;
31
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
32
import org.eclipse.ui.dialogs.SelectionDialog;
30
import org.eclipse.ui.dialogs.SelectionDialog;
33
import org.eclipse.ui.texteditor.IDocumentProvider;
31
import org.eclipse.ui.texteditor.IDocumentProvider;
34
32
Lines 53-60 Link Here
53
import org.eclipse.jdt.internal.ui.SharedImages;
51
import org.eclipse.jdt.internal.ui.SharedImages;
54
import org.eclipse.jdt.internal.ui.dialogs.MainTypeSelectionDialog;
52
import org.eclipse.jdt.internal.ui.dialogs.MainTypeSelectionDialog;
55
import org.eclipse.jdt.internal.ui.dialogs.MultiMainTypeSelectionDialog;
53
import org.eclipse.jdt.internal.ui.dialogs.MultiMainTypeSelectionDialog;
54
import org.eclipse.jdt.internal.ui.dialogs.PackageSelectionDialog;
56
import org.eclipse.jdt.internal.ui.dialogs.TypeSelectionDialog2;
55
import org.eclipse.jdt.internal.ui.dialogs.TypeSelectionDialog2;
57
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
56
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
57
import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
58
58
59
/**
59
/**
60
 * Central access point for the Java UI plug-in (id <code>"org.eclipse.jdt.ui"</code>).
60
 * Central access point for the Java UI plug-in (id <code>"org.eclipse.jdt.ui"</code>).
Lines 318-339 Link Here
318
			}
318
			}
319
		}
319
		}
320
		
320
		
321
		int flags= JavaElementLabelProvider.SHOW_DEFAULT;
321
		IJavaSearchScope searchScope= SearchEngine.createJavaSearchScope((IJavaElement[])consideredRoots.toArray(new IJavaElement[consideredRoots.size()]));
322
		if (consideredRoots.size() > 1)
322
		BusyIndicatorRunnableContext context= new BusyIndicatorRunnableContext();
323
			flags= flags | JavaElementLabelProvider.SHOW_ROOT;
323
		if (style == 0 || style == IJavaElementSearchConstants.CONSIDER_REQUIRED_PROJECTS) {
324
324
			return createPackageDialog(parent, context, searchScope, false, true, filter);
325
		List packages= new ArrayList();
325
		} else {
326
		Iterator iter= consideredRoots.iterator();
326
			return createPackageDialog(parent, context, searchScope, false, false, filter);
327
		while(iter.hasNext()) {
327
		}
328
			IPackageFragmentRoot root= (IPackageFragmentRoot)iter.next();
328
	}
329
			packages.addAll(Arrays.asList(root.getChildren()));
329
	
330
		}			
330
	/**
331
		ElementListSelectionDialog dialog= new ElementListSelectionDialog(parent, new JavaElementLabelProvider(flags));
331
	 * Creates a selection dialog that lists all packages of the given Java search scope.
332
		dialog.setIgnoreCase(false);
332
	 * The caller is responsible for opening the dialog with <code>Window.open</code>,
333
		dialog.setElements(packages.toArray()); // XXX inefficient
333
	 * and subsequently extracting the selected package (of type
334
	 * <code>IPackageFragment</code>) via <code>SelectionDialog.getResult</code>.
335
	 * 
336
	 * @param parent the parent shell of the dialog to be created
337
	 * @param context the runnable context to run the search in
338
	 * @param scope the scope defining the available packages.
339
	 * @param multipleSelection true if multiple selection is allowed
340
	 * @param removeDuplicates true if only one package is shown per package name
341
	 * @param filter the initial pattern to filter the set of packages. For example "com" shows 
342
	 * all packages starting with "com". The meta character '?' representing any character and 
343
	 * '*' representing any string are supported. Clients can pass an empty string if no filtering 
344
	 * is required.
345
	 * @return a new selection dialog
346
	 * 
347
	 * @since 3.2
348
	 */
349
	public static SelectionDialog createPackageDialog(Shell parent, IRunnableContext context, IJavaSearchScope scope, 
350
			boolean multipleSelection, boolean removeDuplicates, String filter) {
351
		
352
		int flag= removeDuplicates?PackageSelectionDialog.F_REMOVE_DUPLICATES:0;
353
		PackageSelectionDialog dialog= new PackageSelectionDialog(parent, context, flag, scope);
334
		dialog.setFilter(filter);
354
		dialog.setFilter(filter);
355
		dialog.setIgnoreCase(false);
356
		dialog.setMultipleSelection(multipleSelection);
335
		return dialog;
357
		return dialog;
336
	}
358
	}
359
	
360
	/**
361
	 * Creates a selection dialog that lists all packages of the given Java search scope.
362
	 * The caller is responsible for opening the dialog with <code>Window.open</code>,
363
	 * and subsequently extracting the selected package (of type
364
	 * <code>IPackageFragment</code>) via <code>SelectionDialog.getResult</code>.
365
	 * 
366
	 * @param parent the parent shell of the dialog to be created
367
	 * @param context the runnable context to run the search in
368
	 * @param scope the scope defining the available packages.
369
	 */
370
	public SelectionDialog createPackageDialog(Shell parent, IRunnableContext context, IJavaSearchScope scope) {
371
		return createPackageDialog(parent, context, scope, false, true, ""); //$NON-NLS-1$
372
	}
337
373
338
	/**
374
	/**
339
	 * Creates a selection dialog that lists all packages of the given Java project.
375
	 * Creates a selection dialog that lists all packages of the given Java project.
Lines 375-385 Link Here
375
	 * @since 2.0
411
	 * @since 2.0
376
	 */
412
	 */
377
	public static SelectionDialog createPackageDialog(Shell parent, IPackageFragmentRoot root, String filter) throws JavaModelException {
413
	public static SelectionDialog createPackageDialog(Shell parent, IPackageFragmentRoot root, String filter) throws JavaModelException {
378
		ElementListSelectionDialog dialog= new ElementListSelectionDialog(parent, new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT));
414
		IJavaSearchScope scope= SearchEngine.createJavaSearchScope(new IJavaElement[] {root});
379
		dialog.setIgnoreCase(false);
415
		BusyIndicatorRunnableContext context= new BusyIndicatorRunnableContext();
380
		dialog.setElements(root.getChildren());
416
		return createPackageDialog(parent, context, scope, false, true, filter);
381
		dialog.setFilter(filter);
382
		return dialog;
383
	}
417
	}
384
418
385
	/**
419
	/**
(-)ui/org/eclipse/jdt/ui/tests/dialogs/DialogsTest2.java (-4 / +39 lines)
Lines 10-34 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.ui.tests.dialogs;
11
package org.eclipse.jdt.ui.tests.dialogs;
12
12
13
import java.io.IOException;
14
import java.lang.reflect.InvocationTargetException;
15
13
import junit.framework.Test;
16
import junit.framework.Test;
14
import junit.framework.TestCase;
17
import junit.framework.TestCase;
15
import junit.framework.TestSuite;
18
import junit.framework.TestSuite;
16
19
20
import org.eclipse.core.runtime.CoreException;
21
17
import org.eclipse.swt.widgets.Shell;
22
import org.eclipse.swt.widgets.Shell;
18
23
19
import org.eclipse.jface.viewers.ILabelProvider;
24
import org.eclipse.jface.viewers.ILabelProvider;
20
25
21
import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog;
26
import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog;
27
import org.eclipse.ui.dialogs.SelectionDialog;
22
28
23
import org.eclipse.jdt.core.IJavaProject;
29
import org.eclipse.jdt.core.IJavaProject;
30
import org.eclipse.jdt.core.IPackageFragmentRoot;
24
31
25
import org.eclipse.jdt.testplugin.JavaProjectHelper;
32
import org.eclipse.jdt.ui.IJavaElementSearchConstants;
26
import org.eclipse.jdt.testplugin.util.DialogCheck;
27
28
import org.eclipse.jdt.ui.JavaElementLabelProvider;
33
import org.eclipse.jdt.ui.JavaElementLabelProvider;
29
import org.eclipse.jdt.ui.JavaElementSorter;
34
import org.eclipse.jdt.ui.JavaElementSorter;
35
import org.eclipse.jdt.ui.JavaUI;
30
import org.eclipse.jdt.ui.StandardJavaElementContentProvider;
36
import org.eclipse.jdt.ui.StandardJavaElementContentProvider;
31
37
38
import org.eclipse.jdt.testplugin.JavaProjectHelper;
39
import org.eclipse.jdt.testplugin.util.DialogCheck;
40
32
public class DialogsTest2 extends TestCase {
41
public class DialogsTest2 extends TestCase {
33
	
42
	
34
	private static final String PROJECT_NAME = "DummyProject";
43
	private static final String PROJECT_NAME = "DummyProject";
Lines 37-42 Link Here
37
		TestSuite suite= new TestSuite(DialogsTest2.class.getName());
46
		TestSuite suite= new TestSuite(DialogsTest2.class.getName());
38
		suite.addTest(new DialogsTest2("testCheckedTreeSelectionDialog"));
47
		suite.addTest(new DialogsTest2("testCheckedTreeSelectionDialog"));
39
		suite.addTest(new DialogsTest2("testCheckedTreeSelectionDialog"));
48
		suite.addTest(new DialogsTest2("testCheckedTreeSelectionDialog"));
49
		suite.addTest(new DialogsTest2("testPackageSelectionDialog01"));
50
		suite.addTest(new DialogsTest2("testPackageSelectionDialog02"));
40
		return suite;
51
		return suite;
41
	}
52
	}
42
53
Lines 78-83 Link Here
78
		JavaProjectHelper.delete(jproject);	
89
		JavaProjectHelper.delete(jproject);	
79
		JavaProjectHelper.delete(jproject2);
90
		JavaProjectHelper.delete(jproject2);
80
	}
91
	}
92
	
93
	public void testPackageSelectionDialog01() throws CoreException, IOException, InvocationTargetException {
94
		IJavaProject jproject= JavaProjectHelper.createJavaProjectWithJUnitSource(PROJECT_NAME, "src", "bin");
81
95
82
}
96
		SelectionDialog dialog= JavaUI.createPackageDialog(getShell(), jproject, IJavaElementSearchConstants.CONSIDER_BINARIES, "");	
97
		dialog.setBlockOnOpen(false);
98
		dialog.open();
99
		
100
		DialogCheck.assertDialog(dialog);
101
		
102
		JavaProjectHelper.delete(jproject);	
103
	}
104
	
105
	public void testPackageSelectionDialog02() throws CoreException, IOException, InvocationTargetException {
106
		IJavaProject jproject= JavaProjectHelper.createJavaProjectWithJUnitSource(PROJECT_NAME, "src", "bin");
107
108
		IPackageFragmentRoot root= jproject.getPackageFragmentRoots()[0];
109
		SelectionDialog dialog= JavaUI.createPackageDialog(getShell(), root, "");	
110
		dialog.setBlockOnOpen(false);
111
		dialog.open();
112
		
113
		DialogCheck.assertDialog(dialog);
114
		
115
		JavaProjectHelper.delete(jproject);	
116
	}
83
117
118
}

Return to bug 111501