Search in sources :

Example 1 with AbstractPMDRecord

use of net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord in project pmd-eclipse-plugin by pmd.

the class ViolationOverview method newProjectNameSorter.

/**
 * Build a sorter for the project name column.
 *
 * @param column
 * @param sortOrder
 * @return
 */
private ViewerSorter newProjectNameSorter(TreeColumn column, final int sortOrder) {
    return new TableColumnSorter(column, sortOrder) {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            AbstractPMDRecord project1;
            AbstractPMDRecord project2;
            int result = 0;
            if (e1 instanceof PackageRecord && e2 instanceof PackageRecord) {
                project1 = ((PackageRecord) e1).getParent();
                project2 = ((PackageRecord) e2).getParent();
                result = project1.getName().compareToIgnoreCase(project2.getName()) * sortOrder;
            }
            return result;
        }
    };
}
Also used : Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) PackageRecord(net.sourceforge.pmd.eclipse.ui.model.PackageRecord) AbstractPMDRecord(net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)

Example 2 with AbstractPMDRecord

use of net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord in project pmd-eclipse-plugin by pmd.

the class ViolationOverview method treeExpanded.

/**
 * Calculates the LOC of the expanded file record.
 *
 * @see org.eclipse.jface.viewers.ITreeViewerListener#treeExpanded(org.eclipse.jface.viewers.TreeExpansionEvent)
 */
public void treeExpanded(TreeExpansionEvent event) {
    Object object = event.getElement();
    if (object instanceof PackageRecord) {
        PackageRecord record = (PackageRecord) object;
        AbstractPMDRecord[] children = record.getChildren();
        for (AbstractPMDRecord element : children) {
            if (element instanceof FileRecord) {
                FileRecord fileRecord = (FileRecord) element;
                fileRecord.calculateLinesOfCode();
                fileRecord.calculateNumberOfMethods();
            }
        }
    }
    // refresh the labels in the table
    Display.getDefault().asyncExec(new Runnable() {

        public void run() {
            getViewer().refresh();
        }
    });
}
Also used : PackageRecord(net.sourceforge.pmd.eclipse.ui.model.PackageRecord) FileRecord(net.sourceforge.pmd.eclipse.ui.model.FileRecord) AbstractPMDRecord(net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)

Example 3 with AbstractPMDRecord

use of net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord in project pmd-eclipse-plugin by pmd.

the class ViolationOverview method dispose.

/**
 * @see org.eclipse.ui.IWorkbenchPart#dispose()
 */
@Override
public void dispose() {
    memento.putList(PRIORITY_LIST, priorityFilter.getPriorityFilterList());
    // on Dispose of the View we save its State into a Memento
    // we save the filtered Projects
    List<AbstractPMDRecord> projects = projectFilter.getProjectFilterList();
    List<String> projectNames = new ArrayList<String>();
    for (int k = 0; k < projects.size(); k++) {
        AbstractPMDRecord project = projects.get(k);
        projectNames.add(project.getName());
    }
    memento.putList(PROJECT_LIST, projectNames);
    // ... the Columns Widths
    List<Integer> widthList = Arrays.asList(columnWidths);
    memento.putList(COLUMN_WIDTHS, widthList);
    // ... what Element is sorted in what way
    Integer[] sorterProps = new Integer[] { Integer.valueOf(currentSortedColumn), Integer.valueOf(columnSortOrder[currentSortedColumn]) };
    List<Integer> sorterList = Arrays.asList(sorterProps);
    memento.putList(COLUMN_SORTER, sorterList);
    // ... and how we should display the Elements
    memento.putInteger(PACKAGE_SWITCH, getShowType());
    memento.save();
    super.dispose();
}
Also used : ArrayList(java.util.ArrayList) AbstractPMDRecord(net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)

Example 4 with AbstractPMDRecord

use of net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord in project pmd-eclipse-plugin by pmd.

the class ViolationOverview method deleteMarkers.

/**
 * Deletes markers of an AbstractPMDRecord. This is performed after the
 * action Clear PMD Markers of the contextmenu was called.
 *
 * @param element
 * @throws CoreException
 */
public void deleteMarkers(AbstractPMDRecord element) throws CoreException {
    if (element instanceof MarkerRecord) {
        MarkerRecord record = (MarkerRecord) element;
        IMarker[] markers = MarkerUtil.EMPTY_MARKERS;
        switch(getShowType()) {
            case SHOW_PACKAGES_FILES_MARKERS:
            case SHOW_FILES_MARKERS:
                // simply get the markers of the marker record
                markers = record.findMarkers();
                break;
            case SHOW_MARKERS_FILES:
                AbstractPMDRecord packRec = record.getParent().getParent();
                markers = packRec.findMarkersByAttribute(PMDUiConstants.KEY_MARKERATT_RULENAME, record.getName());
                break;
            default:
        }
        deleteMarkers(markers);
    } else if (element instanceof FileToMarkerRecord) {
        FileToMarkerRecord record = (FileToMarkerRecord) element;
        IMarker[] markers = record.findMarkers();
        deleteMarkers(markers);
    } else {
        // simply delete markers from resource
        MarkerUtil.deleteAllMarkersIn(element.getResource());
    }
}
Also used : FileToMarkerRecord(net.sourceforge.pmd.eclipse.ui.model.FileToMarkerRecord) MarkerRecord(net.sourceforge.pmd.eclipse.ui.model.MarkerRecord) IMarker(org.eclipse.core.resources.IMarker) FileToMarkerRecord(net.sourceforge.pmd.eclipse.ui.model.FileToMarkerRecord) AbstractPMDRecord(net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)

Example 5 with AbstractPMDRecord

use of net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord in project pmd-eclipse-plugin by pmd.

the class ViolationOverviewContentProvider method updateViewer.

// public void resourceChanged(IResourceChangeEvent event) {
// 
// LOG.debug("resource changed event");
// 
// List<IMarkerDelta> markerDeltas = MarkerUtil.markerDeltasIn(event);
// 
// // first we get a List of changes to Files and Projects
// // so we won't need updating everything
// List<IResource> changedFiles = new ArrayList<IResource>();
// List<IProject> changedProjects = new ArrayList<IProject>();
// for (IMarkerDelta markerDelta : markerDeltas) {
// IResource resource = markerDelta.getResource();
// IProject project = resource.getProject();
// 
// // the lists should not contain Projects or Resources twice
// 
// if (!changedFiles.contains(resource)) {
// changedFiles.add(resource);
// LOG.debug("Resource " + resource.getName() + " has changed");
// }
// 
// if (!changedProjects.contains(project)) {
// changedProjects.add(project);
// LOG.debug("Project " + project.getName() + " has changed");
// }
// }
// 
// // we can add, change or remove Resources
// // all this changes are given to the viewer later
// final List<AbstractPMDRecord> additions = new ArrayList<AbstractPMDRecord>();
// final List<AbstractPMDRecord> removals = new ArrayList<AbstractPMDRecord>();
// final List<AbstractPMDRecord> changes = new ArrayList<AbstractPMDRecord>();
// 
// // we go through the changed Projects
// for (IProject project : changedProjects) {
// LOG.debug("Processing changes for project " + project.getName());
// ProjectRecord projectRec = (ProjectRecord) root.findResource(project);
// 
// // if the Project is closed or deleted,
// // we also delete it from the Model and go on
// if (!(project.isOpen() && project.isAccessible())) { // NOPMD by Sven on 09.11.06 22:17
// LOG.debug("The project is not open or not accessible. Remove it");
// List<AbstractPMDRecord>[] array = updateFiles(project, changedFiles);
// removals.addAll(array[1]);
// root.removeResource(project);
// }
// 
// // if we couldn't find the Project
// // then it has to be new
// else if (projectRec == null) {
// LOG.debug("Cannot find a project record for it. Add it.");
// projectRec = (ProjectRecord) root.addResource(project);
// }
// 
// // then we can update the Files for the new or updated Project
// List<AbstractPMDRecord>[] array = updateFiles(project, changedFiles);
// additions.addAll(array[0]);
// removals.addAll(array[1]);
// changes.addAll(array[2]);
// }
// 
// // the additions, removals and changes are given to the viewer
// // so that it can update itself
// // updating the table MUST be in sync
// treeViewer.getControl().getDisplay().syncExec(new Runnable() {
// public void run() {
// updateViewer(additions, removals, changes);
// }
// });
// }
/**
 * Updates the Files for a given Project
 *
 * @param project
 * @param changedFiles,
 *            a List of all changed Files
 * @return an List of Lists containing additions [0], removals [1] and changes [2] (Array-Position in Brackets)
 */
// protected List<AbstractPMDRecord>[] updateFiles(IProject project, List<IResource> changedFiles) {
// 
// final List<AbstractPMDRecord> additions = new ArrayList<AbstractPMDRecord>();
// final List<AbstractPMDRecord> removals = new ArrayList<AbstractPMDRecord>();
// final List<AbstractPMDRecord> changes = new ArrayList<AbstractPMDRecord>();
// List<AbstractPMDRecord>[] updatedFiles = new List[] { additions, removals, changes };
// 
// // we search for the ProjectRecord to the Project
// // if it doesn't exist, we return nothing
// final ProjectRecord projectRec = (ProjectRecord) root.findResource(project);
// 
// // we got through all files
// if (projectRec != null && project.isAccessible()) {
// updatedFiles = ChangeEvaluator.searchProjectForModifications(projectRec, changedFiles);
// }
// 
// // if the project is deleted or closed
// else if (projectRec != null) {
// final List<AbstractPMDRecord> packages = projectRec.getChildrenAsList();
// // ... we add all Packages to the removals
// // so they are not shown anymore
// removals.addAll(packages);
// for (int k = 0; k < packages.size(); k++) {
// final PackageRecord packageRec = (PackageRecord) packages.get(k);
// removals.addAll(packageRec.getChildrenAsList());
// }
// updatedFiles = new List[] { additions, removals, changes };
// }
// 
// return updatedFiles;
// }
// /**
// * Analyzes the modification inside a single project and compute the list of additions, updates and removals.
// *
// * @param projectRec
// * @param changedFiles
// * @return
// */
// private List<AbstractPMDRecord>[] searchProjectForModifications(ProjectRecord projectRec, List<IResource>
// changedFiles) {
// final List<AbstractPMDRecord> additions = new ArrayList<AbstractPMDRecord>();
// final List<AbstractPMDRecord> removals = new ArrayList<AbstractPMDRecord>();
// final List<AbstractPMDRecord> changes = new ArrayList<AbstractPMDRecord>();
// final IProject project = (IProject) projectRec.getResource();
// 
// LOG.debug("Analyses project " + project.getName());
// 
// for (IResource resource : changedFiles) {
// LOG.debug("Analyses resource " + resource.getName());
// 
// // ... and first check, if the project is the right one
// if (project.equals(resource.getProject())) {
// final AbstractPMDRecord rec = projectRec.findResource(resource);
// if (rec != null && rec.getResourceType() == IResource.FILE) {
// final FileRecord fileRec = (FileRecord) rec;
// fileRec.updateChildren();
// if (fileRec.getResource().isAccessible() && fileRec.hasMarkers()) {
// LOG.debug("The file has changed");
// changes.add(fileRec);
// } else {
// LOG.debug("The file has been removed");
// projectRec.removeResource(fileRec.getResource());
// removals.add(fileRec);
// 
// // remove parent if no more markers
// final PackageRecord packageRec = (PackageRecord) fileRec.getParent();
// if (!packageRec.hasMarkers()) {
// projectRec.removeResource(fileRec.getParent().getResource());
// removals.add(packageRec);
// }
// }
// } else if (rec == null) {
// LOG.debug("This is a new file.");
// final AbstractPMDRecord fileRec = projectRec.addResource(resource);
// additions.add(fileRec);
// } else {
// LOG.debug("The resource found is not a file! type found : " + rec.getResourceType());
// }
// } else {
// LOG.debug("The project resource is not the same! (" + resource.getProject().getName() + ')');
// }
// }
// 
// return new List[] { additions, removals, changes };
// }
/**
 * Applies found updates on the table, adapted from Philippe Herlin
 *
 * @param additions
 * @param removals
 * @param changes
 */
// protected void updateViewer(List<AbstractPMDRecord> additions, List<AbstractPMDRecord> removals,
// List<AbstractPMDRecord> changes) {
// 
// // perform removals
// if (removals.size() > 0) {
// treeViewer.cancelEditing();
// treeViewer.remove(removals.toArray());
// }
// 
// // perform additions
// if (additions.size() > 0) {
// for (int i = 0; i < additions.size(); i++) {
// final AbstractPMDRecord addedRec = additions.get(i);
// if (addedRec instanceof FileRecord) {
// treeViewer.add(addedRec.getParent(), addedRec);
// } else {
// treeViewer.add(root, addedRec);
// }
// }
// }
// 
// // perform changes
// if (changes.size() > 0) {
// treeViewer.update(changes.toArray(), null);
// }
// 
// violationView.refresh();
// }
protected void updateViewer(ChangeRecord<AbstractPMDRecord> changes) {
    // perform removals
    if (changes.hasRemovals()) {
        treeViewer.cancelEditing();
        treeViewer.remove(changes.removals.toArray());
    }
    // perform additions (if any)
    for (AbstractPMDRecord addedRec : changes.additions) {
        if (addedRec instanceof FileRecord) {
            treeViewer.add(addedRec.getParent(), addedRec);
        } else {
            treeViewer.add(root, addedRec);
        }
    }
    // perform changes
    if (changes.hasChanges()) {
        treeViewer.update(changes.changes.toArray(), null);
    }
    violationView.refresh();
}
Also used : FileRecord(net.sourceforge.pmd.eclipse.ui.model.FileRecord) AbstractPMDRecord(net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)

Aggregations

AbstractPMDRecord (net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)19 FileRecord (net.sourceforge.pmd.eclipse.ui.model.FileRecord)8 ArrayList (java.util.ArrayList)7 PackageRecord (net.sourceforge.pmd.eclipse.ui.model.PackageRecord)7 MarkerRecord (net.sourceforge.pmd.eclipse.ui.model.MarkerRecord)5 ProjectRecord (net.sourceforge.pmd.eclipse.ui.model.ProjectRecord)4 IResource (org.eclipse.core.resources.IResource)4 List (java.util.List)3 FileToMarkerRecord (net.sourceforge.pmd.eclipse.ui.model.FileToMarkerRecord)3 IMarker (org.eclipse.core.resources.IMarker)2 IProject (org.eclipse.core.resources.IProject)2 IAdaptable (org.eclipse.core.runtime.IAdaptable)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Rule (net.sourceforge.pmd.Rule)1 ReviewCodeCmd (net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd)1 ViolationOverview (net.sourceforge.pmd.eclipse.ui.views.ViolationOverview)1 CalculateStatisticsAction (net.sourceforge.pmd.eclipse.ui.views.actions.CalculateStatisticsAction)1 CollapseAllAction (net.sourceforge.pmd.eclipse.ui.views.actions.CollapseAllAction)1