首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

抉择workspace中的文件对话框

2012-11-07 
选择workspace中的文件对话框ElementTreeSelectionDialog dialog new ElementTreeSelectionDialog(shell

选择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());}}

热点排行