Search in sources :

Example 51 with IWorkingSet

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);
}
Also used : IWorkingSet(org.eclipse.ui.IWorkingSet) Test(org.junit.Test)

Example 52 with IWorkingSet

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));
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) ReviewCodeCmd(net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd) IResource(org.eclipse.core.resources.IResource) IWorkingSet(org.eclipse.ui.IWorkingSet) AbstractPMDRecord(net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)

Example 53 with IWorkingSet

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;
}
Also used : ResourceWorkingSetFilter(org.eclipse.ui.ResourceWorkingSetFilter) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 54 with IWorkingSet

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;
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkingSetManager(org.eclipse.ui.IWorkingSetManager) IWorkingSetSelectionDialog(org.eclipse.ui.dialogs.IWorkingSetSelectionDialog) IWorkingSet(org.eclipse.ui.IWorkingSet)

Aggregations

IWorkingSet (org.eclipse.ui.IWorkingSet)54 IWorkingSetManager (org.eclipse.ui.IWorkingSetManager)17 IAdaptable (org.eclipse.core.runtime.IAdaptable)15 IResource (org.eclipse.core.resources.IResource)10 IProject (org.eclipse.core.resources.IProject)9 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)8 IFile (org.eclipse.core.resources.IFile)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 IWorkingSetSelectionDialog (org.eclipse.ui.dialogs.IWorkingSetSelectionDialog)5 List (java.util.List)4 CoreException (org.eclipse.core.runtime.CoreException)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 ISelection (org.eclipse.jface.viewers.ISelection)3 IWorkbench (org.eclipse.ui.IWorkbench)3 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)3 File (java.io.File)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Set (java.util.Set)2 IProjectDescription (org.eclipse.core.resources.IProjectDescription)2