use of ch.acanda.eclipse.pmd.ui.dialog.FileSelectionDialog in project eclipse-pmd by acanda.
the class AddRuleSetConfigurationController method browseContainer.
private Optional<IResource> browseContainer(final Shell shell, final IContainer container) {
final FileSelectionDialog dialog = new FileSelectionDialog(shell);
dialog.setMessage("Choose a PMD rule set configuration:");
dialog.setValidator(new ISelectionStatusValidator() {
@Override
public IStatus validate(final Object[] selection) {
IStatus result = new Status(IStatus.OK, PMDPlugin.ID, "");
if (selection.length == 1 && !(selection[0] instanceof IContainer)) {
final IResource resource = (IResource) selection[0];
final String configuration = resource.getLocation().toOSString();
try {
new RuleSetFactory().createRuleSet(configuration);
} catch (final RuleSetNotFoundException | IllegalArgumentException e) {
// the rule set location is invalid
result = new Status(IStatus.WARNING, PMDPlugin.ID, resource.getName() + " is not a valid PMD rule set configuration");
}
} else {
result = new Status(IStatus.WARNING, PMDPlugin.ID, "");
}
return result;
}
});
dialog.setInput(container);
if (dialog.open() == Window.OK) {
return Optional.of((IResource) dialog.getFirstResult());
}
return Optional.absent();
}
Aggregations