Search in sources :

Example 16 with AbstractPMDRecord

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

the class ViolationOverviewContentProvider method getChildrenOfPackageOrFolder.

private Object[] getChildrenOfPackageOrFolder(AbstractPMDRecord record) {
    if (violationView.getShowType() == ViolationOverview.SHOW_MARKERS_FILES) {
        Map<String, AbstractPMDRecord> markers = new HashMap<String, AbstractPMDRecord>();
        List<AbstractPMDRecord> files = record.getChildrenAsList();
        for (AbstractPMDRecord fileRec : files) {
            List<AbstractPMDRecord> newMarkers = fileRec.getChildrenAsList();
            for (AbstractPMDRecord markerRec : newMarkers) {
                markers.put(markerRec.getName(), markerRec);
            }
        }
        return markers.values().toArray(new MarkerRecord[markers.size()]);
    } else {
        return record.getChildren();
    }
}
Also used : HashMap(java.util.HashMap) AbstractPMDRecord(net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)

Example 17 with AbstractPMDRecord

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

the class ViolationOverviewLabelProvider method getProjectName.

/**
 * Return the project name.
 *
 * @param element
 * @return
 */
private String getProjectName(Object element) {
    String projectName = "";
    AbstractPMDRecord projectRec = null;
    if (element instanceof PackageRecord) {
        projectRec = ((PackageRecord) element).getParent();
    } else if (element instanceof FileRecord) {
        projectRec = ((FileRecord) element).getParent().getParent();
    } else if (element instanceof MarkerRecord) {
        projectRec = ((MarkerRecord) element).getParent().getParent().getParent();
    } else if (element instanceof FileToMarkerRecord) {
        projectRec = ((FileToMarkerRecord) element).getParent().getParent().getParent().getParent();
    }
    if (projectRec != null) {
        projectName = projectRec.getName();
    }
    return projectName;
}
Also used : FileToMarkerRecord(net.sourceforge.pmd.eclipse.ui.model.FileToMarkerRecord) MarkerRecord(net.sourceforge.pmd.eclipse.ui.model.MarkerRecord) PackageRecord(net.sourceforge.pmd.eclipse.ui.model.PackageRecord) FileRecord(net.sourceforge.pmd.eclipse.ui.model.FileRecord) FileToMarkerRecord(net.sourceforge.pmd.eclipse.ui.model.FileToMarkerRecord) AbstractPMDRecord(net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)

Example 18 with AbstractPMDRecord

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

the class ProjectFilter method select.

/*
     * @see
     * org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.
     * Viewer, java.lang.Object, java.lang.Object)
     */
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
    boolean select = true;
    AbstractPMDRecord projectRec = null;
    if (element instanceof PackageRecord) {
        projectRec = ((PackageRecord) element).getParent();
    } else if (element instanceof FileRecord) {
        projectRec = ((FileRecord) element).getParent().getParent();
    } else if (element instanceof MarkerRecord) {
        projectRec = ((MarkerRecord) element).getParent().getParent().getParent();
    }
    // we don't want the Element to be shown
    if (projectFilterList.contains(projectRec)) {
        select = false;
    }
    return select;
}
Also used : MarkerRecord(net.sourceforge.pmd.eclipse.ui.model.MarkerRecord) 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 19 with AbstractPMDRecord

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

the class CalculateStatisticsAction method run.

/**
 * Executes the Action
 */
public void run() {
    try {
        final ProgressMonitorDialog dialog = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
        dialog.setCancelable(true);
        dialog.run(false, false, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                final TreeItem[] items = getViewer().getTree().getItems();
                final int unitCount = calculateWorkUnits(items);
                monitor.beginTask(getString(StringKeys.MONITOR_CALC_STATS_TASK), unitCount);
                for (TreeItem item : items) {
                    if (monitor.isCanceled()) {
                        break;
                    }
                    if (item.getData() instanceof PackageRecord) {
                        final PackageRecord record = (PackageRecord) item.getData();
                        final AbstractPMDRecord[] children = record.getChildren();
                        monitor.subTask(getString(StringKeys.MONITOR_CALC_STATS_OF_PACKAGE) + ": " + record.getName());
                        for (AbstractPMDRecord kid : children) {
                            if (kid instanceof FileRecord) {
                                calculateFileRecord((FileRecord) kid);
                                monitor.worked(1);
                            }
                        }
                    } else if (item.getData() instanceof FileRecord) {
                        calculateFileRecord((FileRecord) item.getData());
                        monitor.worked(1);
                    }
                }
                getViewer().refresh(true);
            }
        });
    } catch (InvocationTargetException e) {
        logErrorByKey(StringKeys.ERROR_INVOCATIONTARGET_EXCEPTION, e);
    } catch (InterruptedException e) {
        logErrorByKey(StringKeys.ERROR_INTERRUPTED_EXCEPTION, e);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TreeItem(org.eclipse.swt.widgets.TreeItem) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) PackageRecord(net.sourceforge.pmd.eclipse.ui.model.PackageRecord) FileRecord(net.sourceforge.pmd.eclipse.ui.model.FileRecord) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) 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