KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > dialogs > MultiMainTypeSelectionDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.ui.dialogs;
12
13
14 import java.lang.reflect.InvocationTargetException JavaDoc;
15
16 import org.eclipse.core.runtime.Assert;
17
18 import org.eclipse.swt.widgets.Shell;
19
20 import org.eclipse.jface.operation.IRunnableContext;
21
22 import org.eclipse.ui.dialogs.ElementListSelectionDialog;
23 import org.eclipse.ui.PlatformUI;
24
25 import org.eclipse.jdt.core.IType;
26 import org.eclipse.jdt.core.search.IJavaSearchScope;
27
28 import org.eclipse.jdt.ui.JavaElementLabelProvider;
29
30 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
31 import org.eclipse.jdt.internal.ui.JavaUIMessages;
32 import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
33 import org.eclipse.jdt.internal.ui.util.MainMethodSearchEngine;
34
35 /**
36  * A dialog to select a type from a list of types. The dialog allows
37  * multiple selections.
38  */

39 public class MultiMainTypeSelectionDialog extends ElementListSelectionDialog {
40
41     private IRunnableContext fRunnableContext;
42     private IJavaSearchScope fScope;
43     private int fStyle;
44         
45     /**
46      * Constructor.
47      */

48     public MultiMainTypeSelectionDialog(Shell shell, IRunnableContext context,
49         IJavaSearchScope scope, int style)
50     {
51         super(shell, new JavaElementLabelProvider(
52             JavaElementLabelProvider.SHOW_PARAMETERS | JavaElementLabelProvider.SHOW_POST_QUALIFIED | JavaElementLabelProvider.SHOW_ROOT));
53
54         setMultipleSelection(true);
55
56         Assert.isNotNull(context);
57         Assert.isNotNull(scope);
58         
59         fRunnableContext= context;
60         fScope= scope;
61         fStyle= style;
62     }
63
64     /*
65      * @see Window#open()
66      */

67     public int open() {
68         MainMethodSearchEngine engine= new MainMethodSearchEngine();
69         IType[] types;
70         try {
71             types= engine.searchMainMethods(fRunnableContext, fScope, fStyle);
72         } catch (InterruptedException JavaDoc e) {
73             return CANCEL;
74         } catch (InvocationTargetException JavaDoc e) {
75             //XX: to do
76
ExceptionHandler.handle(e, JavaUIMessages.MultiMainTypeSelectionDialog_errorTitle, e.getMessage());
77             return CANCEL;
78         }
79         
80         setElements(types);
81         return super.open();
82     }
83     
84     /*
85      * @see org.eclipse.jface.window.Window#configureShell(Shell)
86      */

87     protected void configureShell(Shell newShell) {
88         super.configureShell(newShell);
89         PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaHelpContextIds.MULTI_MAIN_TYPE_SELECTION_DIALOG);
90     }
91
92
93 }
94
Popular Tags