Search in sources :

Example 1 with FileSelectionDialog

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();
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) RuleSetFactory(net.sourceforge.pmd.RuleSetFactory) IStatus(org.eclipse.core.runtime.IStatus) FileSelectionDialog(ch.acanda.eclipse.pmd.ui.dialog.FileSelectionDialog) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Aggregations

FileSelectionDialog (ch.acanda.eclipse.pmd.ui.dialog.FileSelectionDialog)1 RuleSetFactory (net.sourceforge.pmd.RuleSetFactory)1 IContainer (org.eclipse.core.resources.IContainer)1 IResource (org.eclipse.core.resources.IResource)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 ISelectionStatusValidator (org.eclipse.ui.dialogs.ISelectionStatusValidator)1