private void selectSourceFolder() {
try {
Class<?>[] acceptedClasses = new Class<?>[] { IJavaModel.class, IJavaProject.class, IPackageFragmentRoot.class };
ISelectionStatusValidator validator = new TypedElementSelectionValidator(acceptedClasses, false);
IPackageFragmentRoot init = null;
IJavaProject project = JavaCore.create(getProject());
IPackageFragmentRoot[] roots = project.getPackageFragmentRoots();
List<IJavaElement> rejectedElements = new ArrayList<IJavaElement>();
for (int i = 0; i < roots.length; i++) {
if (roots[i] instanceof JarPackageFragmentRoot) {
rejectedElements.add(roots[i]);
} else if(roots[i] instanceof IPackageFragmentRoot){
if(((IPackageFragmentRoot)roots[i]).isArchive() || ((IPackageFragmentRoot)roots[i]).isExternal()){
rejectedElements.add(roots[i]);
} else {
if(roots[i].getResource().getProjectRelativePath().toString().equals(sourceFolder.getText())){
init = roots[i];
}
}
}
}
IJavaModel model = (IJavaModel)project.getParent();
IJavaProject[] projects = model.getJavaProjects();
for(int i=0;i<projects.length;i++){
if(!projects[i].equals(project)){
rejectedElements.add(projects[i]);
}
}
ViewerFilter filter = new TypedViewerFilter(acceptedClasses, rejectedElements.toArray());
FolderSelectionDialog dialog = new FolderSelectionDialog(
getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
dialog.setTitle(ClickPlugin.getString("wizard.newPage.dialog.selectSourceFolder"));
//dialog.setMessage(HTMLPlugin.getResourceString("HTMLProjectPropertyPage.WebRoot"));
dialog.setInput(model);
dialog.setValidator(validator);
dialog.addFilter(filter);
dialog.setInitialSelection(init);
if (dialog.open() == FolderSelectionDialog.OK) {
IPackageFragmentRoot root = (IPackageFragmentRoot) dialog.getFirstResult();
sourceFolder.setText(root.getPath().makeRelativeTo(project.getPath()).toString());
}
} catch (Throwable t) {
ClickPlugin.log(t);
}