JDT:详解JavaUI.createTypeDialog方法

来源:互联网 发布:淘宝看店宝怎么下载 编辑:程序博客网 时间:2024/05/16 06:19
在eclipse中,诸如Open Type
 Choose Super Class
 
 
Add Interfaces
都是通过JavaUI.createTypeDialog方法来实现的,只是所传的参数不一样罢了。

我们主要看这个方法中的一些 context,scope ,style,  multipleSelection, filter参数。
public static SelectionDialog createTypeDialog(Shell parent, IRunnableContext context, IJavaSearchScope scope, int style, boolean multipleSelection, String filter);

context:我们可以传一new ProgressMonitorDialog(Shell shell)进去
scope:指搜索的区域(范围),可以传工程或工作空间进去,比如
IJavaSearchScope scope= SearchEngine.createJavaSearchScope(new IJavaElement[] { getJavaProject() });或SearchEngine.createWorkspaceScope();
style:表示对话框中显示的类型,可能为接口,类,枚举等等,可用的值如下:
param style flags defining the style of the dialog; the only valid values are
 *   <code>IJavaElementSearchConstants.CONSIDER_CLASSES</code>,
 *   <code>IJavaElementSearchConstants.CONSIDER_INTERFACES</code>,
 *   <code>IJavaElementSearchConstants.CONSIDER_ANNOTATION_TYPES</code>,
 *   <code>IJavaElementSearchConstants.CONSIDER_ENUMS</code>,
 *   <code>IJavaElementSearchConstants.CONSIDER_ALL_TYPES</code>,
 *   <code>IJavaElementSearchConstants.CONSIDER_CLASSES_AND_INTERFACES</code>
 *   <code>IJavaElementSearchConstants.CONSIDER_CLASSES_AND_ENUMS</code>. 
multipleSelection:是否可多选
filter:初始显示的过滤字符串
 
如下示例:
SelectionDialog dialog = JavaUI.createTypeDialog(window.getShell(),new ProgressMonitorDialog(window.getShell()) , SearchEngine.createWorkspaceScope(), IJavaElementSearchConstants.CONSIDER_CLASSES,false,"IPro");dialog.setTitle("标题");dialog.setMessage("提示信息");dialog.open();
显示效果:
原创粉丝点击