Skip to content

Commit f98d1fb

Browse files
committed
Take the priority filter for rule label decorations into account
1 parent 3447b8c commit f98d1fb

File tree

3 files changed

+37
-25
lines changed

3 files changed

+37
-25
lines changed

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/plugin/PMDPlugin.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,7 @@ private void registerAdditionalRuleSets() {
654654

655655
public RuleLabelDecorator ruleLabelDecorator() {
656656
IDecoratorManager mgr = getWorkbench().getDecoratorManager();
657-
// TODO don't use a raw string...urgh
658-
return (RuleLabelDecorator) mgr.getBaseLabelProvider("net.sourceforge.pmd.eclipse.plugin.RuleLabelDecorator");
657+
return (RuleLabelDecorator) mgr.getBaseLabelProvider(RuleLabelDecorator.ID);
659658
}
660659

661660
public void changedFiles(Collection<IFile> changedFiles) {

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/RuleLabelDecorator.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
package net.sourceforge.pmd.eclipse.ui;
66

77
import java.util.Collection;
8-
import java.util.HashSet;
98
import java.util.Set;
9+
import java.util.concurrent.CopyOnWriteArraySet;
1010

1111
import org.eclipse.core.resources.IResource;
1212
import org.eclipse.core.runtime.CoreException;
@@ -21,18 +21,18 @@
2121
import net.sourceforge.pmd.eclipse.runtime.PMDRuntimeConstants;
2222
import net.sourceforge.pmd.eclipse.runtime.builder.MarkerUtil;
2323
import net.sourceforge.pmd.eclipse.ui.priority.PriorityDescriptorCache;
24+
import net.sourceforge.pmd.eclipse.ui.views.PriorityFilter;
2425

2526
/**
2627
*
2728
* @author Brian Remedios
2829
*/
2930
public class RuleLabelDecorator implements ILightweightLabelDecorator {
30-
private Collection<ILabelProviderListener> listeners;
31+
public static final String ID = "net.sourceforge.pmd.eclipse.plugin.RuleLabelDecorator";
32+
33+
private Set<ILabelProviderListener> listeners = new CopyOnWriteArraySet<>();
3134

3235
public void addListener(ILabelProviderListener listener) {
33-
if (listeners == null) {
34-
listeners = new HashSet<ILabelProviderListener>();
35-
}
3636
listeners.add(listener);
3737
}
3838

@@ -41,16 +41,11 @@ public void dispose() {
4141
}
4242

4343
public void changed(Collection<IResource> resources) {
44-
if (listeners == null) {
45-
return;
46-
}
47-
4844
LabelProviderChangedEvent lpce = new LabelProviderChangedEvent(this, resources.toArray());
4945

5046
for (ILabelProviderListener listener : listeners) {
5147
listener.labelProviderChanged(lpce);
5248
}
53-
5449
}
5550

5651
/**
@@ -65,9 +60,6 @@ public boolean isLabelProperty(Object element, String property) {
6560
}
6661

6762
public void removeListener(ILabelProviderListener listener) {
68-
if (listeners == null) {
69-
return;
70-
}
7163
listeners.remove(listener);
7264
}
7365

@@ -89,8 +81,21 @@ public void decorate(Object element, IDecoration decoration) {
8981
return;
9082
}
9183

92-
Integer first = range.iterator().next();
93-
ImageDescriptor overlay = PriorityDescriptorCache.INSTANCE.descriptorFor(RulePriority.valueOf(first)).getAnnotationImageDescriptor();
84+
// consider only the priorities, that are not filtered
85+
Integer highestPriority = null;
86+
for (Integer priority : range) {
87+
if (PriorityFilter.getInstance().isPriorityEnabled(RulePriority.valueOf(priority))) {
88+
if (highestPriority == null || highestPriority > priority) {
89+
highestPriority = priority;
90+
}
91+
}
92+
}
93+
94+
if (highestPriority == null) {
95+
return;
96+
}
97+
98+
ImageDescriptor overlay = PriorityDescriptorCache.INSTANCE.descriptorFor(RulePriority.valueOf(highestPriority)).getAnnotationImageDescriptor();
9499

95100
try {
96101
boolean hasMarkers = MarkerUtil.hasAnyRuleMarkers(resource);

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/views/actions/PriorityFilterAction.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@
44

55
package net.sourceforge.pmd.eclipse.ui.views.actions;
66

7+
import java.util.Set;
8+
9+
import org.eclipse.core.resources.IFile;
10+
import org.eclipse.core.resources.ResourcesPlugin;
711
import org.eclipse.jface.action.Action;
812
import org.eclipse.jface.resource.ImageDescriptor;
913
import org.eclipse.jface.viewers.ViewerFilter;
1014

1115
import net.sourceforge.pmd.RulePriority;
16+
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
1217
import net.sourceforge.pmd.eclipse.plugin.UISettings;
18+
import net.sourceforge.pmd.eclipse.runtime.builder.MarkerUtil;
19+
import net.sourceforge.pmd.eclipse.ui.model.RootRecord;
1320
import net.sourceforge.pmd.eclipse.ui.priority.PriorityDescriptor;
1421
import net.sourceforge.pmd.eclipse.ui.priority.PriorityDescriptorCache;
1522
import net.sourceforge.pmd.eclipse.ui.views.PriorityFilter;
@@ -40,10 +47,8 @@ private PriorityFilterAction(ViewerFilter[] filters, RulePriority thePriority) {
4047
/**
4148
* Constructor, used for Violations Outline only
4249
*
43-
* @param prio,
44-
* the Priority to filter
45-
* @param view,
46-
* the ViolationOutline
50+
* @param prio the Priority to filter
51+
* @param view the ViolationOutline
4752
*/
4853
public PriorityFilterAction(RulePriority prio, ViolationOutline view) {
4954
this(view.getFilters(), prio);
@@ -53,10 +58,8 @@ public PriorityFilterAction(RulePriority prio, ViolationOutline view) {
5358
/**
5459
* Constructor, used for Violations Overview only
5560
*
56-
* @param prio,
57-
* the Priority to filter
58-
* @param view,
59-
* the violations Overview
61+
* @param prio the Priority to filter
62+
* @param view the violations Overview
6063
*/
6164
public PriorityFilterAction(RulePriority prio, ViolationOverview view) {
6265
this(view.getViewer().getFilters(), prio);
@@ -110,6 +113,11 @@ private void refreshView() {
110113
} else if (overviewView != null) {
111114
overviewView.refresh();
112115
}
116+
117+
// refresh all resources to update the rule label decorator
118+
RootRecord root = new RootRecord(ResourcesPlugin.getWorkspace().getRoot());
119+
Set<IFile> files = MarkerUtil.allMarkedFiles(root);
120+
PMDPlugin.getDefault().changedFiles(files);
113121
}
114122

115123
@Override

0 commit comments

Comments
 (0)