Search in sources :

Example 1 with PackageRecord

use of net.sourceforge.pmd.eclipse.ui.model.PackageRecord 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 PackageRecord

use of net.sourceforge.pmd.eclipse.ui.model.PackageRecord 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 PackageRecord

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

the class ChangeEvaluator method updateFiles.

/**
 * 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)
 */
private List<AbstractPMDRecord>[] updateFiles(IProject project, List<IResource> changedFiles) {
    // TODO use ChangeRecord
    List<AbstractPMDRecord> additions = new ArrayList<AbstractPMDRecord>();
    List<AbstractPMDRecord> removals = new ArrayList<AbstractPMDRecord>();
    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
    ProjectRecord projectRec = (ProjectRecord) root.findResource(project);
    // we got through all files
    if (projectRec != null && project.isAccessible()) {
        updatedFiles = searchProjectForModifications(projectRec, changedFiles);
    } else if (projectRec != null) {
        // if the project is deleted or closed
        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++) {
            PackageRecord packageRec = (PackageRecord) packages.get(k);
            removals.addAll(packageRec.getChildrenAsList());
        }
        updatedFiles = new List[] { additions, removals, changes };
    }
    return updatedFiles;
}
Also used : ArrayList(java.util.ArrayList) ProjectRecord(net.sourceforge.pmd.eclipse.ui.model.ProjectRecord) List(java.util.List) ArrayList(java.util.ArrayList) PackageRecord(net.sourceforge.pmd.eclipse.ui.model.PackageRecord) AbstractPMDRecord(net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)

Example 4 with PackageRecord

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

the class ViolationOverviewContentProvider method getParent.

/**
 * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
 */
public Object getParent(Object element) {
    Object parent = null;
    AbstractPMDRecord record = (AbstractPMDRecord) element;
    switch(violationView.getShowType()) {
        case ViolationOverview.SHOW_FILES_MARKERS:
            if (element instanceof FileRecord) {
                parent = root;
            } else {
                parent = record.getParent();
            }
            break;
        case ViolationOverview.SHOW_MARKERS_FILES:
            if (element instanceof FileToMarkerRecord) {
                parent = record.getParent();
            } else if (element instanceof PackageRecord) {
                parent = root;
            } else if (element instanceof MarkerRecord) {
                parent = record.getParent().getParent();
            }
            break;
        case ViolationOverview.SHOW_PACKAGES_FILES_MARKERS:
            if (element instanceof PackageRecord) {
                parent = root;
            } else {
                parent = record.getParent();
            }
            break;
        default:
    }
    return parent;
}
Also used : FileToMarkerRecord(net.sourceforge.pmd.eclipse.ui.model.FileToMarkerRecord) MarkerRecord(net.sourceforge.pmd.eclipse.ui.model.MarkerRecord) FileRecord(net.sourceforge.pmd.eclipse.ui.model.FileRecord) PackageRecord(net.sourceforge.pmd.eclipse.ui.model.PackageRecord) FileToMarkerRecord(net.sourceforge.pmd.eclipse.ui.model.FileToMarkerRecord) AbstractPMDRecord(net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)

Example 5 with PackageRecord

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

the class ViolationOverviewDoubleClickListener method doubleClick.

/**
 * @see org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.jface.viewers.DoubleClickEvent)
 */
public void doubleClick(DoubleClickEvent event) {
    final IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    final Object object = selection.getFirstElement();
    if (object instanceof PackageRecord) {
        doubleClickToPackageRecord((PackageRecord) object);
    } else if (object instanceof FileRecord) {
        doubleClickToFileRecord((FileRecord) object);
    } else if (object instanceof MarkerRecord) {
        doubleClickToMarkerRecord((MarkerRecord) object);
    } else if (object instanceof FileToMarkerRecord) {
        doubleClickToFileToMarkerRecord((FileToMarkerRecord) object);
    }
}
Also used : FileToMarkerRecord(net.sourceforge.pmd.eclipse.ui.model.FileToMarkerRecord) MarkerRecord(net.sourceforge.pmd.eclipse.ui.model.MarkerRecord) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PackageRecord(net.sourceforge.pmd.eclipse.ui.model.PackageRecord) FileRecord(net.sourceforge.pmd.eclipse.ui.model.FileRecord) FileToMarkerRecord(net.sourceforge.pmd.eclipse.ui.model.FileToMarkerRecord)

Aggregations

PackageRecord (net.sourceforge.pmd.eclipse.ui.model.PackageRecord)10 FileRecord (net.sourceforge.pmd.eclipse.ui.model.FileRecord)8 AbstractPMDRecord (net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)7 MarkerRecord (net.sourceforge.pmd.eclipse.ui.model.MarkerRecord)6 FileToMarkerRecord (net.sourceforge.pmd.eclipse.ui.model.FileToMarkerRecord)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ProjectRecord (net.sourceforge.pmd.eclipse.ui.model.ProjectRecord)1 IMarker (org.eclipse.core.resources.IMarker)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 Viewer (org.eclipse.jface.viewers.Viewer)1 Image (org.eclipse.swt.graphics.Image)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1