eclipse插件开发常用的选择器

容器选择器(IFOlder,IPROJECT ,包等):


ContainerSelectionDialog dialog = new ContainerSelectionDialog(
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
ResourcesPlugin.getWorkspace().getRoot(), false,
"Select new file container");
if (dialog.open() == ContainerSelectionDialog.OK) {
Object[] result = dialog.getResult();
if (result.length == 1) {
org.eclipse.core.runtime.Path path = (org.eclipse.core.runtime.Path) result[0];
srcPath = path.toString();
System.out.println("=============" + srcPath);
srcPath.endsWith("src");


}
}


类选择器:

SelectionDialog s = JavaUI.createTypeDialog(shell,
null,
project.getProject(),
IJavaElementSearchConstants.CONSIDER_ALL_TYPES,
true);
if (s.open() == org.eclipse.jface.window.Window.OK) {
SourceType type = (SourceType) s
.getResult()[0];


unit = (ICompilationUnit) type.getParent();
LinkedList list = new LinkedList();
getPackage(unit, list);
pac = listToString(list);
text1.setText(pac);
}


系统目录选择:

DirectoryDialog dirDlg = new DirectoryDialog(shell);
String dir = dirDlg.open();

系统文件选择:

FileDialog fd = new FileDialog(
final String fileStr = fd.open();

posted @ 2011-12-30 16:36  饺子吃遍天  阅读(164)  评论(0编辑  收藏  举报