use of org.eclipse.ui.IWorkingSet in project pmd-eclipse-plugin by pmd.
the class ProjectPropertiesModelTest method testProjectWorkingSetNull.
/**
* A project may work only on a subset of files defined by a working set
*/
@Test
public void testProjectWorkingSetNull() throws PropertiesException {
final IProjectPropertiesManager mgr = PMDPlugin.getDefault().getPropertiesManager();
final IProjectProperties model = mgr.loadProjectProperties(this.testProject);
model.setProjectWorkingSet(null);
final IWorkingSet w = model.getProjectWorkingSet();
Assert.assertNull("The project should not have a working set defined", w);
}
use of org.eclipse.ui.IWorkingSet in project pmd-eclipse-plugin by pmd.
the class PMDCheckAction method reviewSelectedResources.
/**
* Prepare and run the reviewCode command for all selected resources
*
* @param selection
* the selected resources
*/
private void reviewSelectedResources(IStructuredSelection selection) throws CommandException {
ReviewCodeCmd cmd = new ReviewCodeCmd();
// Add selected resources to the list of resources to be reviewed
for (Iterator<?> i = selection.iterator(); i.hasNext(); ) {
Object element = i.next();
if (element instanceof AbstractPMDRecord) {
IResource resource = ((AbstractPMDRecord) element).getResource();
if (resource != null) {
cmd.addResource(resource);
} else {
LOG.warn("The selected object has no resource");
LOG.debug(" -> selected object : " + element);
}
} else if (element instanceof IWorkingSet) {
IWorkingSet set = (IWorkingSet) element;
for (IAdaptable adaptable : set.getElements()) {
addAdaptable(cmd, adaptable);
}
} else if (element instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) element;
addAdaptable(cmd, adaptable);
} else {
LOG.warn("The selected object is not adaptable");
LOG.debug(" -> selected object : " + element);
}
}
// Run the command
setupAndExecute(cmd, countElements(selection));
}
use of org.eclipse.ui.IWorkingSet in project pmd-eclipse-plugin by pmd.
the class BaseVisitor method isFileInWorkingSet.
/**
* Test if a file is in the PMD working set
*
* @param file
* @return true if the file should be checked
*/
private boolean isFileInWorkingSet(final IFile file) throws PropertiesException {
boolean fileInWorkingSet = true;
IWorkingSet workingSet = projectProperties.getProjectWorkingSet();
if (workingSet != null) {
ResourceWorkingSetFilter filter = new ResourceWorkingSetFilter();
filter.setWorkingSet(workingSet);
fileInWorkingSet = filter.select(null, null, file);
}
return fileInWorkingSet;
}
use of org.eclipse.ui.IWorkingSet in project pmd-eclipse-plugin by pmd.
the class PMDPropertyPageController method selectWorkingSet.
/**
* Process a select workingset event
*
* @param currentWorkingSet
* the working set currently selected of null if none
* @return the newly selected working set or null if none.
*/
public IWorkingSet selectWorkingSet(final IWorkingSet currentWorkingSet) {
final IWorkbench workbench = PlatformUI.getWorkbench();
final IWorkingSetManager workingSetManager = workbench.getWorkingSetManager();
final IWorkingSetSelectionDialog selectionDialog = workingSetManager.createWorkingSetSelectionDialog(this.shell, false);
IWorkingSet selectedWorkingSet = null;
if (currentWorkingSet != null) {
selectionDialog.setSelection(new IWorkingSet[] { currentWorkingSet });
}
if (selectionDialog.open() == Window.OK) {
if (selectionDialog.getSelection().length == 0) {
LOG.info("Deselect working set");
} else {
selectedWorkingSet = selectionDialog.getSelection()[0];
LOG.info("Working set " + selectedWorkingSet.getName() + " selected");
}
}
return selectedWorkingSet;
}
Aggregations