KickJava   Java API By Example, From Geeks To Geeks.

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


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.jdt.core.IType;
19 import org.eclipse.jdt.core.search.IJavaSearchScope;
20 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
21 import org.eclipse.jdt.internal.ui.JavaUIMessages;
22 import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
23 import org.eclipse.jdt.internal.ui.util.MainMethodSearchEngine;
24 import org.eclipse.jdt.ui.JavaElementLabelProvider;
25 import org.eclipse.jface.operation.IRunnableContext;
26 import org.eclipse.swt.graphics.Image;
27 import org.eclipse.swt.widgets.Shell;
28 import org.eclipse.ui.PlatformUI;
29
30 import org.eclipse.ui.dialogs.TwoPaneElementSelector;
31
32 /**
33  * A dialog to select a type from a list of types. The dialog allows
34  * multiple selections.
35  */

36 public class MainTypeSelectionDialog extends TwoPaneElementSelector {
37
38     private IRunnableContext fRunnableContext;
39     private IJavaSearchScope fScope;
40     private int fStyle;
41     
42     private static class PackageRenderer extends JavaElementLabelProvider {
43         public PackageRenderer() {
44             super(JavaElementLabelProvider.SHOW_PARAMETERS | JavaElementLabelProvider.SHOW_POST_QUALIFIED | JavaElementLabelProvider.SHOW_ROOT);
45         }
46
47         public Image getImage(Object JavaDoc element) {
48             return super.getImage(((IType)element).getPackageFragment());
49         }
50         
51         public String JavaDoc getText(Object JavaDoc element) {
52             return super.getText(((IType)element).getPackageFragment());
53         }
54     }
55     
56     /**
57      * Constructor.
58      */

59     public MainTypeSelectionDialog(Shell shell, IRunnableContext context,
60         IJavaSearchScope scope, int style)
61     {
62         super(shell, new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_BASICS | JavaElementLabelProvider.SHOW_OVERLAY_ICONS),
63             new PackageRenderer());
64
65         Assert.isNotNull(context);
66         Assert.isNotNull(scope);
67
68         fRunnableContext= context;
69         fScope= scope;
70         fStyle= style;
71     }
72     
73     /*
74      * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
75      */

76     protected void configureShell(Shell newShell) {
77         super.configureShell(newShell);
78         PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaHelpContextIds.MAINTYPE_SELECTION_DIALOG);
79     }
80
81     /*
82      * @see Window#open()
83      */

84     public int open() {
85         MainMethodSearchEngine engine= new MainMethodSearchEngine();
86         IType[] types;
87         try {
88             types= engine.searchMainMethods(fRunnableContext, fScope, fStyle);
89         } catch (InterruptedException JavaDoc e) {
90             return CANCEL;
91         } catch (InvocationTargetException JavaDoc e) {
92             ExceptionHandler.handle(e, JavaUIMessages.MainTypeSelectionDialog_errorTitle, e.getMessage());
93             return CANCEL;
94         }
95         
96         setElements(types);
97         return super.open();
98     }
99     
100 }
101
Popular Tags