选择workspace中的文件对话框
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(shell, new WorkbenchLabelProvider(), new WorkbenchContentProvider());dialog.setInput(ResourcesPlugin.getWorkspace());dialog.addFilter(new ViewerFilter() {public boolean select(Viewer viewer, Object parentElement, Object element) {if (element instanceof IProject || element instanceof IFolder) {return true;}if (element instanceof IFile) {if (((IFile) element).getName().endsWith(".gif")) {return true;}}return false;}});dialog.setAllowMultiple(false);dialog.setTitle("select image file");dialog.setValidator(new ISelectionStatusValidator() {public IStatus validate(Object[] selection) {for (int i = 0; i < selection.length; i++) {Object object = selection[i];if (object instanceof IFile) {IFile file = (IFile) object;if (file.getName().endsWith(".gif")) {return Status.OK_STATUS;}return new Status(IStatus.ERROR, GraphicPlugin.PLUGIN_ID, 0, "", null);}}return new Status(IStatus.ERROR, GraphicPlugin.PLUGIN_ID, 0, "", null);}});if (dialog.open() == ContainerSelectionDialog.OK) {Object result = dialog.getFirstResult();if(result instanceof IFile){imagePath.setText(((IFile)result).getFullPath().toOSString());}}