在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();
显示效果: